I am trying to make a simple program that plays some narration, and has a sound effect on a trigger. Being new to python, I am just building up functions in layers. Getting music to work was easy, as it should be, but I cannot get sound to work.
I have read of a few people with similar issues, but either they are also unsolved, or the symptoms are slightly different, and the solutions don't work for me.
I have tried this on a pi3 (which is the end target), and windows 7, both running latest python 3, and pygame.
import pygame
import time
import os
pygame.mixer.init()
#pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()
pygame.mixer.music.load("English.mp3")
pygame.mixer.music.play()
print (os.getcwd())
shot = pygame.mixer.Sound("gun-gunshot-02.wav")
shot.play()
while True:
Time.sleep(1) # for testing and irritation prevention if sound ever plays
shot.play()
I should also note that the sound effect does work if I play it using music, but of course it replaces the narration.
Error is as follows same on both machines, same with both mp3 and wav:
C:\Users\me\Documents\Interrupter Traceback (most recent call last): File "C:/Users/me/Documents/Interrupter/simpletest.py", line 11, in shot = pygame.mixer.Sound("gun-gunshot-02.wav") pygame.error: Unable to open file 'gun-gunshot-02.wav'
Thanks in advance
shot = pygame.mixer.Sound(file="gun-gunshot-02.wav")- Rodrigo Alencar