【发布时间】:2019-05-07 01:46:51
【问题描述】:
有没有办法通过与scipy.io.wavfile.read 和scipy.io.wavfile.write 类似的API 将MP3 音频文件读入/写出numpy 数组:
sr, x = wavfile.read('test.wav')
wavfile.write('test2.wav', sr, x)
?
注意:pydub 的 AudioSegment 对象不能直接访问 numpy 数组。
PS:我已经阅读了Importing sound files into Python as NumPy arrays (alternatives to audiolab),尝试了所有答案,包括那些需要Popen ffmpeg 并从stdout 管道中读取内容等的答案。我还阅读了Trying to convert an mp3 file to a Numpy Array, and ffmpeg just hangs 等。 ,并尝试了主要答案,但没有简单的解决方案。在花了几个小时之后,我将其发布在此处,并附有“回答你自己的问题——分享你的知识,问答式”。我也读过How to create a numpy array from a pydub AudioSegment?,但这并不容易涵盖多通道情况等。
【问题讨论】:
标签: python numpy audio ffmpeg mp3