Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Streaming Audio With Circuit Python?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Streaming Audio With Circuit Python?

by PunqRot on Sun Mar 22, 2020 7:10 pm

I would like to convert a project from AdaBox 004, Boomy, into CircuitPython.

I have most of what I need:
audiobusio - to handle the output
adafruit_esp32spi - to connect to a WiFi module (AirLift)
adafruit_sdcard.mpy - for config files

But I'm unclear on the existence of a module that will take an audio stream (e.g. SomaFM) and play it?

I'm fine with an "RTFM" type answer if someone could just point me to the "FM" I need to "R."

Thanks,

Chad

PunqRot
 
Posts: 40
Joined: Sat Jan 01, 2011 6:00 pm

Re: Streaming Audio With Circuit Python?

by tannewt on Sun Mar 22, 2020 7:38 pm

Hi Chad, we don't currently have a way to queue up more audio seamlessly as it comes in. I don't actually know much about audio streaming. What format is the incoming audio? Is it more like Wave or MP3? It may not be too hard to modify RawSample or Wave to allow for additional queuing.

What CircuitPython board are you using? Seems like you want something with a bunch of memory.

Sorry there isn't a manual! You'll be the first person to do this.

tannewt
 
Posts: 1727
Joined: Thu Oct 06, 2016 8:48 pm

Re: Streaming Audio With Circuit Python?

by PunqRot on Mon Mar 23, 2020 3:25 pm

Jinkies! That's about as definitive of an answer as one can get coming from the author of the language!

The link I should have provided is the one with the Arduino code to stream the source:
https://learn.adafruit.com/adabox004/internet-radio

And yes, it does appear to be MP3.

Is the ability to stream MP3 from HTTP something reasonable to add to a feature request?

PunqRot
 
Posts: 40
Joined: Sat Jan 01, 2011 6:00 pm

Re: Streaming Audio With Circuit Python?

by PunqRot on Mon Mar 23, 2020 3:26 pm

Oh. And it's the M4 express I was looking to use:
https://www.adafruit.com/product/3857

PunqRot
 
Posts: 40
Joined: Sat Jan 01, 2011 6:00 pm

Re: Streaming Audio With Circuit Python?

by tannewt on Mon Mar 23, 2020 4:31 pm

:-) I'll ping Jeff who added MP3 support and he'll reply here.

tannewt
 
Posts: 1727
Joined: Thu Oct 06, 2016 8:48 pm

Re: Streaming Audio With Circuit Python?

by jepler on Mon Mar 23, 2020 5:59 pm

I think it would be neat to see this added. However, it hasn't reached the top of my TODO list. There are two major things I know of that need to be reworked in the CircuitPython core to facilitate this.

First, right now it is a requirement that the MP3 to be played is a file on a FAT filesystem (though it can be on SD or internal flash). We need to lift this requirement so that it could be on any Python object that supports a few key operations (at least read() / recv()).

Second, the way we do buffering, we can only store up about 2kB of the mp3 stream ahead of time and if it takes more than a few ms to retrieve the next portion of the stream, playback will stop or glitch. We need to change the buffering so that the size of the buffer can be increased according to an application's needs, and so that the buffer can be filled at a time that doesn't glitch playback if it takes more than a few ms.

jepler
 
Posts: 23
Joined: Mon Oct 28, 2013 4:16 pm

Re: Streaming Audio With Circuit Python?

by PunqRot on Mon Mar 23, 2020 6:04 pm

Thank you both for looking into this. I'm glad I wasn't missing something obvious.

Clearly, this isn't something that can or would get done quickly, but does this have enough value to make it onto the roadmap? If so, I'll wait for it. This project is old enough I'd rather wait and do it this way.

Otherwise, I'll go back to the drawing board which is fine, too. As my wife and I like to say, "#alwayslearning"

PunqRot
 
Posts: 40
Joined: Sat Jan 01, 2011 6:00 pm

Re: Streaming Audio With Circuit Python?

by tannewt on Mon Mar 23, 2020 10:31 pm

PunqRot, don't wait for us on it. If you'd like to take a stab at it let us know and we're happy to give guidance.

Adding support for the ESP32-S2 into CircuitPython is coming soon (once we get hardware) and a much higher priority. Once that is up and going we *might* add MP3 streaming but we'll see where we are at that point.

tannewt
 
Posts: 1727
Joined: Thu Oct 06, 2016 8:48 pm

Re: Streaming Audio With Circuit Python?

by PunqRot on Tue Mar 24, 2020 2:00 pm

PunqRot, don't wait for us on it. If you'd like to take a stab at it let us know and we're happy to give guidance.


Ooooooh. Would that I could, sir. I'm merely a hacker, not a real developer. I can piece together code and modify that which exists. While I used to write new modules and what-not in my Perl or PHP days, my Python is still very much in "tinker" mode.

The original (approaching three years on-and-off) version of this project started as a Pi using npm, some neopixels, and a couple of rotary encoders. But after getting that AdaBox, my mind already transitioned to an Arduino-based system. But I didn't like the SD card support for Wi-Fi info and station configurations. That's why I really liked CircuitPython. Also I like the idea of being able to make minor changes on-the-fly without having to rip stuff apart and go back to my IDE.

I'll wait and see. In the meantime, I'll take another crack at finishing my Pi-based system. After all, I have a lot more free time on my hands these days.

PunqRot
 
Posts: 40
Joined: Sat Jan 01, 2011 6:00 pm

Please be positive and constructive with your questions and comments.