Page 1 of 1

Can't open .wav files using pygame.mixer

Posted: Tue Oct 08, 2019 4:34 pm
by model 14
I'm just starting out playing with audio using example programs to make sounds.
When I run this script using Python3 on my Pi 4B:

import pygame.mixer
pygame.mixer.init(48000,-16,1,1024)
audio1 = pygame.mixer.Sound("buzzer.wav")

I get a "no such file exists error"
I can't open any .wav file.

Please help. Thanks

Re: Can't open .wav files using pygame.mixer

Posted: Tue Oct 08, 2019 4:45 pm
by B.Goode
model 14 wrote:
Tue Oct 08, 2019 4:34 pm
I'm just starting out playing with audio using example programs to make sounds.
When I run this script using Python3 on my Pi 4B:

import pygame.mixer
pygame.mixer.init(48000,-16,1,1024)
audio1 = pygame.mixer.Sound("buzzer.wav")

I get a "no such file exists error
I can't open any .wav file.

Please help. Thanks

The Python3 interpreter will be looking for the sound file buzzer.wav in the Current Working Directory from which the script is launched.

How, precisely, are you running the script?

Where, precisely, is the file buzzer.wav stored?

Re: Can't open .wav files using pygame.mixer

Posted: Tue Oct 08, 2019 9:23 pm
by model 14
I'm in the Pi directory of Raspbian when I run the python3 interpreter or script. I import pygames just fine. Why wouldn't the .wav files be there also? I'm really confused. I've run find in every directory and I still can't find .wave files.

Re: Can't open .wav files using pygame.mixer

Posted: Tue Oct 08, 2019 9:42 pm
by pcmanbob
I am not sure the pi even has any way files included in the image file, why don't you just add which ever way files you want to play to the /home/pi directory, then you should be able to play them.

Wav is after all a Windows file format.