SoXI失败,退出代码为1

2024-10-04 01:26:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将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并将其添加到路径中 我用的是魅力


Tags: inpyliblocallinefilenamemp3users