Speaks text using the system text-to-speech engine.

Usage #

package main

import (
    "log"
    t "github.com/hugmouse/gotermux"
)

func main() {
    ttsConfig := t.TTSSpeak{
        Engine:        "com.google.android.tts",
        Lang:          "en",
        Region:        "US", 
        Variant:       "",
        Rate:          1.0,
        Stream:        t.Music,
        TextToSpeech: "Hello from GoTermux! This is a text-to-speech demonstration.",
    }
    
    err := t.TermuxTTSSpeak(ttsConfig)
    if err != nil {
        log.Printf("TTS error: %v", err)
    }
}

Parameters #

  • t TTSSpeak - Text-to-speech configuration

Return Value #

Returns error - nil on success, error message on failure.

Struct TTSSpeak #

FieldTypeDescription
EnginestringTTS engine to use
LangstringLanguage code (e.g., “en”, “es”)
RegionstringRegion code (e.g., “US”, “GB”)
VariantstringLanguage variant
Ratefloat64Speech rate (0.1 to 4.0)
StreamAudioStreamAudio stream for playback
TextToSpeechstringText to convert to speech

Audio Stream Constants #

You can use these constants for the Stream field:

  • Notification - Notification audio stream
  • Alarm - Alarm audio stream
  • Music - Music audio stream (recommended for TTS)
  • Ring - Ringtone audio stream
  • System - System audio stream
  • VoiceCall - Voice call audio stream

Language Examples #

Common language/region combinations:

  • English (US): Lang: "en", Region: "US"
  • English (UK): Lang: "en", Region: "GB"
  • Spanish: Lang: "es", Region: "ES"
  • French: Lang: "fr", Region: "FR"
  • German: Lang: "de", Region: "DE"
The speech rate should be between 0.1 (very slow) and 4.0 (very fast). A rate of 1.0 is normal speaking speed.