Kh0128/Aphasia_Classificifier
0
1import os, subprocess, tempfile, uuid2 3def convert_to_wav(src_path: str, sr: int = 16000, mono: bool = True) -> str:4 """Convert mp3/mp4/wav to a normalized wav for downstream tools."""5 tmpdir = tempfile.mkdtemp(prefix="audio_")6 out_path = os.path.join(tmpdir, f"{uuid.uuid4().hex}.wav")7 cmd = [8 "ffmpeg", "-y", "-i", src_path,9 "-ar", str(sr),10 "-ac", "1" if mono else "2",11 out_path12 ]13 subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)14 return out_path15 