TestTranslator / scripts /audio_utils.py
yujuanqin's picture
update scripts
42742c6
raw
history blame contribute delete
865 Bytes
from pathlib import Path
import subprocess
from subprocess import CompletedProcess
def cmd(command: str, check=True, capture_output=False) -> CompletedProcess:
print(command)
if capture_output:
ret = subprocess.run(command, shell=True, check=check, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True)
else:
ret = subprocess.run(command, shell=True, check=check)
print(ret.stdout)
return ret
def to_wav(folder: Path):
for file in folder.glob("*.mp3"):
# print(file)
wav_path = folder / f'{file.stem}.wav'
if not wav_path.exists():
command = f"ffmpeg -i {file} -ac 1 -ar 16000 {wav_path}"
# print(command)
cmd(command)
if __name__ == '__main__':
to_wav(Path("/Users/jeqin/work/test/audios/short_audios"))