View source on GitHub
|
On-device speech synthesis via MediaPipe CalculatorGraph.
mp.tasks.audio.TextToSpeech(
handle: ctypes.c_void_p
)
Args | |
|---|---|
handle
|
Opaque C pointer created by MpTextToSpeechCreate.
|
Methods
cancel
cancel() -> None
Cancels any in-flight synthesis or streaming session.
close
close() -> None
Closes the synthesizer and releases native C++ resources.
create_from_model_path
@classmethodcreate_from_model_path( model_path: str, delegate:mp.tasks.BaseOptions.Delegate= _BaseOptions.Delegate.CPU, default_voice_id: str = '', speaking_rate: float = 1.0 ) -> 'TextToSpeech'
Creates a TextToSpeech instance from a .litertlm model path.
create_from_options
@classmethodcreate_from_options( options:mp.tasks.audio.TextToSpeechOptions) -> 'TextToSpeech'
Creates a TextToSpeech instance from TextToSpeechOptions.
list_voices
list_voices() -> list[VoiceInfo]
Lists all voices available in the loaded model bundle.
start_stream
start_stream(
initial_text: str = '',
voice_id: Optional[str] = None,
locale: Optional[str] = None,
finish_input: bool = False
) -> 'TtsStream'
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
synthesize(
text: str, voice_id: Optional[str] = None, locale: Optional[str] = None
) -> mp.tasks.audio.TtsAudioResult
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
synthesize_stream(
text: str, voice_id: Optional[str] = None, locale: Optional[str] = None
) -> Iterator[mp.tasks.audio.TtsAudioResult]
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__
__enter__() -> 'TextToSpeech'
__exit__
__exit__(
exc_type, exc_val, exc_tb
) -> None
View source on GitHub