Class TextToSpeech

java.lang.Object
com.codename1.media.TextToSpeech

public final class TextToSpeech extends Object

Speaks text aloud using the platform's built-in synthesizer.

  • iOS -- AVSpeechSynthesizer.
  • Android -- android.speech.tts.TextToSpeech.
  • JavaSE simulator -- best-effort: say on macOS, espeak on Linux, SAPI via PowerShell on Windows. When none of those tools are present, isSupported() returns false and speak(String) silently no-ops so simulator code paths keep working.

No permissions or Info.plist entries are required.

TextToSpeech.speak("Welcome to the demo");
  • Method Details

    • isSupported

      public static boolean isSupported()
    • speak

      public static void speak(String text)
      Speaks text using the platform default voice. Returns immediately; the utterance plays asynchronously.
    • speak

      public static void speak(String text, TtsOptions options)
    • stop

      public static void stop()
      Stops any ongoing utterance. No-op when nothing is playing.
    • getAvailableVoices

      public static String[] getAvailableVoices()
      Returns the platform-supplied voice identifiers. May be empty on platforms that don't enumerate voices (e.g. the simulator when relying on the system say binary).