ESP32 Audio File Player Project

Last Updated on February 3, 2025

Standalone Audio players are readily available in market and its very simple to build, but if your project only needs to play few second audio or Audio file for notifications or instructions, you don’t need to build bulky and costly audio player along with project design. Instead of reading audio files from external storage use the following simple and effective solution. ESP32 Audio File Player Project utilizes an ESP32 microcontroller to convert internally stored audio data into analog signals, which are then amplified using a single BC547 transistor to drive an 8-ohm speaker.




Why we are doing this project because, most DIY audio player or audio notification projects depends on the external SD cards, external memory and DAC modules with complex coding. But this project uses ESP32 microcontroller and its internal DAC to play audio or audio file. You can try it with other microcontrollers with either internal or external DACs. Here we store Audio file (WAV) as HEX code in the memory of ESP32 through headerfile then make it play and convert as Analog signal using internal DAC and then taking analog audio output (with lower resolution) through GPIO pin (25). To make audio louder we use Single Transistor Audio Amplifier using BC547. Finally you can hear the sound from speaker while ESP32 microcontroller reads the audio file. This project perfect for lightweight applications like alarms, voice notifications, or retro sound effects.

ESP32 Audio File Player

Wiring Diagram

Schematic Diagram

Required Components

  1. ESP32 Development Board (DOIT Devkit V1)
  2. 8Ω Loud Speaker
  3. Transistor BC547 (NPN)
  4. Resistors 2.2KΩ, 10Ω each one
  5. Connecting Wires
  6. 5V DC power supply
  7. Breadboard
  8. Computer

Working Video

Construction & Working

The ESP32 microcontroller includes two built-in digital-to-analog converters (DACs), both of which offer 8-bit resolution. These DAC channels are typically available on GPIO25 and GPIO26. This configuration allows you to output analog voltage levels directly from the microcontroller from 0 to the reference voltage (typically 3.3V), which is especially useful for applications such as audio playback, here we used GPIO25 pin (DAC1) as audio output pin. Connected GPIO25 to the base terminal of BC547 transistor. Speaker Positive terminal is connected to the +5V Supply and negative terminal of speaker is connected to Collector terminal of transistor. Between collector and base terminal there is a 2.2KΩ Resistor used to give enough Base Voltage (VB). Emitter terminal is connected to the Ground through 10Ω Resistor.

Let’s start to make Audio File and Firmware to feed to ESP32.

ESP32 deals with only HEX code (machine level language)., so we need to convert the Audio file into HEX before that Audio File should be in .WAV format, if your audio in mp3 or any other format then you have to convert it to .WAV, here is the simple way to do it.

Open Audacity Audio Editor software and import your audio the make sure that it is in mono track, if not make it mono that is in single track, then trim it to 5 Seconds or 6 Seconds length (Because the ESP32 have little memory). Then export it in WAV format.

Make sure to select mono channel, Sample Rate between 8000 to 16000 Hz then Encoding as Unsigned 8-bit PCM (Because the ESP32 DAC resolution is 8 bit) and then export, Now we have the AudioFile.wav

Let’s Convert AudioFile.wav to HEX

To feed the AudioFile into ESP32 we need it in HEX code format, here is the method to do it. First thing to have is HxD converter app, just download and install HxD Converter, then open the AudioFile.wav, immediately this app will convert it into HEX code.

Then Export this HEX code as C and save it as AudioFile.h (this is the header file we are going to use in Aruduino IDE)

Next step is to have XTronical DAC Audio library to Play a digital WAV AudioFile or recording through code. You can get XTronical DAC Audio library here, then install it on your Arduino IDE before start coding.

Arduino Code for ESP32 Audio File Player Project

/*code from theoryCIRCUIT.com */

#include "AudioFile.h"
#include "XT_DAC_Audio.h"

XT_Wav_Class Sound(rawData);     
                                      
XT_DAC_Audio_Class DacAudio(25,0);

uint32_t DemoCounter=0;               

void setup() {
  Serial.begin(115200);               
}


void loop() {
  DacAudio.FillBuffer();                
  if(Sound.Playing==false)       
    DacAudio.Play(&Sound);       
  Serial.println(DemoCounter++);        
}

get our AudioFile.h header file here or you can make your own.

Steps to Remember:

  1. Choose Audio File within 5 to 7 Seconds length.
  2. Make it .WAV file with mono channel, Sample Rate between 8000 to 16000 Hz then Encoding as Unsigned 8-bit PCM
  3. Convert this into HEX code and make it as header file like (AudioFile.h)
  4. Install XTronical DAC Audio library in Arduino IDE
  5. Upload the Code to ESP32
  6. Use 5V DC supply to power single transistor amplifier.

If you have any doubts you can ask in the comment section our team is happy to help you.




Leave a Reply

Your email address will not be published. Required fields are marked *