python - Pygame error: not able to open .wav file -
i have problem pygame program. need help. wav file in same directory python file. run in terminal- python3:
import pygame.mixer sounds = pygame.mixer sounds.init() def wait_finish(channel): while channel.get_busy(): pass asked = 0 true = 0 false = 0 choice = str(input("push 1 true, 2 false, 0 end")) while choice != '0': if choice == '1': asked = asked + 1 true = true + 1 s = sounds.sound("correct.wav") wait_finish(s.play()) if choice == '2': asked = asked + 1 false = false + 1 s = sounds.sound("wrong.wav") wait_finish(s.play()) choice = str(input("push 1 true, 2 false, 0 end")) print ("you asked" +str(asked) + "questions") print ("there were" +str(false) + "wrong answers") print ("and" + str(true) + "correct answers")
it throws- pygame.error:
unable open file 'correct.wav'
rather have discussion in comments section i'll post this.
once def wait_finish(channnel):
has been altered def wait_finish(channel):
, issue sounds.sound
rather sounds.sounds
has been resolved, program works fine normal .wav files on machine.
convinced error of sound or sounds calling wrong.wav file played explain "unable open file wrong.wav" message.
if pygame doesn't file may not play , line like:
sounds.pre_init(frequency=22050, size=-16, channels=2, buffer=4096)
(called before sounds.init()
) might come play.
(nb might have use different buffer option testing pygame python 2.7)
on box, if pygame doesn't or cannot find file, no error @ speakers click when call play made.
can suggest @ point try entirely different wav file current 1 using wrong answers , see if makes difference. record, changed wait_finish function :
def wait_finish(channel): while channel.get_busy(): pygame.time.clock().tick(10)
Comments
Post a Comment