将 MP3 转换为 WAV 时出现 2 个错误
Posted
技术标签:
【中文标题】将 MP3 转换为 WAV 时出现 2 个错误【英文标题】:Getting 2 errors while converting MP3 to WAV 【发布时间】:2019-09-15 13:54:04 【问题描述】:我正在尝试使用 pyglet 模块播放 mp3 文件。 根据一些建议,我已经安装了 avbin64 并将 avbin64.dll 移动到我的 python 代码所在的目录。但是,我仍然收到 2 个错误
import pyglet
music = pyglet.resource.media('song.mp3')
music.play()
pyglet.app.run()
错误代码
Traceback (most recent call last):
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\media\codecs\wave.py", line 59, in __init__
self._wave = wave.open(file)
File "C:\Users\udit\AppData\Local\Programs\Python\Python37\lib\wave.py", line 510, in open
return Wave_read(f)
File "C:\Users\udit\AppData\Local\Programs\Python\Python37\lib\wave.py", line 164, in __init__
self.initfp(f)
File "C:\Users\udit\AppData\Local\Programs\Python\Python37\lib\wave.py", line 131, in initfp
raise Error('file does not start with RIFF id')
wave.Error: file does not start with RIFF id
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:/PycharmProjects/test/test2.py", line 3, in <module>
music = pyglet.resource.media('song.mp3')
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\resource.py", line 678, in media
return media.load(path, streaming=streaming)
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\media\__init__.py", line 143, in load
raise first_exception
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\media\__init__.py", line 133, in load
loaded_source = decoder.decode(file, filename, streaming)
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\media\codecs\wave.py", line 109, in decode
return WaveSource(filename, file)
File "F:\PycharmProjects\test\venv\lib\site-packages\pyglet\media\codecs\wave.py", line 61, in __init__
raise WAVEDecodeException(e)
pyglet.media.codecs.wave.WAVEDecodeException: file does not start with RIFF id
【问题讨论】:
【参考方案1】:根据"Loading media",您应该使用pyglet.media.load
打开音频(和视频)文件:
music = pyglet.media.load('song.mp3')
您还必须安装 ffmpeg 才能使 pyglet 能够读取 mp3 文件(根据 Supported media types)。请务必关注installation instructions。
【讨论】:
我已经安装了 FFmpeg 并尝试使用pyglet.media.load
打开文件,但仍然遇到同样的错误
@Anjali 你关注installation instructions了吗?以上是关于将 MP3 转换为 WAV 时出现 2 个错误的主要内容,如果未能解决你的问题,请参考以下文章
将 g 711 数据包转换为 wav 文件时出现断断续续的声音