Turn Your ESP32 Into a Bluetooth Speaker (No Extra Hardware Required)
If you've ever wanted your ESP32 project to stream audio from your phone or laptop, you know it's usually a pain. You either need extra components, complex libraries, or you're stuck with low-quality audio.
This library changes that. It implements the A2DP (Advanced Audio Distribution Profile) protocol directly on the ESP32, using its built-in Bluetooth. That means you can turn your ESP32 into a Bluetooth speaker with just a few lines of code, no external DAC or audio module needed.
What It Does
The ESP32-A2DP library by pschatzmann is an Arduino-friendly implementation of the Bluetooth A2DP source (transmitter) and sink (receiver) profiles. In simpler terms, your ESP32 can:
- Act as a Bluetooth speaker (receive audio from your phone)
- Act as a Bluetooth audio source (send audio to another speaker)
- Handle multiple connections
- Output audio via I2S, internal DAC, or even just PWM
It's designed to work with the Arduino framework, so if you've used ESP32 with Arduino IDE or PlatformIO, you're good to go.
Why It's Cool
Here's what makes this project stand out:
No external hardware required. You can use the ESP32's built-in DAC to drive a simple speaker directly. No need for a dedicated audio decoder chip like a MAX98357 or PCM5102.
Real A2DP, not fake Bluetooth. This isn't some stripped-down audio protocol. It's proper A2DP with SBC codec support, so audio quality is comparable to a standard Bluetooth speaker.
Simple API. You can literally get audio playing in 5 lines of code. Check this:
#include "Audio.h"
#include "BluetoothA2DPSink.h"
BluetoothA2DPSink a2dp_sink;
Audio audio;
void setup() {
a2dp_sink.start("ESP32_Speaker");
}
void loop() {
// nothing needed
}
Works with both source and sink mode. You can stream audio from your ESP32 to a Bluetooth speaker, or receive audio from your phone. Both directions work.
Good documentation. The repo has working examples for I2S, internal DAC, even a web-based volume control.
How to Try It
You have two options:
Option 1: Arduino IDE
- Install the library via Library Manager (search "ESP32-A2DP")
- Open File > Examples > ESP32-A2DP > SimpleSink
- Upload to your ESP32
- Connect your phone's Bluetooth to "ESP32_Speaker"
Option 2: PlatformIO
- Add
lib_deps = pschatzmann/ESP32-A2DPto platformio.ini - Copy one of the examples from the repo
- Build and upload
For the simplest test, just connect a small speaker to GPIO25 (DAC output) and GND. That's literally all you need.
Final Thoughts
This library fills a real gap. A lot of ESP32 audio projects focus on voice assistants or MP3 playback from SD cards, but streaming audio from your phone is something people actually want.
If you're building a retro radio, a custom Bluetooth speaker, a smart mirror that plays podcasts, or just want to learn about A2DP on embedded hardware, this is a solid choice. It's not perfect (SBC only, no AAC or aptX), but for casual audio it works surprisingly well.
Give it a shot. You'll probably have audio playing in under 10 minutes.
Brought to you by @githubprojects