50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import os
|
|
import json
|
|
import soundfile as sf
|
|
from faster_whisper import WhisperModel
|
|
from datasets import Dataset
|
|
|
|
DATASET_DIR = r"C:\GitHub\VocoLoom\f5_dataset"
|
|
WAV_DIR = os.path.join(DATASET_DIR, "wavs")
|
|
RAW_OUT = os.path.join(DATASET_DIR, "raw")
|
|
|
|
print("Loading Whisper tiny model...")
|
|
model = WhisperModel("tiny", device="cpu")
|
|
|
|
records = []
|
|
durations = []
|
|
|
|
wav_files = sorted([f for f in os.listdir(WAV_DIR) if f.endswith(".wav")])
|
|
print(f"Transcribing {len(wav_files)} sliced clips...")
|
|
|
|
for i, fname in enumerate(wav_files):
|
|
full_path = os.path.join(WAV_DIR, fname)
|
|
info = sf.info(full_path)
|
|
dur = round(info.duration, 2)
|
|
|
|
segs, _ = model.transcribe(full_path, language="de")
|
|
text = " ".join([s.text for s in segs]).strip()
|
|
|
|
records.append({
|
|
"audio_path": full_path,
|
|
"text": text,
|
|
"duration": dur
|
|
})
|
|
durations.append(dur)
|
|
print(f"[{i+1}/{len(wav_files)}] {fname} ({dur}s): {text[:50]}...")
|
|
|
|
# Save HuggingFace Dataset using save_to_disk
|
|
ds = Dataset.from_list(records)
|
|
ds.save_to_disk(RAW_OUT)
|
|
|
|
# Save duration.json
|
|
with open(os.path.join(DATASET_DIR, "duration.json"), "w", encoding="utf-8") as f:
|
|
json.dump({"duration": durations}, f, indent=2)
|
|
|
|
# Save metadata.json
|
|
with open(os.path.join(DATASET_DIR, "metadata.json"), "w", encoding="utf-8") as f:
|
|
json.dump(records, f, indent=2, ensure_ascii=False)
|
|
|
|
print(f"\n[OK] F5 dataset successfully saved to: {RAW_OUT}")
|
|
print(f"Total clips: {len(records)}, Total duration: {sum(durations)/60:.2f} minutes")
|