Quartz Components
Published © GPL3+

AI Based Text-to-Speech System with MAX98357A & ESP32

Build a real-time AI powered Text-to-Speech system using ESP32 and MAX98357A I2S amplifier for smart voice and IoT projects.

BeginnerFull instructions provided3 hours47
AI Based Text-to-Speech System with MAX98357A & ESP32

Things used in this project

Hardware components

ESP32 30 Pin CP2102 Development Board with Wi-Fi and Bluetooth
×1
MAX98357 I2S 3W Class D Amplifier Audio Decoder Module
×1
4 ohm 2.5 Watt Speaker Pair
×1
MB102 Colored Breadboard
×1
USB to micro-USB Cable
×1
Connecting wires
×1

Software apps and online services

Arduino IDE
Arduino IDE
wit.ai

Story

Read more

Schematics

ESP32 MAX98357A Circuit Diagram for AI Text-to-Speech System

Circuit diagram for the ESP32 based AI Text-to-Speech system using the MAX98357A I2S Audio Amplifier. Shows the wiring connections for audio output, speaker integration, power supply, and ESP32 communication setup for real-time voice generation projects.

Code

ESP32 AI Text-to-Speech Source Code using MAX98357A

C/C++
This code enables real-time AI powered Text-to-Speech on ESP32 using the MAX98357A I2S Audio Amplifier and Wit.ai API. It connects the ESP32 to WiFi, streams AI generated voice audio, and supports multiple voice styles including pirate, wizard, cartoon, and British butler voices. Perfect for smart assistants, robotics, IoT, and embedded voice projects.
#include <WitAITTS.h>

// WiFi Credentials
const char* WIFI_SSID     = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";

// Wit.ai API Token
const char* WIT_TOKEN = "YOUR_WIT_AI_TOKEN";

// Create TTS Object
WitAITTS tts;

// Voice List
String voices[] = {
  "wit$Remi",
  "wit$Rebecca",
  "wit$Cody",
  "wit$Charlie",
  "wit$Pirate",
  "wit$Wizard",
  "wit$Rosie",
  "wit$Cartoon Kid",
  "wit$Vampire",
  "wit$British Butler"
};

int currentVoice = 0;

void setup() {

  Serial.begin(115200);
  delay(1000);

  Serial.println("DIY ESP32 Voice Synthesizer");

  tts.setDebugLevel(DEBUG_INFO);

  // Initialize TTS
  if (tts.begin(WIFI_SSID, WIFI_PASSWORD, WIT_TOKEN)) {

    Serial.println("TTS Ready");

    // Default Voice
    tts.setVoice(voices[currentVoice]);

    // Voice Style
    tts.setStyle("default");

    // Audio Settings
    tts.setSpeed(100);
    tts.setPitch(100);
    tts.setGain(0.5);

    Serial.println("\nAvailable Commands:");
    Serial.println("voice 0 -> Remi");
    Serial.println("voice 1 -> Rebecca");
    Serial.println("voice 2 -> Cody");
    Serial.println("voice 3 -> Charlie");
    Serial.println("voice 4 -> Pirate");
    Serial.println("voice 5 -> Wizard");
    Serial.println("voice 6 -> Rosie");
    Serial.println("voice 7 -> Cartoon Kid");
    Serial.println("voice 8 -> Vampire");
    Serial.println("voice 9 -> British Butler");

    Serial.println("\nType text to speak");

  } else {

    Serial.println("TTS Initialization Failed");
  }
}

void loop() {

  // Required for audio streaming
  tts.loop();

  if (Serial.available()) {

    String input = Serial.readStringUntil('\n');
    input.trim();

    // Change Voice Command
    if (input.startsWith("voice")) {

      int index = input.substring(6).toInt();

      if (index >= 0 && index < 10) {

        currentVoice = index;

        tts.setVoice(voices[currentVoice]);

        Serial.print("Voice Changed To: ");
        Serial.println(voices[currentVoice]);

        tts.speak("Voice changed successfully");
      }

    } else if (input.length() > 0) {

      Serial.print("Speaking: ");
      Serial.println(input);

      tts.speak(input);
    }
  }
}

Credits

Quartz Components
2 projects • 4 followers
Quartz Components builds embedded, IoT, robotics, and DIY electronics projects powered by Arduino, ESP32, sensors, and smart hardware.

Comments