pydub .export()问题-“ wave.Error:未指定#个通道”

时间:2018-11-06 02:17:09

标签: python-3.x ffmpeg pydub

我正在尝试使用pydub库从mp3剪辑片段。导出剪辑给我带来了一个问题。

我尝试将.mp3和.wav都导出。我敢肯定,这是我最后做的愚蠢的事情。到目前为止,Pydub看起来还不错,我只是一路上搞乱了。

我的代码的导出部分如下:

def cut_clip(track, start, stop):
    full_file = pydub.AudioSegment.from_file(track, format="mp3")
    clip = full_file[start:stop]
    return 

def create_clip_file():
    global clip
    clip = cut_clip('test.mp3', 2200000, 2280000)
    clip = pydub.AudioSegment.export("clip.wav", format="wav")
    print("%s is written." % clip)
    new_file_length = get_track_length(clip)

create_clip_file()

这是回溯。

subprocess.call(['ffmpeg', '-y', '-f', 'mp3', '-i', 'test.mp3', '-acodec', 'pcm_s16le', '-vn', '-f', 'wav', '-'])
Traceback (most recent call last):
  File "test.py", line 43, in <module>
    create_clip_file()
  File "test.py", line 38, in create_clip_file
    clip = pydub.AudioSegment.export("clip.wav", format="wav")
  File "/home/jeremy/.virtualenvs/chopin-qm-qH-MX/lib/python3.4/site-packages/pydub/audio_segment.py", line 795, in export
    wave_data.setnchannels(self.channels)
AttributeError: 'str' object has no attribute 'channels'
Exception ignored in: <bound method Wave_write.__del__ of <wave.Wave_write object at 0x6fee80b615c0>>
Traceback (most recent call last):
  File "/usr/lib/python3.4/wave.py", line 315, in __del__
    self.close()
  File "/usr/lib/python3.4/wave.py", line 433, in close
    self._ensure_header_written(0)
  File "/usr/lib/python3.4/wave.py", line 450, in _ensure_header_written
    raise Error('# channels not specified')
wave.Error: # channels not specified

有人碰巧看到我在做什么错吗?

我可以使用ffmpeg剪切剪辑,但是我确实想将头包裹在pydub上。

0 个答案:

没有答案