【问题标题】:SoXI failed with exit code 1SoXI 失败,退出代码为 1
【发布时间】:2021-03-17 20:26:27
【问题描述】:

我想将 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

【问题讨论】:

    标签: python python-3.x sox


    【解决方案1】:
    1. First reason
    1. 第二个 - 需要文件的完整路径

    【讨论】:

    • 好吧,你赢是为了简洁,但这不是解决我遇到同样错误的原因。
    【解决方案2】:

    尝试从命令行运行 sox。它会给你更多的信息错误。

    $ sox --i -c data/stereo-test.mp3 
    

    就我而言,它告诉我没有 mp3 文件的库:

    $ sox --i -c data/stereo-test.mp3 
    sox FAIL formats: no handler for file extension `mp3'
    

    在 Windows 系统上,您必须install the correct DLLs

    在 linux 系统上:

    $ sudo apt-get install libsox-fmt-mp3
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following NEW packages will be installed:
      libsox-fmt-mp3
    0 upgraded, 1 newly installed, 0 to remove and 133 not upgraded.
    Need to get 56.6 kB of archives.
    After this operation, 96.3 kB of additional disk space will be used.
    Get:1 http://mirrors.ocf.berkeley.edu/raspbian/raspbian buster/main armhf libsox-fmt-mp3 armhf 14.4.2+git20190427-1 [56.6 kB]
    Fetched 56.6 kB in 1s (71.8 kB/s)   
    Selecting previously unselected package libsox-fmt-mp3:armhf.
    (Reading database ... 103401 files and directories currently installed.)
    Preparing to unpack .../libsox-fmt-mp3_14.4.2+git20190427-1_armhf.deb ...
    Unpacking libsox-fmt-mp3:armhf (14.4.2+git20190427-1) ...
    Setting up libsox-fmt-mp3:armhf (14.4.2+git20190427-1) ...
    

    之后,我得到了更令人满意的结果:

    $ sox --i -c data/stereo-test.mp3 
    2
    

    【讨论】:

      猜你喜欢
      • 2017-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      • 2020-07-16
      • 1970-01-01
      • 2010-11-08
      • 2021-05-18
      相关资源
      最近更新 更多