Which solution to play larger soundfiles at specific timestamps

Hi,

for my current project I want to play long soundfiles ( up to 7h) at specific timestamps inside those files. The reason is I want to build a fake radio with different channels and I want the timeline to be consistent when switching back and forth between channels.

I have done some audio projects in the past and usually used the DFplayer mini in combination with an Arduino Nano or similar. Unfortunately the mini does not support jumping to timestamps if I understood the documentation correctly. Also I would like to have a little bit more amplification power if possible than the mini provides. Either onboard or with an additional module. The DFPlayer pro has these features but it only has 128mb memory which will not be sufficient to store the audio files I want to play. Now I am contemplating different solutions.

DFPlayer Pro + additional SD Storage: I already used the DFplayer mini and it worked nicely but I have not used external storage if thats even possible. If not this solution is out of the question.The internal storage is too small.

ESP32 Audio Kit: This seems to have all features on one board and much more but I only found some rather complicated libraries which seem to be overkill for my project. While I already did some projects I am not sure whether I have a deep enough understanding to use this solution. I am willing to learn but I could only find very limited documentation how to use the Audio Kit.

Is there another solution that I have not found in my research? I need:

  • Arduino functionality for some LEDs, switches, rotary encoder
  • if possible battery connector, but external module is also fine
  • Audio Playback functionality with the function to play specific tracks and jump to timestamps inside the tracks
  • audio amplification, internal or external
  • good documentation

Thanks for your input.

Teensy has a rich Audio library and great 32 bit MCUs and an audio board

Maybe a Raspberry Pi which has an operating system/file system and a built-in soundchip. You might even find an existing app that does what you want.

You'd still need an amplifier or amplified "computer speakers".

...The DFPlayer is limited because the microcontroller can't directly access the SD card.

I’m not sure I’ve understood your project plan. Could you not store ALL ‘timestamp tracks’ on the huge mini SD capacity accessible to the DFR player? When any track commences, note the time. When the actual playing time reaches one of your timestamps, play the appropriate track. Etc.

I am not sure whether I understand your suggestion. I have ~20 audio files with lengths from 1h to 7h. If I understood you correctly you are suggesting to split up the long audio files into smaller tracks allowing me to adress them by file, not by time stamp. This would be a huge effort.

Thank you for the suggestions. I don't fully get the teensy audio library. There are really a lot of great functions but I have not found the simple functions to play mp3 and jump to a certain timestamps. I am also in Germany so I am not sure about the shipping.

The more I research the more I get the feeling the jump to timestamp seems to be my main problem. I did not find any compact solution up to now that supports jumping to a timestamp.

Ok, thanks, that confirms my suspicion that I have not fully understood what you are trying to do. Could you clarify further. Taking one of your 20 ‘long tracks’ as an example, what logic is applied as you play it to recognise one of your ‘jump’ points? What action then occurs? When that is complete, what next? Etc.

I have made a couple of Arduiino/ESP32 mp3 players using the VS1053 modules. They are cheap exceptionally good sound quality both have SD card holders and the Arduino libraries are already there.

Here are a couple of links one is Amazon and the other is Adafruit, my choice is Amazon but both do the same job.

both require some kind of amplifier or speaker. I used a BLE transmitter for earbuds or bluetooth speaker.

Apart from making mp3 players I also made an internet radio and did that using the Nano ESP32 and Micropython

These long audio tracks are meant to be radio stations but with fixed prerecorded music tracks and radio talk and ads inbetween. Thats why I have them in one long file rather than a playlist. I want there to be a consistent timeline when switching between stations. Meaning, when I switch from Channel A to Channel B and listen there for a minute and then switch back to Channel A, it should play like Channel A was running the whole time (e.g. still the same song/talk is on but progressed 1 minute). A precision +-5 seconds or so would be fine. To do this I assumed it is best to have a consistent timeline and when switching channels jump to the timestamp in the track of this shared timeline.

@sumguy This seems very promising. Can you confirm that the libraries actually feature a "play track at position/timestamp" function? This is critical for my project and not (easily) possible with most hardware/library combinations. Can you comment what amplifier and speaker combination you used for your internet radio? Sound quality is not the highest priority but I want to get the best possible under the constraints I have.

@terbsen I created my own method of keeping track of position, the mp3 stream is fed to the player from a file on the SD card so you have to keep track of the file name and the number of bytes already played, when you pause the number of bytes is stored in nvr and recalled when you resume.

This transmitter is tucked away inside the box

Ok, unfortunately I think this would not work for me. To my understanding the bitrate is not constant of mp3 files, therefore simply counting bits could lead to different speeds / tracks going out of sync. While searching the web for the VS1053 I stumbled upon this. It sounds like a solution for my problem but I have trouble fully understanding:

https://forums.adafruit.com/viewtopic.php?t=123646v

@terbsen whatever works for you is good.
I have to correct your line of thinking, you don't count bits you are streaming bytes from an SD card, so imagine you have a 50000 byte sound sample , if you wanted to skip to the half way point you would 'seek' to byte 25000 in the sample.
Keep us informed of your progress.

To write to it, yes, which I’m sure is what you meant. But for those unfamiliar with the device, of course it can access the SD card via the module to read track and folder data, busy status, volume, etc. Not sure about the ‘directly’ distinction?

I think it is adressing the DFPlayer Pro. The DFPlayer Mini has the onboard SD Slot but I have not found a solution how I could access an external SD Card with the DFPlayer Pro, which only has 128mb of internal storage. But this could be possible, I just have not found a solution yet that works with my limited knowledge.

Ok, understood. Then it seems clear that the DFR player can be ruled out as the basis for a solution.

I’m curious: is it just the challenge? Why are you trying to accurately emulate a 20 channel radio? Stage prop?

How many stations would you have ?

May be just having multiple DFPlayers playing in parallel with only one output routed to the speakers would do ? Then when switching radio channels the others keep playing, like in real life, stations keep broadcasting.

I once developed a speaking clock project which used a singe (relatively) long WAV file for all the voice phrases and the program jumped around in this file to assemble the time announcements, for example "At the third stroke it will be nine eleven and thirty seconds beep beep beep".
You can do this with a WAV file because it is uncompressed and has no codec encoding so you are free to jump around in it.

I suppose you could do the same. If you have say 20 sound files, one for each of 20 radio stations and you have a clock running, you can jump in to the appropriate point into the selected file as the user selects another channel.

The project is here : Arduino ESP8266 Speaking Clock and in the meantime I have an ESP32 version (not yet published) but, in principle, you are simply using the file system seek command to jump into the right place (based on a clock) in the right file as the user switches channel.

Maybe you find something useful there.

If it's not a stereo "radio" you're emulating, you could use L, R for two mono channels ─ for half as many players.

I think that’s the approx 20 long tracks that @terbsen mentioned at some point. I’m still not clear enough about the details. For example,
how long must the deception of continuity be maintained?

This topic was discussed before, but seemed inconclusive : MP3/WAV Board With Ability To Start at a Given Timestamp?

Finding an MP3 module with exactly the right features might be difficult. I would probably try a more low level approach.

The key problem being MP3 files don't have a timestamp as such, and may not have fixed length frames. Using a raw PCM/WAV format makes it very easy to seek to a location, at the expense of bigger files.

If you can process the files in advance, reading the MP3 files and creating an index might be an option. For a 7 hour file, an index to 1 second would be around 100kB.

Thanks for the suggestion. Which module and library would allow to play an audio file at a certain bit index?