将MP3转换为WAV时出现2个错误

时间:2019-09-15 13:54:04

标签: python mp3 wav python-module pyglet

我正在尝试使用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 个答案:

答案 0 :(得分:3)

根据"Loading media",您应该使用import bs4 as bs import urllib.request class Stock: stockrow_url = "https://stockrow.com" url_suffix = "/financials/{}/annual" def __init__(self, ticker : str, stock_url=stockrow_url, url_suffix = url_suffix): # Stock ticker self.ticker = ticker.upper() # URLs for financial statements related to the ticker self.stock_url = stock_url + "/{}".format(self.ticker) sauce = urllib.request.urlopen(self.stock_url).read() soup = bs.BeautifulSoup(sauce, 'html.parser').h1 print(soup) self.income_url = self.stock_url + url_suffix.format("income") self.balance_sheet_url = self.stock_url + url_suffix.format("balance") self.cash_flow_url = self.stock_url + url_suffix.format("cashflow") teva = Stock("teva") print(teva.get_income_statement()) 打开音频(和视频)文件:

pyglet.media.load

您还必须安装ffmpeg才能使pyglet能够读取mp3文件(根据Supported media types)。确保遵循installation instructions