CircuitPython School - Playing Sound (wav or mp3) with PyGame on a Raspberry Pi

Поділитися
Вставка
  • Опубліковано 4 січ 2025

КОМЕНТАРІ • 29

  • @ajwilliams5551
    @ajwilliams5551 2 роки тому +2

    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!

    • @profgallaugher
      @profgallaugher  2 роки тому

      So glad you are enjoying this. Shoot me an address over email if you’d like a “Make Something Awesome!” Sticker.

  • @richardskidmore6632
    @richardskidmore6632 11 місяців тому

    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.👍

  • @profgallaugher
    @profgallaugher  3 роки тому +1

    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!

    • @ccf805
      @ccf805 3 роки тому

      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.

    • @snerkrabbledauber7032
      @snerkrabbledauber7032 3 роки тому

      I had that happen. I realized I was playing an mp3 file. aplay was playing it as a wav.

  • @avabanbury594
    @avabanbury594 3 роки тому +2

    Thank you so much! This helped me with a project for my Intro to Computer-Science class!!

  • @Duurzaamheid
    @Duurzaamheid 5 днів тому

    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.

  • @MuhammedBasil
    @MuhammedBasil 11 місяців тому

    This is helpful. Thank you.

  • @jalvarez242424
    @jalvarez242424 2 роки тому +2

    Any ideas on how to add buttons to each file? Thanks.

    • @profgallaugher
      @profgallaugher  2 роки тому +2

      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!

  • @richardskidmore6632
    @richardskidmore6632 11 місяців тому

    Ps my code is exactly the same but only plays the last in the list. Any idea what I’ve done wrong? Ta. Rik

  • @nayanrimal3206
    @nayanrimal3206 Рік тому

    good job bro

  • @mugtabataha3355
    @mugtabataha3355 2 роки тому

    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

    • @profgallaugher
      @profgallaugher  2 роки тому +1

      Check out the DJ board video ua-cam.com/video/1FAYy1hrcGc/v-deo.html

  • @vaibhavbatra4613
    @vaibhavbatra4613 3 роки тому

    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?

    • @profgallaugher
      @profgallaugher  3 роки тому +1

      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!

    • @vaibhavbatra4613
      @vaibhavbatra4613 3 роки тому

      @@profgallaugher Great. Thank you so much!

  • @suhasmahajan-if9ez
    @suhasmahajan-if9ez 10 місяців тому

    Sir if i will pulg ear phones will it work?

  • @nicolebendo9079
    @nicolebendo9079 2 роки тому

    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 ! :)

    • @profgallaugher
      @profgallaugher  2 роки тому +2

      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.

  • @profgallaugher
    @profgallaugher  2 роки тому

    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

  • @manvirbhangu7755
    @manvirbhangu7755 2 роки тому

    Is there a reason that my rasp pi produces static sound?

    • @profgallaugher
      @profgallaugher  2 роки тому

      No idea. Perhaps someone on the Adafruit Discord channel has some suggestions.

  • @user-EricLin0619
    @user-EricLin0619 3 роки тому

    Why did terminal tell me " NameError: name 'speaker' is not defined? "

    • @profgallaugher
      @profgallaugher  3 роки тому +2

      "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!

    • @user-EricLin0619
      @user-EricLin0619 3 роки тому

      @@profgallaugher I have solved the problem, thanks for your reply!!!