mp.tasks.audio.TextToSpeech

On-device speech synthesis via MediaPipe CalculatorGraph.

handle Opaque C pointer created by MpTextToSpeechCreate.

Methods

cancel

View source

Cancels any in-flight synthesis or streaming session.

close

View source

Closes the synthesizer and releases native C++ resources.

create_from_model_path

View source

Creates a TextToSpeech instance from a .litertlm model path.

create_from_options

View source

Creates a TextToSpeech instance from TextToSpeechOptions.

list_voices

View source

Lists all voices available in the loaded model bundle.

start_stream

View source

Starts an incremental or single-utterance streaming synthesis session.

Args
initial_text Optional initial text fragment to enqueue immediately.
voice_id Optional speaker voice ID override.
locale Optional BCP-47 locale override.
finish_input If False, additional tokens/words can be appended via TtsStream.push_text() followed by TtsStream.finish_input().

Returns
An active TtsStream handle supporting push_text(), finish_input(), and iteration over TtsAudioResult chunks.

synthesize

View source

Synthesizes text synchronously and returns mono float32 PCM audio.

Args
text Input text to synthesize.
voice_id Optional speaker voice ID override; if None, falls back to default_voice_id configured in TextToSpeechOptions.
locale Optional BCP-47 locale override; if None, falls back to default_locale configured in TextToSpeechOptions.

Returns
A TtsAudioResult containing the full synthesized audio waveform.

synthesize_stream

View source

Streams synthesized audio chunk-by-chunk.

Args
text Input text to synthesize into clause-level audio chunks.
voice_id Optional speaker voice ID override; if None, falls back to default_voice_id configured in TextToSpeechOptions.
locale Optional BCP-47 locale override; if None, falls back to default_locale configured in TextToSpeechOptions.

Yields
TtsAudioResult chunks as each clause finishes acoustic + vocoder synthesis.

__enter__

View source

__exit__

View source