<jupyter_start><jupyter_text>Convert to flac for wav2vec> "Converting from a list"- toc: false- branch: master- hidden: true- categories: [pydub]<jupyter_code>BASE_PATH = "/home/jim/Playing/unlabelled"
files = []
with open(f"{BASE_PATH}/ina/no-music") as inf:
    for line in inf.readlines():
        stripped = line.strip()
        if stripped.startswith("./"):
            stripped = stripped[2:]
        if stripped.endswith(".csv"):
            stripped = stripped[0:-4]
        files.append(stripped)
exts = ["m4a", "mkv", "mp3", "MP3", "mp4", "wav"]
from pathlib import Path

data = {}
for file in files:
    for ext in exts:
        pathstr = f"{BASE_PATH}/{file}.{ext}"
        cur_path = Path(pathstr)
        if cur_path.is_file():
            data[file] = pathstr
from pydub import AudioSegment
for basename, fname in data.items():
    outstr = f"{BASE_PATH}/flac/{basename}.flac"
    audio = AudioSegment.from_file(fname)
    audio.export(outstr, format="flac", parameters=["-ac", "1", "-ar", "16000"])
count = 1
with open(f"{BASE_PATH}/vad_input.txt", "w") as outf:
    for basename, fname in data.items():
        outstr = f"{BASE_PATH}/flac/{basename}.flac"
        audio = AudioSegment.from_file(outstr)
        outf.write(f"train{count:04d} {outstr} {audio.duration_seconds}\n")
        count += 1<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15997023809523808, 'fraction_numerical': 0.013392857142857142, 'mean_word_length': 3.28343949044586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '644450', 'license': 'Apache-2.0', 'n_tokens_mistral': 489, 'n_tokens_neox': 480, 'n_words': 106, 'path': '_notebooks/2021-11-12-convert-flac-for-fairseq.ipynb', 'repo_name': 'jimregan/notes', 'size': '1344'}