問(wèn)題描述
我嘗試使用 wave
模塊打開(kāi)一個(gè)波形文件,但無(wú)論我嘗試什么,都會(huì)遇到相同的錯(cuò)誤.出現(xiàn)錯(cuò)誤的行如下:
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)
這是錯(cuò)誤信息:
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)Pythonlibwave.py", line 498, in open
return Wave_read(f)
File "C:Program Files (x86)Pythonlibwave.py", line 163, in __init__
self.initfp(f)
File "C:Program Files (x86)Pythonlibwave.py", line 143, in initfp
self._read_fmt_chunk(chunk)
File "C:Program Files (x86)Pythonlibwave.py", line 269, in _read_fmt_chunk
raise Error('unknown format: %r' % (wFormatTag,))
wave.Error: unknown format: 49
String f
是 .WAV 文件的路徑,在我的任何媒體播放器中播放時(shí)都可以使用.
String f
is a path to a .WAV file and it works when played in any of my media players.
我當(dāng)然已經(jīng)導(dǎo)入了 wave
模塊.我嘗試將 f
作為相對(duì)路徑和絕對(duì)路徑.我嘗試用wav"替換WAV".
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".
錯(cuò)誤是由什么引起的?
推薦答案
Python 的 wave 模塊適用于特定類型的 WAV:PCM (WAVE_FORMAT_PCM: 0x0001
).
Python's wave module works with a specific type of WAV: PCM (WAVE_FORMAT_PCM: 0x0001
).
在您的情況下,您使用的是 WAVE_FORMAT_GSM610
[0x0031 = hex(49)] 類型的 WAV.
In your case, you're using a WAV of type WAVE_FORMAT_GSM610
[0x0031 = hex(49)].
您可以使用 Audacity 之類的程序或一些庫(kù)來(lái)轉(zhuǎn)換編解碼器以更改 WAV 文件的類型.
You can use a program like Audacity or some lib for converting codecs to change the type of the WAV file.
您可以在此處查看 WAV 類型列表:https://www.videolan.org/developers/vlc/doc/doxygen/html/vlc__codecs_8h.html
You can see a list of WAV types here: https://www.videolan.org/developers/vlc/doc/doxygen/html/vlc__codecs_8h.html
Python的wave模塊源碼:https://github.com/python/cpython/blob/master/Lib/wave.py
Python's wave module source code: https://github.com/python/cpython/blob/master/Lib/wave.py
這篇關(guān)于在 Python 中打開(kāi)一個(gè)波形文件:未知格式:49. 出了什么問(wèn)題?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!