0% found this document useful (0 votes)
44 views

reciving and playing audio files through esp 32

The document outlines the process of receiving, storing, and playing audio files via Bluetooth using an ESP32. It details how to transfer audio files, play them through Bluetooth speakers or I2S speakers, and includes code snippets for receiving, playing, and deleting audio files stored in SPIFFS or LittleFS. The document also emphasizes the need for an MP3 decoder for playback and provides necessary programming examples for each function.

Uploaded by

Jeevan Rm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

reciving and playing audio files through esp 32

The document outlines the process of receiving, storing, and playing audio files via Bluetooth using an ESP32. It details how to transfer audio files, play them through Bluetooth speakers or I2S speakers, and includes code snippets for receiving, playing, and deleting audio files stored in SPIFFS or LittleFS. The document also emphasizes the need for an MP3 decoder for playback and provides necessary programming examples for each function.

Uploaded by

Jeevan Rm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Reciving and playing audio files through blutooth and .

deleting them

1. Receiving Audio Files via Bluetooth and Storing Them

We can transfer audio files over Bluetooth using Bluetooth Serial (SPP) or Bluetooth Low
Energy (BLE) and store them in SPIFFS, LittleFS

How It Works:

1. A mobile or PC sends an audio file (MP3/WAV) to ESP32 over Bluetooth.

2. ESP32 receives the data and stores it in SPIFFS or an SD card.

3. Later, ESP32 can play the stored file using an I2S DAC modul

2. Playing Stored Audio via Bluetooth or Speaker

Once the audio file is stored, you have two ways to play it:

(A) Play Audio via Bluetooth (A2DP Source)

ESP32 can act as a Bluetooth audio transmitter (A2DP Source).

The stored audio file is sent to a Bluetooth speaker for playback.

Needs an MP3 decoder (like Helix MP3) if stored in MP3 format.

(B) Play Audio via I2S Speaker

ESP32 has an I2S (Inter-IC Sound) interface that works with DAC modules like MAX98357A.

The stored file (MP3/WAV) is read and played via a connected speaker.
1 NESSASARY PROGRAM REQUIRED

This method receives an audio file over Bluetooth, stores it, and plays it through an I2S speaker.

1. Receive and Store Audio File via Bluetooth

#include "BluetoothSerial.h"
#include "SPIFFS.h"

BluetoothSerial SerialBT;

void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32-Audio-Receiver");

if (!SPIFFS.begin(true)) {
Serial.println("SPIFFS Mount Failed");
return;
}
}

void loop() {
if (SerialBT.available()) {
File file = SPIFFS.open("/audio.mp3", FILE_WRITE);
if (!file) {
Serial.println("Failed to open file");
return;
}

while (SerialBT.available()) {
file.write(SerialBT.read());
}

file.close();
Serial.println("File saved!");
}
}
2. Play Stored Audio File via I2S

#include "Arduino.h"
#include "Audio.h"

Audio audio;

void setup() {
Serial.begin(115200);
audio.setPinout(26, 25, 22); // I2S connections
audio.begin("/audio.mp3", "SPIFFS");
}

void loop() {
audio.loop();
}

1. Deleting Audio Files from SPIFFS or LittleFS

audio files are stored in SPIFFS or LittleFS, We can delete them using the remove() function.

Required program

#include "SPIFFS.h"

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

if (!SPIFFS.begin(true)) {
Serial.println("SPIFFS Mount Failed");
return;
}

if (SPIFFS.remove("/audio.mp3")) {
Serial.println("File deleted successfully");
} else {
Serial.println("File deletion failed");
}
}

void loop() {
}

This code deletes the file /audio.mp3 from SPIFFS.

The same method works for LittleFS (LittleFS.remove("/audio.mp3")).

You might also like