abr_sdk.tts#
API for running TTS (text-to-speech) applications.
Author: Pawel Jaworski
Module Contents#
Classes#
API#
- class abr_sdk.tts.Tts(lib_or_path: str | pathlib.Path | abr_sdk.core.Library, *, lib_search_paths: list[str | pathlib.Path] | None = None, use_default_lib_search_paths: bool = True, resources_dir: str | pathlib.Path | None = None, litert_delegate: str | None = None, cache_dir: str | pathlib.Path | None = None, raw_config: abr_sdk.core.VariantDict | None = None, logger: logging.Logger | None = None)#
Bases:
abr_sdk.core.ApplicationSynthesize speech audio from input text.
Push raw UTF-8 text bytes and receive synthesized mono PCM audio, one signed 16-bit integer per sample in little-endian order at 16 kHz. The backend normalizes pushed text (numbers, dates, currency, acronyms, and abbreviations become speakable words) one sentence at a time, so raw text can be pushed as-is.
Streaming usage::
chunks: list[bytes] = [] with Tts("libnith_5m_live.so") as tts: tts.push(b"Hello world.", on_pcm=chunks.append) tts.wait_for_completion() pcm = b"".join(chunks)
Parameters
raw_config Configuration keys passed to the library as-is, for keys that have no keyword argument. A key that a keyword argument also sets raises :class:
ValueError.Initialization
- _app_type#
‘tts’
Application type the library must declare.
- text_input_buffer: abr_sdk.core.Buffer#
None
FIFO byte queue that receives the raw UTF-8 text pushed into the model.
- pcm_output_buffer: abr_sdk.core.Buffer#
None
FIFO byte queue that emits the synthesized PCM audio as the model produces it.
- __enter__() abr_sdk.tts.Tts#
- push(data: bytes, *, on_pcm: collections.abc.Callable[[bytes], None] | None = None, output_poll_timeout_ms: int = 0) None#
Push UTF-8 text bytes into the TTS pipeline.
On the first call an internal :class:
Processoris created with on_pcm as the listener callback. Subsequent calls reuse the same processor. Advances the event loop until all input has been accepted by the pipeline; PCM bytes produced while advancing are delivered toon_pcm.Parameters
data UTF-8 encoded text bytes. on_pcm Callback invoked with each chunk of synthesized PCM bytes. Only used on the first call (when the internal processor is created). output_poll_timeout_ms Time in milliseconds, measured from when
pushis called, after which the call stops waiting for output and returns. All input is accepted first, even if that takes longer.0(the default) returns once all input is accepted and no output is immediately ready.
- class abr_sdk.tts.Processor(tts: abr_sdk.tts.Tts, on_pcm: collections.abc.Callable[[bytes], None] | None = None)#
Event loop driving a streaming TTS session.
Initialization
- process_and_wait_for_output(data: bytes | None, timeout_ms: int, drain_to_idle: bool) None#
Push
datainto TTS and advance the event loop until input is drained.When
drain_to_idleis true, flushes the pipeline once all input is pushed and keeps polling until the flush marker arrives on the PCM output buffer.
- __enter__() abr_sdk.tts.Processor#