Let’s make a Bluetooth microphone I said to myself, how hard can it be? A quick thanks to https://www.PCBWay.com/?from=atomic for sponsoring the channel.

We’ve already made a Bluetooth speaker so making a Bluetooth microphone should be easy.

So, What are we doing in this video?

So, what’s the issue with the A2DP Bluetooth profile - we used this to create our Bluetooth speaker in a previous video. This is trivially easy and required just a few lines of code with some helper libraries.

What’s more, you can also output audio using the A2DP Bluetooth profile, this also just requires a few lines of code.

The problem is, my PC and most probably your PC is not a Bluetooth speaker - so it’s not going to pick up our A2DP source as a potential input it can use. It’s simply not the way the standards have been defined and implemented.

The alternative is to use the Hands-Free Profile or HFP. This is used by hands-free kits to communicate with mobile phones and now that we spend all day on Zoom calls, computers.

The Hands-Free Profile defines two roles, an Audio Gateway known as AG and a Hands-Free unit known as HF. We’re going to turn our ESP32 into a hands-free unit. This will let it connect to our computer which will quite happily act as an audio gateway. This will then let us send audio data from the microphone to the computer.

There are several issues with this:

The first is a fundamental issue with the codecs used. These are limited to 8KHz or 16KHz sampling rates.

As we know from our previous videos on audio input on the ESP32 8KHz is just about good enough for speech, but it’s not great. Unfortunately in my experiments with the ESP32 and the computer I’ve not managed to get them to agree to the 16KHz sampling rate. So I’m stuck with 8KHz. My phone will however connect at 16KHz so will get slightly better quality.

The second issue is just getting this to work. I tried running the examples in the ESP-IDF and hit a number of problems. The main one being that it was unable to stay connected for more than a few seconds. The code is also pretty hard to understand.

I have however managed to find an alternative Bluetooth stack that seems to be stable and has sample code that I was able to understand and get to work.

This gave me a working handsfree system, but it’s not really good enough as a microphone.

I really wanted a wireless microphone.

So I’ve made it work using TCP sockets and a bit of duck taping using a virtual audio driver.

Success!? - I’ll let you be the judge of that…

You can find the code for the handsfree profile here: https://github.com/atomic14/esp32-hsp-hf please do not attempt to use it unless you are experienced with the IDF and Bluetooth - I won’t be able to provide any help or support.

And you can find my wireless microphone code here: https://github.com/atomic14/esp32_wireless_microphone


Patreon: https://www.patreon.com/atomic14 ko-fi: https://ko-fi.com/atomic14