Skip to content

API Reference parrot.voice.tts.supertonic_backend

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.voice.tts.supertonic_backend

View source

Supertonic TTS Backend.

Implements :class:AbstractTTSBackend against the Supertonic sub-second text-to-speech model (ONNX runtime + weights). Mirrors the structure of :class:GoogleTTSBackend: the heavy ONNX session is created lazily on first synthesis, and inference runs off the event loop via asyncio.to_thread.

Unlike the Google backend (which returns raw PCM and leaves container conversion to the caller), this backend returns a browser-playable WAV container by default and labels SynthesisResult.mime_format truthfully — mime_format is a label, not a converter, so the bytes always match the label.

Extras-gated: the ONNX runtime and the Supertonic weights ship behind the ai-parrot-integrations[voice-supertonic] extra. When those dependencies (or the model weights) are missing, synthesize raises ImportError / ValueError — it never silently degrades. Graceful degradation to text-only is the handler's responsibility (FEAT-231, AgentVoiceTalk).

Added by FEAT-231 (AgentTalk Voice Support).

Alias AbstractTTSBackend

Re-exported from parrot.voice.tts.backend.AbstractTTSBackend.

Class SupertonicTTSBackend

TTS backend that wraps the Supertonic ONNX speech model.

The ONNX inference session is created lazily on first synthesize call to keep construction cheap (so VoiceSynthesizer._get_backend can build the backend without paying the model-load cost). Inference runs in a worker thread via asyncio.to_thread so the event loop is never blocked.

Example::

backend = SupertonicTTSBackend(voice="default")
result = await backend.synthesize("Hola, ¿en qué puedo ayudarte?")
# result.audio is a playable WAV; result.mime_format == "audio/wav"
await backend.close()
Parameter Type Default Description
voice Optional[str] None Default voice/speaker identifier to use when the caller does not supply one. None falls back to the Supertonic default speaker.
model_path Optional[str] None Filesystem path to the Supertonic ONNX weights. When None (default), the SUPERTONIC_MODEL_PATH environment variable is consulted at synthesis time.
sample_rate int _SAMPLE_RATE Output PCM sample rate in Hz. Defaults to 44100 Hz (the actual Supertonic ONNX pipeline output rate).
inference_fn None Optional callable (session, text, *, voice, language, sample_rate) -> bytes that drives the loaded ONNX session and returns raw PCM. The Supertonic ONNX graph I/O (tokenisation, speaker embedding, output tensor names) is build-specific and intentionally not hardcoded — deployments inject it here (or subclass and override _synthesize_sync). See spec FEAT-231 §8 R-deps.
**kwargs {} Extra keyword arguments are accepted and ignored to allow forward-compatible construction.

Method SupertonicTTSBackend.synthesize

Synthesize speech from text using Supertonic.

Runs ONNX inference off the event loop, wraps the resulting PCM samples into a WAV container, and returns a SynthesisResult whose mime_format truthfully reflects the returned bytes.

synthesize(text: str, *, voice: Optional[str] = None, mime_format: str = 'audio/ogg', language: Optional[str] = None) -> SynthesisResult

Parameter Type Default Description
text str The text to convert to speech. Must be non-empty.
voice Optional[str] None Voice/speaker identifier. Falls back to the voice supplied at construction time, then to the Supertonic default.
mime_format str 'audio/ogg' Requested MIME type. Only "audio/wav" is produced by this backend; any other value is normalised to "audio/wav" (the bytes are always a WAV container, so the returned mime_format stays truthful).
language Optional[str] None BCP-47 language tag forwarded to the model. None delegates language selection to the model default.

Returns: SynthesisResult — SynthesisResult with playable WAV bytes and mime_format == "audio/wav".

Raises:

  • ValueError — If text is empty or the weights are unconfigured.
  • RuntimeError — If inference produces no audio.
  • ImportError — If the voice-supertonic extra is not installed.

Method SupertonicTTSBackend.close

Release the ONNX inference session.

Clears the internal session reference to allow garbage collection of the loaded model.

close() -> None

Alias SynthesisResult

Re-exported from parrot.voice.tts.models.SynthesisResult.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally