Opening a wave file in Python: unknown format: 49. What#39;s going wrong?(在 Python 中打开一个波形文件:未知格式:49. 出了什么问题?)
问题描述
我尝试使用 wave
模块打开一个波形文件,但无论我尝试什么,都会遇到相同的错误.出现错误的行如下:
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)
这是错误信息:
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 文件的路径,在我的任何媒体播放器中播放时都可以使用.
String f
is a path to a .WAV file and it works when played in any of my media players.
我当然已经导入了 wave
模块.我尝试将 f
作为相对路径和绝对路径.我尝试用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".
错误是由什么引起的?
推荐答案
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 之类的程序或一些库来转换编解码器以更改 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
这篇关于在 Python 中打开一个波形文件:未知格式:49. 出了什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Python 中打开一个波形文件:未知格式:49. 出了什么问题?


基础教程推荐
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01