Ahmed007/hamsa-tiny-v0.4
09
1import soundfile as sf2import os3 4os.makedirs("dataset", exist_ok=True)5archive_path = "test"6wav_dir = os.path.join(archive_path, "wav")7segments_file = os.path.join(archive_path, "text.all")8with open(segments_file, "r", encoding="utf-8") as f:9 for _id, line in enumerate(f):10 segment = line.split(" ")[0]11 text = " ".join(line.split(" ")[1:])12 wav_name, _, time = segment.split("_")13 time = time.replace("seg-", "")14 start, stop = time.split(":")15 start = int(int(start) / 100 * 16_000)16 stop = int(int(stop) / 100 * 16_000)17 wav_path = os.path.join(wav_dir, wav_name + ".wav")18 sound, _ = sf.read(wav_path, start=start, stop=stop)19 sf.write(f"dataset/{segment}.wav", sound, 16_000)20 open(f"dataset/{segment}.txt", "w").write(text)21 