I am trying to play a audio file using pyglet but I get the error below. Why is this and how can I fix it?
Code:
import pyglet
player = pyglet.media.Player()
sound = pyglet.media.load("air_raid.wav", streaming=False)
player.queue(sound)
player.play()
Error:
Traceback (most recent call last):
File "C:/Users/Christian.wargel/Desktop/audio/audio.py", line 4, in <module>
sound = pyglet.media.load("air_raid.wav", streaming=False)
File "C:\Users\Christian.wargel\Documents\Python27\lib\site-packages\pyglet\media\__init__.py", line 1431, in load
source = StaticSource(source)
File "C:\Users\Christian.wargel\Documents\Python27\lib\site-packages\pyglet\media\__init__.py", line 612, in __init__
audio_data = source.get_audio_data(buffer_size)
File "C:\Users\Christian.wargel\Documents\Python27\lib\site-packages\pyglet\media\avbin.py", line 426, in get_audio_data
packet_type, packet = self._process_packet()
File "C:\Users\Christian.wargel\Documents\Python27\lib\site-packages\pyglet\media\avbin.py", line 397, in _process_packet
audio_data = self._decode_audio_packet()
File "C:\Users\Christian.wargel\Documents\Python27\lib\site-packages\pyglet\media\avbin.py", line 489, in _decode_audio_packet
duration = float(len(buffer)) / self.audio_format.bytes_per_second
ZeroDivisionError: float division by zero
The same code works on my laptop with Python 2.7. I guess there maybe something wrong with your .wav sound file. Please check whether your sound file is empty. I downloaded sample14.wav from http://download.wavetlan.com/SVV/Media/HTTP/http-wav.htm and it really works. Could you test the same sample14.wav file?
Another possible reason may be the the version of your pyglet not matching your python version.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.