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.
.

We can turn the AI Thinker ESP32 Audio Kit V2.2 easily into a Bluetooth Speaker with the following three libraries:

Audio Kit

In the ESP32-A2DP library we can indicate a callback method to process the data. We just feed the AudioKitStream from the Arduino Audio Tools. Here is the Arduino Sketch

The Arduino Sketch

#define USE_A2DP
#include "AudioTools.h"
#include "AudioDevices/ESP32AudioKit/AudioKit.h"

BluetoothA2DPSink a2dp_sink;
AudioKitStream kit;

// Write data to AudioKit in callback
void read_data_stream(const uint8_t *data, uint32_t length) {
    kit.write(data, length);
}

void setup() {
  AudioLogger::instance().begin(Serial, AudioLogger::Info);

  // setup output
  auto cfg = kit.defaultConfig(TX_MODE);
  cfg.default_volume = 50;
  kit.begin(cfg);

  // register callback
  a2dp_sink.set_stream_reader(read_data_stream, false);
  a2dp_sink.start("AudioKit");
}

void loop() {
  kit.processActions();
}

The audio quality is just perfect and even the automatic volume control is working!

The full example can be found on Github

Disclaimer

Please note that the sketches that I am posting on this site are working at the point of time of the posting. It might be that things have changed when you read this. So please use the corresponding updated example in the Audio Tools Project if you want to try it out yourself.


9 Comments

John · 3. June 2022 at 15:35

Hi, I am receiving errors surrounding this include statement.

#include “AudioDevices/ESP32AudioKit/AudioKit.h”

I have installed the libraries from your github, but for some reason this still doesn’t work. Any idea how to fix this?

    pschatzmann · 3. June 2022 at 15:45

    Just use the updated example from Github

Joe · 3. February 2022 at 0:06

Hi… Great project. Just one problem i have having. I’m not sure which board to select on the arduino IDE when i’m uploading your sketch. I’ve tried multiple boards
but the serial prints out AudioKit.h : 185 – begin faild: please verify your AUDIOKIT_BOARD setting: 5

    pschatzmann · 3. February 2022 at 2:05

    if you have a new board it is 5. If you have an old board it is 6. You really need to now which audio chip has been used.

      Joe · 3. February 2022 at 18:45

      I used the exact same board as you, used the same sketch also but the error persists.
      When i change it to #define AUDIOKIT_BOARD 6 the error changes to:

      [W] AudioKit.h : 43 – sd_active = false
      Warning: reset succeed
      [I] AudioKit.h : 193 – Channels 2->2
      [I] AudioOutput.h : 747 – void audio_tools::FormatConverterStream::setup()
      [I] AudioOutput.h : 760 – FormatConverterStream: no conversion
      [I] AudioKit.h : 539 – void audio_tools::AudioKitStream::setupActions()
      [W] AudioKit.h : 542 – Deactivating SPI because SD is not active
      [I] AudioActions.h : 42 – ActionLogic::add pin: 39 / logic: 0
      [I] AudioActions.h : 58 – pin 39 -> INPUT_PULLUP
      [I] AudioKit.h : 292 – void audio_tools::AudioKitStream::addAction(int, void ()(bool, int, void), void)
      [I] AudioActions.h : 42 – ActionLogic::add pin: 13 / logic: 0
      [I] AudioActions.h : 58 – pin 13 -> INPUT_PULLUP
      [I] AudioKit.h : 292 – void audio_tools::AudioKitStream::addAction(int, void (
      )(bool, int, void), void)
      [I] AudioActions.h : 42 – ActionLogic::add pin: 18 / logic: 0
      [I] AudioActions.h : 58 – pin 18 -> INPUT_PULLUP
      [I] AudioKit.h : 292 – void audio_tools::AudioKitStream::addAction(int, void ()(bool, int, void), void*)
      [I] AudioActions.h : 42 – ActionLogic::add pin: 5 / logic: 0
      [I] AudioActions.h : 58 – pin 5 -> INPUT_PULLUP

        pschatzmann · 3. February 2022 at 18:58

        I don’t see any errors: on the contrary – it seems to work now with this setting and no it’s not the same board. I have one with the ES8388 audio chip and you have an old board with the AC101. For details see https://github.com/Ai-Thinker-Open/ESP32-A1S-AudioKit

          Joe · 3. February 2022 at 23:27

          Awesome! it connects now. volume, mute, stop and play buttonw work.
          When i connect headphone jack, and pair with my laptop i see that the mic indicates that its picking sound. The last hurdle to cross now is that i don’t hear anything play on the headphone and speaker i connected to the board.
          Any idea why?

Leave a Reply

Avatar placeholder

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