CircuitPython School - Make Some Noise, playing wav files

Поділитися
Вставка
  • Опубліковано 6 січ 2025
  • NOTE: If you're NOT using a CircuitPlayground Bluefruit, some boards support audiopwmio, while others support audioio. If you replace the line:
    from audiopwmio import PWMAudioOut as AudioOut
    with the code below:
    try:
    from audioio import AudioOut
    except ImportError:
    try:
    from audiopwmio import PWMAudioOut as AudioOut
    except ImportError:
    print("This board does not support AudioOut")
    pass # Not all boards can play audio with AudioOut
    then the code should work on any CircuitPython board that has audio properly setup. For more on using audio with non CircuitPlayground boards, see later videos in this playlist, including: "Feel the Noise! .wav and .mp3 files on microcontrollers"
    ---
    Learn to play .wav sound files using CircuitPython on a CircuitPlayground Bluefruit (same code works on CircuitPlayground Express, as well). Part of Prof. Gallaugher's Physical Computing course. Like what you see? Let me know!

КОМЕНТАРІ • 19

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

    The CircuitPlayground Bluefruit has been out of stock so I am using the CircuitPlayground Express. In order to get this Lesson to work, I have to remove the NeoPixel code, quit Mu, eject my board, and when I restart with just this lesson, it works. The LED Animation Lesson did not work unless I commented out some of the animations. Since the Express is smaller, it cannot hold as much code as the Bluefruit. Amazing material!! Thanks for teaching!!!

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

    Some students are trying to use this tutorial on boards that don't support audiopwmio. If you are not using a CircuitPlayground Bluefruit & try this code, but get an error about audiopwmio not being available, try this code (btw: this code is introduced in later sound lessons in this series - including this will ensure your audio code works on board that use either audiopwmio, or audioio
    try:
    from audioio import AudioOut
    except ImportError:
    try:
    from audiopwmio import PWMAudioOut as AudioOut
    except ImportError:
    print("This board does not support AudioOut")
    pass # Not all boards can play audio with AudioOut

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

    Hi Paul. I'm having trouble finding the audiopwmio and audiocore libraries you are referncing. I'm using CP 8.0.5 and both the CPB & Pico. Have these changed names? Also looking for the library(s) need to play MP3 files. Hope you can point me in the right direction. Thanks.

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

      Hi. I’m not Paul, but if you look further down the playlist you’ll see several lessons covering both wav and mp3 play on the Pico.

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

      @@profgallaugher Sorry John. The libraries seem to be part of the general CP install and you don't need to do a separate copy of those libraries to the lib folder. I was trying to find the separate library files in the library bundle to no avail. When I just ran the code it worked fine. Might be worth noting that so others don't go searching (maybe you did and I missed it). Thanks.

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

    Is there a way to import the cpx library and activate the speaker in this code at the same time? I want to use the accelerometer as well but the cpx library seems to activate the speakers already. I get the error "ValueError Speaker_ENABLE in use" when I try to run this code

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

      Check out the CircutPlayground libraries. I tend not to teach these since they don’t translate to other non CircuitPlayground boards but you’ll find a play file command to play wav files as well as separate accelerometer commands. They should work together. circuitpython.readthedocs.io/projects/circuitplayground/en/latest/api.html

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

      I was able to avoid the circuit playground libraries by following your tutorials on accelerometers and parallel processing! thank you so much!

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

    Strange... I continually receive the error "ImportError: no module named 'audiopwmio'"

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

      That would show up if you were trying to use a library named audiopwmio and it wasn't imported properly. Make sure you have this line in your code:
      from audiopwmio import PWMAudioOut as AudioOut
      Also make sure you're using CircuitPython 7. I'm assuming you're using a device that's audio-capable, like the CircuitPlayground Bluefruit. The code presented should definitely work. If not, you can jump ahead to the video "CircuitPython School: Installing CircuitPython on Multiple Boards" and see if that library is part of the built-ins on your board.

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

      @@profgallaugher I'm using a CPE. I followed your directions to no avail, so I deleted the contents of the board and installed the latest .UF2 and libraries. Now when it crashes with "ImportError: no module named 'audiopwmio'", it also produces a core.py file which is a duplicate of code.py. Should I include the entire code.py file?

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

      @@profgallaugher Well, it's two weeks later and there has been no change. I am using the latest of everything. Many of your lessons after number 20 require audiopwmio so I'm not able to test them properly.

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

      I tried the CPE with a buzzer and "simpleio.tone(PIEZO_PIN, TONE_FREQ[i], duration=0.5)" instead; there was no issue.

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

      Some microcontrollers use audioio and others use audiopwmio. When I introduce "Playing .wav files from a microcontroller" I've updated the code to work on either one of these. This little chunk of code, instead of the from line used above, may work on the CPX. If you want an explanation of what's really happening in hear you can see the later video, but essentially it says "Can I use audioio on this board? No? Then can I use audiopwmio on this board? No? Then it prints a message if neither can be used, but I think you should be able to use at least one on the CPX. Here's the replacement code for the line that's giving you a problem:
      try:
      from audioio import AudioOut
      except ImportError:
      try:
      from audiopwmio import PWMAudioOut as AudioOut
      except ImportError:
      print("This board does not support AudioOut")
      pass # Not all boards can play audio with AudioOut

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

    where is the video for audacity

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

      Check the playlist. It’s the video named CPB Bonus Creating Your Audio Files for CircuitPython bit.ly/circuitpython-tutorials