Anjali
Anjali

Reputation: 187

Getting 2 errors while converting MP3 to WAV

I am trying to play mp3 file using pyglet module. Following some suggestions, I have already installed avbin64 and moved avbin64.dll to the directory where my python code is. but still, I am getting 2 errors

import pyglet

music = pyglet.resource.media('song.mp3')
music.play()

pyglet.app.run()

error code

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

Upvotes: 2

Views: 376

Answers (1)

Aran-Fey
Aran-Fey

Reputation: 43166

As per "Loading media", you're supposed to open audio (and video) files with pyglet.media.load:

music = pyglet.media.load('song.mp3')

You must also have ffmpeg installed for pyglet to be able to read mp3 files (as per Supported media types). Make sure to follow the installation instructions.

Upvotes: 3

Related Questions