schreibfaul1 / ESP32-audioI2S

Play mp3 files from SD via I2S
GNU General Public License v3.0
1.08k stars 284 forks source link

Is it possible to play an mp3 from char array? #671

Closed Emmanuele75 closed 4 months ago

Emmanuele75 commented 8 months ago

Hi everyone! I would like to play a sound (beep) by loading it directly into a char array. Example:

const unsigned char beep_mp3[] = { 0x49, 0x44, 0x33, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x54, 0x53, 0x53, 0x45, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x03, 0x4c, 0x61, 0x76, .........

There's no way I can get this. Can anyone help me? Thank you.

akakhtar commented 7 months ago

Use tone function of arduino to play beep sound

sartyx commented 7 months ago

Same question here and no, it is not about beeps. I just want to store the audio internally because I don't want to add any external memory such as SD or even a stream.

Doesn't have to be mp3 for my usecase though.

unsigned const char WavData[35564] = {
  0x52, 0x49, 0x46, 0x46, 0xe4, 0x8a, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45,
  0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 
[...] and so on 
amarotica commented 6 months ago

I'm looking for the same functionality. I converted a WAV to RAW to a header file and a feature that could then play that included .h file would be awesome!

schreibfaul1 commented 6 months ago

Why should it be so complicated? You can save the audio file directly as SPIFFS or in an FFat partition without RAW conversion.

sartyx commented 6 months ago

There are reasons for that, first is, not all ESP32 support SPIFF even if they should second is data from an array is faster which can be an issue if you want to play sounds on button press for a game.

robertmuth commented 5 months ago

A design change the would make this easier:

With this change, if I have an in-memory file, I could just write a simple AudioStream wrapper for it and hand it to class Audio for playing.

Maybe Audiostream can be made general enough to also include web streams which would allow for moving a lot of code out of the class Audio.

github-actions[bot] commented 4 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 4 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.