.. include:: /index.rst :start-after: start_hello_message :end-before: end_hello_message 1. TTS with Espeak and Pico2Wave ================================================= In this lesson, we'll use two built-in text-to-speech (TTS) engines on Raspberry Pi — **Espeak** and **Pico2Wave** — to make the Pironman 5 Pro MAX talk. These two engines are both simple and run offline, but they sound quite different: * **Espeak**: very lightweight and fast, but the voice is robotic. You can adjust speed, pitch, and volume. * **Pico2Wave**: produces a smoother and more natural voice than Espeak, but has fewer options to configure. You'll hear the difference in **voice quality** and **features**. ---- 1. Testing Espeak -------------------- Espeak is a lightweight TTS engine included in Raspberry Pi OS. Its voice sounds robotic, but it is highly configurable: you can adjust volume, pitch, speed, and more. **Run the program** .. code-block:: bash cd ~/sunfounder-voice-assistant/examples sudo python3 tts_espeak.py * You should hear the Pironman 5 Pro MAX say: “Hello! I'm Espeak TTS.” * Try changing the tuning parameters in the code to experiment with how ``amp``, ``speed``, ``gap``, and ``pitch`` affect the sound. **Code** .. code-block:: python from sunfounder_voice_assistant.tts import Espeak # Create Espeak TTS instance tts = Espeak() # Set amplitude 0-200, default 100 tts.set_amp(200) # Set speed 80-260, default 150 tts.set_speed(150) # Set gap 0-200, default 1 tts.set_gap(1) # Set pitch 0-99, default 80 tts.set_pitch(80) tts.say("Hello! I’m Espeak TTS.") **Code explanation:** * ``tts.set_amp()`` — Controls the volume (0–200). * ``tts.set_speed()`` — Adjusts the speaking speed (80–260). * ``tts.set_gap()`` — Sets the word gap (0–200). * ``tts.set_pitch()`` — Sets the pitch (0–99). * ``tts.say()`` — Converts text to speech and plays it. 💡 **Tip:** Try increasing the pitch and speed to make the robot sound cheerful, or lowering them to make it sound serious. ---- 2. Testing Pico2Wave --------------------- Pico2Wave produces a **more natural and human-like voice** compared to Espeak. It’s very easy to use, but less flexible — you can only **change the language**, not the pitch, speed, or volume. This makes Pico2Wave a great choice when you want clear and smooth speech without too much configuration. **Run the program** .. code-block:: bash cd ~/sunfounder-voice-assistant/examples sudo python3 tts_pico2wave.py * You should hear the Pironman 5 Pro MAX say: “Hello! I'm Pico2Wave TTS.” * Try changing the language (for example, ``es-ES`` for Spanish) and listen to how the voice changes. **Code** .. code-block:: python from sunfounder_voice_assistant.tts import Pico2Wave # Create Pico2Wave TTS instance tts = Pico2Wave() # Set the language tts.set_lang('en-US') # en-US, en-GB, de-DE, es-ES, fr-FR, it-IT # Quick hello (sanity check) tts.say("Hello! I'm Pico2Wave TTS.") **Code explanation:** * ``tts.set_lang()`` — Sets the output language for speech synthesis. - ``en-US`` (default) - ``en-GB`` - ``de-DE`` - ``es-ES`` - ``fr-FR`` - ``it-IT`` * ``tts.say()`` — Converts the text to speech and plays it immediately. ---- Troubleshooting ------------------- * **No sound when running Espeak or Pico2Wave** * Check that your speakers/headphones are connected and volume is not muted. * Run a quick test in terminal: .. code-block:: bash espeak "Hello world" pico2wave -w test.wav "Hello world" && aplay test.wav If you hear nothing, the issue is with audio output, not your Python code. * **Espeak voice sounds too fast or too robotic** * Try adjusting the parameters in your code: .. code-block:: python tts.set_speed(120) # slower tts.set_pitch(60) # different pitch * **Permission denied when running code** * Try running with ``sudo``: .. code-block:: bash sudo python3 test_tts_espeak.py Comparison: Espeak vs Pico2Wave ------------------------------------- .. list-table:: :widths: 20 40 40 :header-rows: 1 * - Feature - Espeak - Pico2Wave * - Voice quality - Robotic, synthetic - More natural, human-like * - Languages - Default English - Fewer, but common ones * - Adjustable - Yes (speed, pitch, etc.) - No (only language) * - Performance - Very fast, lightweight - Slightly slower, heavier