python - Pygame cannot open sound file -
import pygame, time pygame.locals import * soundobj = pygame.mixer.sound('beeps.wav') soundobj.play() time.sleep(1) # wait , allow sound play 1 sec soundobj.stop()
and throws error:
traceback (most recent phone call last): file "c:/users/jauhar/desktop/python/sounds.py", line 4, in <module> soundobj = pygame.mixer.sound('beeps.wav') pygame.error: unable open file 'beeps.wav'
the beeps.wav file saved in same directory python file code in.
i can't understand why won't work!
you cannot utilize pygames' library's unless initialize either modules using or of pygame.
pygame.mixer.pre_init(44100, 16, 2, 4096) #frequency, size, channels, buffersize pygame.init() #turn of pygame on.
do these before in pygame. recommend it.
python audio pygame
No comments:
Post a Comment