File size: 865 Bytes
ade4f6a 42742c6 ade4f6a 42742c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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"))
|