Skip to content

API Reference parrot.voice.tts.synthesizer

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

parrot.voice.tts.synthesizer

View source

Voice Synthesizer Service.

Main service that orchestrates text-to-speech synthesis. Selects the appropriate backend based on configuration, manages the backend lifecycle, and provides a unified synthesize(text) interface used by integration wrappers (Telegram, etc.).

Mirrors the structure of parrot.voice.transcriber.transcriber.VoiceTranscriber. Added by FEAT-213 (Telegram Voice Reply TTS Output).

Alias AbstractTTSBackend

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

Alias SynthesisResult

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

Alias TTSConfig

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

Class VoiceSynthesizer

Text-to-speech synthesis service.

Manages the TTS backend lifecycle and provides a unified interface for synthesizing speech from text strings.

The backend is lazily created on first use. Call close() to release backend resources when done.

Example::

synth = VoiceSynthesizer(TTSConfig(backend="google", voice="Charon"))
try:
    result = await synth.synthesize("Hello from the bot!")
    # result.audio holds the raw audio bytes
finally:
    await synth.close()
Parameter Type Default Description
config Optional[TTSConfig] None TTS configuration including backend selection, voice, and audio format. Defaults to TTSConfig() (Google backend, "audio/ogg" output) when None.

Method VoiceSynthesizer.synthesize

Synthesize speech from text.

Delegates to the backend selected by self.config.backend. Uses the voice and MIME format from the configuration.

Example::

result = await synth.synthesize(
    "Hola, ¿en qué te puedo ayudar?",
    language="es-ES",
)
print(f"Audio size: {len(result.audio)} bytes")

synthesize(text: str, *, language: Optional[str] = None) -> SynthesisResult

Parameter Type Default Description
text str The text to convert to speech. Must be non-empty.
language Optional[str] None BCP-47 language tag (e.g. "en-US"). When None, the value from self.config.language is used as a fallback; if that is also None the backend applies its own default.

Returns: SynthesisResult — SynthesisResult containing the raw audio bytes and the actual MIME format of the audio data.

Raises:

  • ValueError — If text is empty, or if the backend is not implemented.
  • RuntimeError — If the underlying TTS API returns no audio.

Method VoiceSynthesizer.close

Release backend resources.

Should be called when the synthesizer is no longer needed to free up any resources held by the backend (API sessions, etc.).

close() -> None

Function close_shared_synthesizers

Close and drop every shared synthesizer without propagating errors.

close_shared_synthesizers() -> None

Function get_shared_synthesizer

Return the process-wide synthesizer for a configuration.

get_shared_synthesizer(config: TTSConfig) -> VoiceSynthesizer

Parameter Type Default Description
config TTSConfig Full text-to-speech configuration used to key the cache.

Returns: VoiceSynthesizer — The shared VoiceSynthesizer for config.

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