It was quite a challenge to convert eSpeak NG to an Arduino Library.

The eSpeak NG is a compact open source software text-to-speech synthesizer for Linux, Windows, Android and other operating systems. It supports more than 100 languages and accents. It is based on the eSpeak engine created by Jonathan Duddington.

Language Specific Configuration Files

Using a foreign language is quite easy: You just need to load the language dependent files and set the corresponding voice. Here is the list of all language configuration files that are available.

The Arduino Sketch

To preserve some valuable memory we do not load the (default) English language, but I set up the German (de) language instead:

#include "AudioTools.h" // https://github.com/pschatzmann/arduino-audio-tools
#include "FileSystems.h" // https://github.com/pschatzmann/arduino-posix-fs
#include "espeak.h" // https://github.com/pschatzmann/arduino-espeak-ng)

I2SStream i2s; // or replace with AudioKitStream for AudioKit
const bool load_english = false;
ESpeakPROGMEM espeak(i2s, load_english);

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

  // add foreign language configuration file
  espeak.add("/mem/data/de_dict", espeak_ng_data_de_dict,espeak_ng_data_de_dict_len);
  espeak.add("/mem/data/lang/de", espeak_ng_data_lang_gmw_de, espeak_ng_data_lang_gmw_de_len);

  // setup espeak
  espeak.begin();
  // Set voice
  espeak.setVoice("de");

  // setup output
  audio_info espeak_info = espeak.audioInfo();
  auto cfg = i2s.defaultConfig();
  cfg.channels = espeak_info.channels; // 1
  cfg.sample_rate = espeak_info.sample_rate; // 22050
  cfg.bits_per_sample = espeak_info.bits_per_sample; // 16
  i2s.begin(cfg);
}

void loop() {
  espeak.say("Hallo Welt!");
  delay(5000);
}

Dependencies

This library requires the installation of the following libraries:

Supported Platforms

For the time being I have only tested this sketch on an ESP32. Please note that the sketch needs about 1’638’633 bytes of PROGMEM.

Github

Further information can be found on Github


0 Comments

Leave a Reply

Avatar placeholder

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