简体   繁体   English

在python中读取.wav文件

[英]reading .wav files in python

I'm trying (for a course) to read a sound file .wav via ipython. 我正在尝试(针对某个课程)通过ipython读取声音文件.wav。 When I try the 'normal' code to read a file: 当我尝试使用“普通”代码读取文件时:

from scipy.io.wavfile import read

(fs,x) = read ('/Users/joehigham/Desktop/Audio_1.wav')

I get the well known traceback call of 我得到了众所周知的回溯电话

ValueError: string size must be a multiple of element size 

Can anyone point me in the right direction as to why this happens, and of course how can I right the problem? 谁能为我指出发生这种情况的正确方向,当然我该如何解决这个问题?

Thanks in advance - I did look round SO for the solution, but nothing (that I found) seems to match this problem with sound files. 在此先感谢您-我的确找到了解决方案,但似乎找不到与声音文件匹配的问题(我发现)。

Your wav file probably has 24 bit data. 您的wav文件可能具有24位数据。 You can check with: 您可以通过以下方式进行检查:

import wave
w = wave.open("filename.wav")
print(w.getsampwidth())

If the value printed is 3, your data is 24 bit. 如果打印的值为3,则您的数据为24位。 If that is the case, scipy.io.wavfile won't work. 如果是这种情况, scipy.io.wavfile将不起作用。 I wrote a reader that handles 24 bit data; 我写了一个处理24位数据的阅读器。 see https://github.com/WarrenWeckesser/wavio (which replaced the gist at https://gist.github.com/WarrenWeckesser/7461781 ). 请参阅https://github.com/WarrenWeckesser/wavio (已取代要点, 网址 https://gist.github.com/WarrenWeckesser/7461781 )。 The reader is also on PyPI . 读者也可以使用PyPI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM