import pygame, time
from pygame.locals import *
soundObj = pygame.mixer.Sound('beeps.wav')
soundObj.play()
time.sleep(1) # wait and let the sound play for 1 second
soundObj.stop()
and it throws this error:
Traceback (most recent call last):
File "C:/Users/Jauhar/Desktop/Python/sounds.py", line 4, in <module>
soundObj = pygame.mixer.Sound('beeps.wav')
pygame.error: Unable to open file 'beeps.wav'
The beeps.wav file is saved in the same directory as the python file the code is in.
I can't understand why it won't work!
Pygame (version 2.9 at least) doesn't support 32-bit float WAVs. Re-encode it to a signed 16-bit WAV (using Audacity for example).
You cannot use pygames' library's unless you initialize either the modules your using or all of pygame.
pygame.mixer.pre_init(44100, 16, 2, 4096) #frequency, size, channels, buffersize
pygame.init() #turn all of pygame on.
do these before you do anything in pygame. I recommend it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With