I want to convert mp3
files to wav 16khz
(these are files from Mozilla Common Voice)
My function
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
I get an error for all files:
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
I downloaded sox-14-4-2 and added it to the PATH And I use PyCharm