问题描述
我尝试用 wave
模块打开一个wave文件,但是不管我尝试什么,我总是收到相同的错误。
出错的行如下:
$ p $ w $ wave $ open $ f
这是错误信息:
Traceback(最近一次调用最后一次):
在< module>文件中的第47行annotate.py
播放(文件)
文件annotate.py,第33行,正在播放
wav = wave.open(f)
文件C:\程序文件(x86 )\Python\lib\wave.py,第498行,打开
返回Wave_read(f)
文件C:\程序文件(x86)\Python\lib\\ \\ wave.py,第163行,在__init__
self.initfp(f)
文件C:\程序文件(x86)\Python\lib\wave.py,行143,在initfp
self._read_fmt_chunk(chunk)
文件C:\程序文件(x86)\Python\lib\wave.py,第269行,在_read_fmt_chunk中
错误('未知格式:%r'%(wFormatTag))
wave.Error:未知格式:
字符串 f
是一个.WAV文件的路径,在我的任何媒体播放器中播放时都可以使用。
我当然已经导入了 wave
模块。
我尝试了 f
作为相对路径和绝对路径。
我尝试用wav替换WAV。
WAVE_FORMAT_PCM:0x0001
)。 在你的情况下,你使用的是一个类型为 WAVE_FORMAT_GSM610
[0x0031 = hex(49)]的WAV。 b
您可以使用像Audacity或某些lib的程序来转换编解码器来更改WAV文件的类型。
您可以看到一个列表的WAV类型在这里:
I try to open a wave file with the wave
module, but I keep getting the same error whatever I try.The line with the error is the following:
wav = wave.open(f)
This is the error message:
Traceback (most recent call last):
File "annotate.py", line 47, in <module>
play(file)
File "annotate.py", line 33, in play
wav = wave.open(f)
File "C:\Program Files (x86)\Python\lib\wave.py", line 498, in open
return Wave_read(f)
File "C:\Program Files (x86)\Python\lib\wave.py", line 163, in __init__
self.initfp(f)
File "C:\Program Files (x86)\Python\lib\wave.py", line 143, in initfp
self._read_fmt_chunk(chunk)
File "C:\Program Files (x86)\Python\lib\wave.py", line 269, in _read_fmt_chunk
raise Error('unknown format: %r' % (wFormatTag,))
wave.Error: unknown format: 49
String f
is a path to a .WAV file and it works when played in any of my media players.I have of course imported the wave
module.I tried f
both as a relative and an absolute path. I tried replacing "WAV" by "wav".
What is the error caused by?
Python's wave module works with a specific type of WAV: PCM (WAVE_FORMAT_PCM: 0x0001
).
In your case, you're using a WAV of type WAVE_FORMAT_GSM610
[0x0031 = hex(49)].
You can use a program like Audacity or some lib for converting codecs to change the type of the WAV file.
You can see a list of WAV types here:https://www.videolan.org/developers/vlc/doc/doxygen/html/vlc__codecs_8h.html
Python's wave module source code:https://github.com/python/cpython/blob/master/Lib/wave.py
这篇关于在Python中打开一个wave文件:未知格式:49.出了什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!