Brilliant - many thanks. I agree, a lifesaver for me. Been trying for days to play wav files on my pi zero w and this is the only code that will do it for some reason. Many, many thanks.👍
I noticed one time on a fresh install the speaker-test & aplay produced only heavy static for the length of the play, however playing files through python did work. It also worked when logging in via VNC and using VLC player, so if you hear static when testing & running aplay, just continue & hopefully your sound will work fine. If anyone knows why speaker-test & aplay are not working on some installs, do comment, below!
The speaker-test works fine for me. When I attempt to play a .wav, .mp3 or .m4a audio file, I only hear white noise and get message "Playing raw data 'audiofilename.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono. I'm using a Raspberry Pi 4 with Raspberry Pi OS and using bluetooth for my Google Home Mini.
Great video 👍 I just found you channel. Is this info still usable ? Would it be possible to loop the files, and create Some kind of a playlist ? Thanks a lot.
Check out the video on bit.ly/raspberry-pi-tutorials on “The Right Away to Add Buttons”. You can then trigger a sound with each button press. If you’re new to CircuitPython also check out the CircuitPython School playlist on my channel. It’s where my students start. Cheers!
Can you please make a video elaborating the use of the sound function with if statement because i have 6 different classes and i want the raspberry to say the name of each one of them when available
Check out the playlist: bit.ly/circuitpython-tutorials and look for Lesson 18 - Random Numbers. This will show you how to generate random values. You can put the names of your sounds in a list & get a random element from that list and play that element. For a delay of a random amount, you can generate a random value in a range of the # of seconds (or fractions of a second) you want to wait, and use a time.sleep(random_seconds_value) in between getting & playing random sounds. Hope that helps!
Hi! I'm using a raspberry pico and my jack port is linked to the pins GP18 and GP19, how can I modifiy this programm so that it plays the sound though that port ? Thanks ! :)
Hi. If you are using a Pico you won’t use PyGame. Check out the CircuitPython playlist. There are lots of sound tutorials there and you can use CircuitPython with the Pico. See bit.ly/circuitpython-tutorials.
If your Pi repeatedly asks "To install the screen reader press CTRL+ALT+SPACE", you can delete that auto-repeat by entering the following command, then rebooting your Pi: sudo rm /etc/xdg/autostart/piwiz.desktop
"NameError ... is not defined" means you're referring to a variable (in your case one named "speaker") that has not been created. If you look hard at the code you'll see that the variable is named "speaker_volume", not "speaker". So if you refer to "speaker" before it has been created & has anything inside it, your program thinks this is a made-up word like flitzblaubgasdf. When you assign a variable a value you define it, or give it a definition. If I tell you flitzblaubgasdf = "林冠廷 is a code god", then I have just defined that variable and you'll know what flitzblaubgasdf is. Check your code & make sure your "speaker" is called "speaker_volume" in all places. Also: Sometimes this will show up if you refer to a value that should be part of an imported library (not the case here). That's another thing to double check. Good luck!
Your content is immaculate. This is the second life-saving video I've watched from you. Learning so much just 2 days into Raspberry Pi!
So glad you are enjoying this. Shoot me an address over email if you’d like a “Make Something Awesome!” Sticker.
Brilliant - many thanks. I agree, a lifesaver for me. Been trying for days to play wav files on my pi zero w and this is the only code that will do it for some reason. Many, many thanks.👍
I noticed one time on a fresh install the speaker-test & aplay produced only heavy static for the length of the play, however playing files through python did work. It also worked when logging in via VNC and using VLC player, so if you hear static when testing & running aplay, just continue & hopefully your sound will work fine. If anyone knows why speaker-test & aplay are not working on some installs, do comment, below!
The speaker-test works fine for me. When I attempt to play a .wav, .mp3 or .m4a audio file, I only hear white noise and get message "Playing raw data 'audiofilename.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono. I'm using a Raspberry Pi 4 with Raspberry Pi OS and using bluetooth for my Google Home Mini.
I had that happen. I realized I was playing an mp3 file. aplay was playing it as a wav.
Thank you so much! This helped me with a project for my Intro to Computer-Science class!!
Glad it helped, Ava! Keep hacking!
Great video 👍
I just found you channel.
Is this info still usable ?
Would it be possible to loop the files, and create Some kind of a playlist ?
Thanks a lot.
This is helpful. Thank you.
Any ideas on how to add buttons to each file? Thanks.
Check out the video on bit.ly/raspberry-pi-tutorials on “The Right Away to Add Buttons”. You can then trigger a sound with each button press. If you’re new to CircuitPython also check out the CircuitPython School playlist on my channel. It’s where my students start. Cheers!
Ps my code is exactly the same but only plays the last in the list. Any idea what I’ve done wrong? Ta. Rik
good job bro
Can you please make a video elaborating the use of the sound function with if statement because i have 6 different classes and i want the raspberry to say the name of each one of them when available
Check out the DJ board video ua-cam.com/video/1FAYy1hrcGc/v-deo.html
What if I want to play the files in random order? Also, not one after the other but after silences in between? What would be the code for that?
Check out the playlist: bit.ly/circuitpython-tutorials and look for Lesson 18 - Random Numbers. This will show you how to generate random values. You can put the names of your sounds in a list & get a random element from that list and play that element. For a delay of a random amount, you can generate a random value in a range of the # of seconds (or fractions of a second) you want to wait, and use a time.sleep(random_seconds_value) in between getting & playing random sounds. Hope that helps!
@@profgallaugher Great. Thank you so much!
Sir if i will pulg ear phones will it work?
Try ‘em out, homie!
Hi! I'm using a raspberry pico and my jack port is linked to the pins GP18 and GP19, how can I modifiy this programm so that it plays the sound though that port ? Thanks ! :)
Hi. If you are using a Pico you won’t use PyGame. Check out the CircuitPython playlist. There are lots of sound tutorials there and you can use CircuitPython with the Pico. See bit.ly/circuitpython-tutorials.
If your Pi repeatedly asks "To install the screen reader press CTRL+ALT+SPACE", you can delete that auto-repeat by entering the following command, then rebooting your Pi:
sudo rm /etc/xdg/autostart/piwiz.desktop
Is there a reason that my rasp pi produces static sound?
No idea. Perhaps someone on the Adafruit Discord channel has some suggestions.
Why did terminal tell me " NameError: name 'speaker' is not defined? "
"NameError ... is not defined" means you're referring to a variable (in your case one named "speaker") that has not been created. If you look hard at the code you'll see that the variable is named "speaker_volume", not "speaker". So if you refer to "speaker" before it has been created & has anything inside it, your program thinks this is a made-up word like flitzblaubgasdf. When you assign a variable a value you define it, or give it a definition. If I tell you flitzblaubgasdf = "林冠廷 is a code god", then I have just defined that variable and you'll know what flitzblaubgasdf is. Check your code & make sure your "speaker" is called "speaker_volume" in all places. Also: Sometimes this will show up if you refer to a value that should be part of an imported library (not the case here). That's another thing to double check. Good luck!
@@profgallaugher I have solved the problem, thanks for your reply!!!