I decided to use my SAM TTS Library with the AI Thinker Audio Kit. Unfortunately I found quite some bugs in my library that I needed to correct first, but now it is working as expected. Here is the Arduino Sketch

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

AudioKitStream kit;
SAM sam(kit);

const char* text = "Hallo my name is SAM";

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

  // setup i2s
  auto cfg = kit.defaultConfig();
  cfg.bits_per_sample = sam.bitsPerSample();
  cfg.channels = sam.channels();
  cfg.sample_rate = sam.sampleRate();
  kit.begin(cfg);

  sam.say(text);
}

void loop() {
  delay(100);
}

We can use the stream output support of SAM and because the AudioKitStream is implementing the Arduino Stream, we can provide it directly as output argument. In the setup we just need to make sure that we use the correct I2S parameters: Fortunately SAM can provide this info to us.

The sound quality is much inferior to what we get from FLITE – but it uses less memory:

Sketch uses 557245 bytes (17%) of program storage space. Maximum is 3145728 bytes.
Global variables use 25876 bytes (7%) of dynamic memory, leaving 301804 bytes for local variables. Maximum is 327680 bytes.

Source Code

The (potentially) updated source code can be found in the samples directory of my AudioTools library.

Dependencies

You need to install the following libraries:


4 Comments

Schmurtz · 30. December 2021 at 17:06

Wow ! Your Arduino Audio Tools library is awesome….

Schmurtz · 30. December 2021 at 16:16

Nice, thanks to share it !
So I notice that you have made/tested : SAM , FLITE and jscrane/TTS. Which one offers the best results ?
It could be nice to have a sample sentence of each one in your blog posts to compare. (I found jscrane and sam sample but not Flite).

I follow numerous project on sound on ESP, you probably know all of them but just in case I share with you :
https://github.com/earlephilhower/ESP8266Audio -> awesome library to manage sound output with I2S board or not.
https://github.com/earlephilhower/ESP8266SAM -> similar to your sam library
https://github.com/sle118/squeezelite-esp32 -> for me the most incredible audio player on ESP32
https://www.youtube.com/playlist?list=PL5vDt5AALlRfGVUv2x7riDMIOX34udtKD -> a great youtube channel to expose basics of sound with ESP32
https://github.com/schreibfaul1/ESP32-audioI2S -> an alternative to ESP8266Audio which manage google TTS natively

    pschatzmann · 30. December 2021 at 16:21

    You might have missed this blog https://www.pschatzmann.ch/home/2021/06/23/text-to-speach-in-arduino-using-flite/
    I think FLITE is best – but it comes at the price of high memory consumption.

      Schmurtz · 30. December 2021 at 16:37

      Oh yes I missed it ! Thanks for your fast answer !
      My idea is to use an ESP32 for home automation notifications. That’s something which has already done (by MrDiy ou ESParkle), but I try to port it to ESP32 and add some functionalities (Google TTS, good support of AAC for web radio, …).

      I was thinking that if my internet connection is down it could be useful to keep possible to send TTS notifications without Google TTS. it’s like that I found your blog, during my search about TTS on ESP.

      Thanks sharing, I keep an eye on your blog 🙂

Leave a Reply

Avatar placeholder

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