Sending "audio" data trough bluetooth

Hello !

I want to make a little bot ( like an Alexa voice assistant ), so for that i used a little robot in kit that contains these pieces :

  • SD card reader
  • 2 Speakers
  • Bluetooth ( BT16 4.0 )
  • 1 mic module

So i need to pass my voice from the robot to the computer, then the audio response generated from my computer to the robot and since there is a bluetooth intagreted in it i will make with that

its impossible ( at least not wished ) to make thing like voice<--->text directly on the Arduino

So I need to have an audio file ( MP3, WAV or whatever ) on the arduino and no text

So my think is that :
I need to save my voice from mic module to SD card ( as temp) then send it by bluetooth to the computer

Then the computer need to transform thé answer as an audio file like mp3 then send it to the robot by Bluetooth and the robot will save it on the SD card then play it

But i think i need to send the MP3 as data like any kind of text data or whatever maybe creating some kind of bus

But i really dont know how to do that and the speed of the transfer ( think the speed will depend with the distance between robot and computer and also the size of the MP3 )

Also voice and answer dont need to be long files and there is no need to stream the sound i think with my actuals components its preferable to make the save on the SD then play it ( i plan to play some kind of elevator music to let the user wait )

Dont know if my Ask is clear, dont hesitate to ask me for more details if needed, thanks a lot at least for the read :slight_smile:

At this point, the only detail missing is which of all the things you have mention, have you actually made to work?

Almost everything ( playing MP3 file, all the computer code in python )

Here I just dont know how to (in practice) send MP3 file from the computer to my robot using bluetooth

You are not sending MP3 files, you are just sending bytes. make no difference where the bytes come from or where they go. Can you ready bytes from a file identified as being MP3?

Thanks !
No at the actual state I don't really know how to get bytes from a MP3 file ( or any other kind of file )

Maybe there is a tuto about that ?

Also After I will need to send bytes by one send or by packet ?

Much simpler solution: bluetooth microphone to send audio to computer; bluetooth speaker on which the computer's answer is played back.

So far I don't see anything in your project description that needs to access the stored information on the Arduino after the one time playback.

Playing back mp3 that is sent to an Arduino via bluetooth is not trivial: you need an mp3 player for that (like the DF Player), and something like SD card storage to store it. So you'd need an mp3 player that can read from the SD card the Arduino can write stuff to. That's probably possible but appears very complex to me.

Open the file in binary mode, then read each byte from beginning to end and send via BLE (or whatever) to the arduino

I already had a payer in the robot

In fact the robot can play multiple MP3 stored in the SD card

Also using bluetooth mic and bluetooth speaker is outside of my scope since I need all the stuff to be in the robot

But its a nice idea, the robot is also composed with 4 servos but i will not use them at start maybe later to interaction at certain voice record

Oh okay simple as that

Thanks a lot I will try it, did you think the transfer will be long ? And if yes what could be a better way to transfer stuff like that ( short MP3 file ) ?

Bluetooth Low Energy (BLE) is optimized for low power consumption, not speed. It has a maximum rate of 1mBit/second, so a 100kB file would take 1 second at best.

However, if all you're doing is transferring audio back and forth, there is already a BLE protocol for that which is already supported by ESP32 arduino: A2DP. I would suggest researching it and seeing if it's more suitable for what you want to do.

Oh okay thanks in fact 1S for 100kb IS perfectly reasonable since I Can compress the audio and lost quality ( i do not stream music only sentences )

I will test with that first and next will see about the A2DP protocol, since I use an Arduino nano and a bluetooth module included in the robot kit I will check if its possible

I don't want to change the nano for an esp32 but its nice to see that there is a preferable way with that if i change my mind

Thanks a lot for your help I will come back after my attempt to let you know if things work well with classic bluetooth data transfering

Come back to give some update

In fact I didnt see well but my robot kit only allow BLE as wireless connection

And After checking the datasheet better of the module, it Say :
Packet of 280 byte
And 70ms between each

Its about 71second for a 290kb MP3/WAV

So since BLE isnt suited for large data transfering and since the data transfer IS relatively slow i will let the Idea behind for now,

What do you think about passing the MP3 file datas trough USB ( letting the robot always connected to my computer ) is this could be a better option ?

I think that if I cant find any solution I will replace everything with a Raspberry pi zero at the end ( and use wifi to avoid doing heavy computer on it )

Does the computer have a limited set of potential responses? Or are they generated on the fly?

In the first situation you can store all of them on an SD card on the robot, and simply have the computer tell the robot which one to play, rather than transfer the whole file.

In fact response are generated on the fly :frowning: ( using chatgpt api )

So I can't do that, I think the best solution is to go for a little raspberry pi zero since the bluetooth is solded on the shell sell in the robot kit ( the kit is the elegoo penguin 2.0 )

I can change the Arduino nano provided for an esp32 like but this will need some additional work since replacing the board+shell with a Raspberry pi zero is simpler I think

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.