Skip to content

API Reference parrot.voice.tts.google_backend

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

parrot.voice.tts.google_backend

View source

Google TTS Backend.

Implements AbstractTTSBackend using GoogleGenAIClient.generate_speech. This is the default backend for VoiceSynthesizer.

The audio returned by generate_speech is raw PCM data (Gemini TTS produces 24kHz mono 16-bit PCM). This backend wraps it in a WAV container and reports the truthful audio/wav MIME; Telegram voice notes are then converted to OGG/Opus by the caller (TASK-1409 / Telegram wrapper).

Added by FEAT-213 (Telegram Voice Reply TTS Output).

Alias AbstractTTSBackend

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

Alias GoogleGenAIClient

Re-exported from parrot.clients.google.GoogleGenAIClient.

Class GoogleTTSBackend

TTS backend that wraps GoogleGenAIClient.generate_speech.

Builds a SpeechGenerationPrompt with a single SpeakerConfig and calls generate_speech; then extracts the raw audio bytes from the returned AIMessage.output.

Example::

backend = GoogleTTSBackend(voice="Kore")
result = await backend.synthesize("Hello, world!")
print(f"Audio: {len(result.audio)} bytes, format: {result.mime_format}")
Parameter Type Default Description
client Optional['GoogleGenAIClient'] None An already-instantiated GoogleGenAIClient. When None (default), a new client is created lazily on first use. Providing an explicit client is the recommended pattern for unit testing (dependency injection).
voice Optional[str] None Default voice identifier to use when the caller does not supply one (e.g. "Charon", "Kore", "Puck"). Falls back to "Charon" when None.
**kwargs {} Extra keyword arguments are accepted and ignored to allow forward-compatible construction.

Method GoogleTTSBackend.synthesize

Synthesize speech from text using the Google TTS API.

Builds a single-speaker SpeechGenerationPrompt, calls GoogleGenAIClient.generate_speech, and returns WAV audio bytes packed in a SynthesisResult.

Example::

result = await backend.synthesize(
    "Buenos días, ¿cómo estás?",
    voice="Kore",
    mime_format="audio/ogg",
    language="es-ES",
)

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 identifier (e.g. "Charon"). Falls back to the voice supplied at construction time, then to "Charon".
mime_format str 'audio/ogg' Requested MIME type. Google output is always WAV, so the returned result truthfully reports audio/wav.
language Optional[str] None BCP-47 language tag forwarded to SpeechGenerationPrompt.language (e.g. "es-ES"). None leaves the prompt at its default ("en-US").

Returns: SynthesisResult — SynthesisResult with WAV audio bytes and audio/wav MIME.

Raises:

  • ValueError — If text is empty.
  • RuntimeError — If generate_speech returns no audio data.

Method GoogleTTSBackend.close

Release backend resources.

The Google client does not require explicit teardown, but this method clears the internal reference to allow garbage collection.

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