问题描述
我想将 mp3
文件转换为 wav 16khz
(这些是来自 Mozilla Common Voice 的文件)
我的功能
def one_sample(mp3_filename):
""" Take an audio file,and optionally convert it to 16kHz WAV """
if not os.path.splitext(mp3_filename.lower())[1] == ".mp3":
mp3_filename += ".mp3"
# Storing wav files next to the mp3 ones - just with a different suffix
wav_filename = os.path.splitext(mp3_filename)[0] + ".wav"
if not os.path.exists(wav_filename):
transformer = sox.Transformer()
transformer.convert(samplerate=SAMPLE_RATE,n_channels=CHANNELS)
try:
transformer.build(mp3_filename,wav_filename)
except sox.core.soxError:
pass
Traceback (most recent call last):
File "C:\Users\Ksavich\AppData\Local\Programs\Python\python38-32\lib\site-packages\sox\core.py",line 147,in soxi
shell_output = subprocess.check_output(
File "C:\Users\Ksavich\AppData\Local\Programs\Python\python38-32\lib\subprocess.py",line 411,in check_output
return run(*popenargs,stdout=PIPE,timeout=timeout,check=True,File "C:\Users\Ksavich\AppData\Local\Programs\Python\python38-32\lib\subprocess.py",line 512,in run
raise CalledProcessError(retcode,process.args,subprocess.CalledProcessError: Command '['sox','--i','-c','clips/common_voice_ru_23425218.mp3']' returned non-zero exit status 1.
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "D:/dip/ru/fox.py",line 93,in <module>
one_sample(path4)
File "D:/dip/ru/fox.py",line 17,in one_sample
_maybe_convert_wav(mp3_filename,wav_filename)
File "D:/dip/ru/fox.py",line 57,in _maybe_convert_wav
transformer.build(mp3_filename,wav_filename)
File "C:\Users\Ksavich\AppData\Local\Programs\Python\python38-32\lib\site-packages\sox\transform.py",line 593,in build
input_format,input_filepath = self._parse_inputs(
File "C:\Users\Ksavich\AppData\Local\Programs\Python\python38-32\lib\site-packages\sox\transform.py",line 496,in _parse_inputs
input_format['channels'] = file_info.channels(input_filepath)
File "C:\Users\Ksavich\AppData\Local\Programs\Python\python38-32\lib\site-packages\sox\file_info.py",line 82,in channels
output = soxi(input_filepath,'c')
File "C:\Users\Ksavich\AppData\Local\Programs\Python\python38-32\lib\site-packages\sox\core.py",line 153,in soxi
raise SoxiError("SoXI Failed with exit code {}".format(cpe.returncode))
sox.core.soxiError: SoXI Failed with exit code 1
Process finished with exit code 1
我下载了 sox-14-4-2 并将其添加到 PATH 我使用 PyCharm
解决方法
- 第二 - 需要文件的完整路径