As you might know from my last posts I am currently extending my Arduino Audio Tools library to support the AI Thinker Audio Kit which is based on the ES8388 audio chip.

The AI Thinker ESP32 AudioKit was raising my interest because it also provides audio input in the form of built in microphones and an line-in jack.

Audio Kit

So far I demonstrated how to output sound to the AudioKit and it is about time to look into the input of audio.

The simplest functionality I can think of is to input the audio signal from the jack and output it via the speaker.

Arduino Sketch

Here is the sketch:

#include "AudioTools.h"
#include "AudioLibs/AudioKit.h"

using namespace audio_tools;  

AudioKitStream kit; // Access I2S as stream
StreamCopy copier(kit, kit); // copy kit to kit

// Arduino Setup
void setup(void) {
    Serial.begin(115200);
    AudioLogger::instance().begin(Serial, AudioLogger::Warning);

    auto cfg = kit.defaultConfig(RXTX_MODE);
    cfg.input_device = AUDIO_HAL_ADC_INPUT_LINE2;
    kit.begin(cfg);

}

// Arduino loop - copy data
void loop() {
    copier.copy();
}

It is amazingly short – because all we need to do is to copy from the kit (input) to the kit (output). I just needed to specify the input device to be AUDIO_HAL_ADC_INPUT_LINE2, which is the audio jack!

I connected the output of my IPAD to the audio jack of the AudioKit, pumped up the volume and … the music was playing!

Dependencies

You need to install the following libraries:

Github

The (up to date) example source code can be found on Github and is available in the Arduino examples when you install the libraries.

Addendum

After some playing around I confirmed the open bug, that both the microphone line and aux in are active at the same time!


14 Comments

Camilo · 2. September 2022 at 3:44

hello!! I don’t know if I missed my previous comment,
I wanted to ask you a favor if you know how I could record several audios, with different names with the same code, for example record 5 seconds of audio1, then another 5 of audio 2 and thus create several files, because when trying it creates only 1 file and others will break the code

there is mi code
#include “AudioTools.h”
#include “AudioLibs/AudioKit.h”
#include “SdFat.h”
#include “AudioKitHAL.h”

int channels = 1;
int samples_per_second = 44100;
int bits_per_sample = 16;

AudioKitStream kitStr; // Audio source
SdFat SD;
File audioFile;
// final output stream
EncodedAudioStream out_stream(&audioFile, new WAVEncoder()); // encode as wav file
StreamCopy copier(out_stream, kitStr); // copies sound to out
AudioKit kit;
unsigned long myTime;
void setup(){
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Info);

// setup Audiokit
auto cfg = kitStr.defaultConfig(RX_MODE);
cfg.input_device = AUDIO_HAL_ADC_INPUT_LINE1;
cfg.channels = channels;
cfg.sample_rate = samples_per_second;
cfg.bits_per_sample = bits_per_sample;
kitStr.begin(cfg);

// we need to provide the audio information to the encoder
out_stream.begin(cfg);
// open the output file
SD.begin(SdSpiConfig(kit.pinSpiCs(), DEDICATED_SPI, SD_SCK_MHZ(2)));
audioFile = SD.open(“/proyecto/RecordTest1.wav”, O_WRITE | O_CREAT);

}

void loop(){
myTime = millis();
if(myTime <= 5000){
copier.copy();
}else{
audioFile.close();
}

}

Bhola khawas · 6. July 2022 at 17:20

Hello sir Thank you so much for the audio-tool library. I am trying to use voice recognition on esp32-a1s audio kit. In internet there are very less tutorials on that. can you pleas suggest how I can achieve that. I will be very thankful of you. Thanks once again.

Camilo Delgado · 13. June 2022 at 15:39

hello! How are you?, I wanted to ask if you know how to make a request with form data from this board to send an audio from the sd memory, I would really appreciate it if you have an idea

hfb977 · 28. May 2022 at 17:03

Hi, your blog and github is helping me so much to understand the A1S, thanks for puting your knowledge out here.

I’m working in a project with an sd card and i`m using this code to initialize the sd card:

if (!SD.begin(SdSpiConfig(PIN_CS, SHARED_SPI, SD_SCK_MHZ(2)))) {
Serial.println(“initialization failed!”);
return;
}

But this error message always appear:

Initializing SD card…initialization failed!

I`m working with fat32 and Exfat configuration on the sd card

You could please help me with this? thank you so much

Camilo Delgado · 16. May 2022 at 21:36

Hola como estas?!! muchas gracias por estos blogs tan interesantes!! quería preguntarle una cosa, usted sabe como seria posible crear un archivo wav o mp3 a partir de esta placa de AUDIOKIT con lo que va recibiendo el mic?

    pschatzmann · 16. May 2022 at 21:48

    If you use my arduino-audio-tools project, that should be quite easy: Just copy from the AudioKit to an EncodedAudioStream where you specify the output (a file in your case) and the Encoder (e.g. WavEncoder).
    Further details you can find in the Wiki: https://github.com/pschatzmann/arduino-audio-tools/wiki/Encoding-and-Decoding-of-Audio

      Camilo Delgado · 23. May 2022 at 0:06

      thank you very much really! I’m going to try it

        Camilo Delgado · 23. May 2022 at 2:38

        Sorry, I’m new in this, is it possible to give it some time? example record only 1 minute? since even with the code I don’t know how to stop the recording and my memory appears empty when I check it

          pschatzmann · 25. May 2022 at 12:40

          That should be easy. Just add a time variable and execute the in the loop copy only between the start and end time.

          Camilo Delgado · 31. May 2022 at 2:03

          I could, this worked, only the audio comes out a bit cut off
          myTime = millis();
          if(myTime <= 5000){
          copier.copy();
          }else{
          audioFile.close();
          }

        Max · 22. August 2022 at 16:06

        Hello Camilo,

        coud you provide your whole code? i am realy struggeling getting the same problem running 🙂

          pschatzmann · 22. August 2022 at 16:32

          This is the whole code. Maybe you forgot to install the dependencies ?

Leave a Reply

Avatar placeholder

Your email address will not be published.