Raise_child异常输出

时间:2014-07-25 20:14:16

标签: python exception audio wav pydub

我正在尝试让pydub将2个音频wav文件混合到一个wav文件中。这是我目前的代码:

from pydub import AudioSegment

sound1 = AudioSegment.from_wav("Test_1.wav")
sound2 = AudioSegment.from_wav("Test_2.wav")

# mix sound2 with sound1, starting at 5000ms into sound1)
output = sound1.overlay(sound2, position=5000)

# save the result
output.export("mixed.wav", format="wav")

这是确切的错误日志:

Traceback (most recent call last):
  File "heterodyning.py", line 10, in <module>
    output.export("mixed.wav", format = "wav")
  File "build/bdist.linux-armv6l/egg/pydub/audio_segment.py", line 234, in export
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

然而,无论出于何种原因,每当我尝试运行它时,它都会引发raise_child异常,并告诉我没有这样的文件或目录,指的是我告诉它导出的最后一行。我不知道为什么。谁能告诉我为什么会这样?

1 个答案:

答案 0 :(得分:0)

您当前的工作目录是什么样的?如果那里没有“mixed.wav”文件,则output.export("mixed.wav", format="wav")将失败,因为它不知道将叠加声音放在何处。您可以通过以下方式在python中打开文件:

mixed_file = open("mixed.wav", "wb")

在导出到文件之前执行此操作。

你应该得到这样的东西:

mixed_file = open("mixed.wav", "wb")
output.export(mixed_file, format="wav")