Monday, June 24, 2024

ESP32 I2S Audio Processing – Guide

Tested DIY

Audio processing, voice recognition, and efficient data transmission have become integral aspects of modern technology. In this step-by-step guide, we explore a hands-on ESP32 I2S Audio Processing project that leverages the I2S (Inter-IC Sound) interface and ESP32 microcontroller.

By utilizing the I2S interface, which supports high-quality digital audio data transfer, this project aims to capture audio input signals from external sources and process them within the ESP32, which can be used to perform specific audio processing algorithms.

ESP32 I2S Audio Processing Hardware

Additionally, the I2S functionality will be employed to facilitate the transmission of processed or recognized audio data to other devices or systems, enabling seamless communication and integration within larger audio-centric applications or networks.

Here we try to attach the I2S-based MEMS mic array and then try to get the I2S buffer data and display it on port in real time.

Also Check: E-Paper Clock using ESP32

- Advertisement -

The components needed are listed in the table below.

Bill of Materials

ESP32/Indus Board1Microcontroller400
Jumper Wire5Female-Female10

ESP32 I2S Audio Processing – Coding 

Here we are using Arduino IDE. First, the I2S driver is initialized in code by default. This driver is pre-installed in the board manage library but in case it is not there, then install this library in Arduino IDE. 

Now we are ready to code. First, you need to include the I2S driver library in the code, then you can configure the input like a sample rate or bit rate for audio capture and other things in the code 

- Advertisement -
Arduino IDE I2S Driver Library
Fig 2. Code configuration

Next, you need to set the pins for the I2S interfacing in the code. 

It typically consists of three lines:

  • Serial Data (SD): This line carries the actual audio data in a serial format.
  • Word Clock (WS or LRCLK – Left/Right Clock): This line is responsible for indicating the beginning of each audio sample. It helps synchronize the sender and receiver so that they know when to read the data.
  • Bit Clock (BCLK): This line carries the clock signal that determines the rate at which the bits of audio data are transmitted.

Additionally, there might be a fourth line for a Master Clock (MCLK) in some configurations. MCLK provides the master timing reference for the audio data transmission.

Here in the code, I have used GPIO 26, 22, and 25 for these I2S pins.

Now create the setup function and then the loop function and set the code to capture the audio data and display it in the serial monitor.

Code for ESP32 I2S Audio Processing
Fig 3. Pin setting 

Also Check: ESP32 based ChatGPT Terminal

Circuit Diagram

Now connect the components according to the following circuit diagram.

ESP32 MEMS I2C Mic Connection
Fig 4. Connection 


After uploading the code open the serial monitor. You can see the I2S data; you can also open the serial plotter to visualize the serial data.

ESP32 I2S Audio Processing Data
Fig 5. Sound data 
ESP32 I2S Audio Processing Visual Graph
Fig 6. Sound data graph

This project showcases the synergy between hardware, represented by the I2S mic array and ESP32 microcontroller, and software encapsulated in the Arduino code. The I2S interface emerges as a crucial component, ensuring high-quality digital audio data transfer.

By combining audio processing, voice recognition, and efficient transmission, this project opens doors to a myriad of applications within the audio-centric domain. As technology continues to evolve, the marriage of I2S and ESP32 promises innovative solutions for the future of audio processing.

Ashwini Sinha
Ashwini Sinha
A tech journalist at EFY, with hands-on expertise in electronics DIY. He has an extraordinary passion for AI, IoT, and electronics. Holder of two design records and two times winner of US-China Makers Award.


Unique DIY Projects

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components