Play MP3

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
yllumi
Posts: 37
Joined: Tue Aug 19, 2014 8:41 am
Location: Bandung, West Java, Indonesia
Contact:

Play MP3

Post by yllumi » Wed Apr 08, 2015 7:15 am

Hi everyone,
Is there anyone who tried to play MP3 file with micropython?
I have a small college task to simulate MP3 player with micropython board.
I have tried to play wave file using wave library, but it olny can play small size and short wav audio file.
Is it possible to play mp3 file directly from SD card just like wave library do?

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Play MP3

Post by blmorris » Wed Apr 08, 2015 1:04 pm

It is certainly within the capability of the pyboard's processor to decode and play MP3 files - this project was the first of many results when I searched Google for "stm32f4 mp3".
As far as I know nobody has done this on micropython yet, but it is on my (long) to-do list. The project that I linked to uses the STM32F4 Discovery board. It uses the USB OTG port in Host mode to read MP3 files from a USB flash drive, and sends the output via I2S to the Discovery board's codec.
On the pyboard it will be much easier to use the SD card for file storage. MicroPython does not yet have I2S support, so if you do manage to decode MP3's your only playback option at this point is to use the DAC outputs.
I am working on I2S support, and I am planning to post some preliminary code shortly, but it is still some way from working. I'll follow that with a daughterboard with an I2S codec so other people can use it too - I'm primarily a hardware engineer, so the daughterboard design will actually be easier than the software for me.
I'm afraid that none of my work will come in time to help for your 'small college task,' but do keep us posted if you get anywhere with MP3 decoding, and don't hesitate to ask for help!

-Bryan

User avatar
yllumi
Posts: 37
Joined: Tue Aug 19, 2014 8:41 am
Location: Bandung, West Java, Indonesia
Contact:

Re: Play MP3

Post by yllumi » Thu Apr 09, 2015 4:49 am

Thanks for the reply. That was a helpful clue. At least I then don't need to buy any external source like audio breakout since I knew the pyboard's processor is capable to do this job. I will then try using DAC output first.

symac
Posts: 11
Joined: Thu Jan 04, 2018 2:01 pm

Re: Play MP3

Post by symac » Thu Jan 04, 2018 2:08 pm

Anyone managed to do something about that during the past 2 years ? I just came around micropython and would be interested to use it to replace what I have been doing using Rpi + Python ( http://www.geobib.fr/blog/tag:jukidbox/page:2 ) so being able to play mp3 is a prerequisite. This thread seems to be the most advanced thing I have found. I found a solution using DFplayer cheap on https://github.com/ShrimpingIt/micropython-dfplayer but nothing directly on the board.

Any advice even if this thread is quite old now?

Thanks.

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: Play MP3

Post by SpotlightKid » Thu Jan 04, 2018 5:54 pm

The difference of the STM32F4DISCOVERY board vs the pyboard in this regard is, that the former has an hi-fi audio DAC on the board. Usually one needs to talk I2S to these chips, for which there is no support in Micropython. There is an abandoned PR from many moons ago to add I2S support, but it was unfinished and would now need serious reworking, because the repository layout has changed extensively in the meantime. (Just search for "I2S" in the github PR tracker.)

Update: oh, I see that @blmorris, the author of said PR already answered above...
Last edited by SpotlightKid on Sat Jan 06, 2018 6:26 am, edited 1 time in total.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Play MP3

Post by OutoftheBOTS_ » Sat Jan 06, 2018 4:10 am

Hopefully it may get added to the ESP32 in the future as the ESP32 has both DAC and I2S and also bluetooth for playing via a bluetooth speaker. When I use Raspberry Pi to play sound with Python I usually use a bluetooth speaker as it is easier than wires.

You could easily use something like this as an external MP3 device that is easily controlled my a MicroPython board https://www.ebay.com/itm/U-disk-audio-p ... SwWTRW1scV

symac
Posts: 11
Joined: Thu Jan 04, 2018 2:01 pm

Re: Play MP3

Post by symac » Tue Jan 09, 2018 1:15 pm

[quote=OutoftheBOTS_ post_id=24400 time=1515211808 user_id=3423]
You could easily use something like this as an external MP3 device that is easily controlled my a MicroPython board https://www.ebay.com/itm/U-disk-audio-p ... SwWTRW1scV
[/quote]
Yes, I had thought about ESP32 because of the DAC, and the external device should help in the decoding process, but what I would also like is to be able to control a screen from my controller to display the cover of the currently played album. That means I need to be able to access the microsd card containing all of that from the microcontroller. Maybe it is possible (and useful) to do it from the microcontroller and send the data to the external mp3 device for deciding, I don't know, need to do some tests.

For the moment, I am used to Raspberry Pi so don't really know what I will be able to achieve with ESP32/Micropython, I am waiting to get the hardware to make some tests, will let you know if I get to something (otherwise will switch back to RPi).

User avatar
bestazi
Posts: 3
Joined: Fri Jan 19, 2018 11:01 am

Re: Play MP3

Post by bestazi » Fri Jan 19, 2018 11:02 am

Thanks guys for info. :)

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: Play MP3

Post by loboris » Sat Jan 20, 2018 9:55 am

There is an excelent ESP32 MP3 Decoder project on GitHub.
It should be relatively easy to port the mp3 part to MicroPython, I have some plans to do it.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Play MP3

Post by OutoftheBOTS_ » Sun Jan 21, 2018 3:50 am

@laboris you are a machine :)

Since you are already planning writing a blue tooth library and you already have SD working in both 1 pin and 4 pins modes and TFT working super fast maybe you could look at adding a MP3 blue tooth sound module or MP4 sound/TFT to the blue tooth library your writing. Blue tooth speakers are easy way as all the needed hardware is in the blue tooth speaker (I2S to DAC to amp to speaker with battery to power the amp)

Post Reply