model 14
Posts: 15
Joined: Thu Aug 22, 2019 11:52 am

Can't open .wav files using pygame.mixer

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

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

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

Tue Oct 08, 2019 4:45 pm

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?

model 14
Posts: 15
Joined: Thu Aug 22, 2019 11:52 am

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

Tue Oct 08, 2019 9:23 pm

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.

pcmanbob
Posts: 9463
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

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

Tue Oct 08, 2019 9:42 pm

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.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Python”