Get started with Chirp 3 HD voices using Text-to-Speech
Source notebook
Repo path:
audio/speech/getting-started/get_started_with_chirp_3_hd_voices.ipynb· Open on GitHub · intro
Synthesizes Chirp 3 HD Text-to-Speech audio with online and streaming requests.
Summary
This notebook introduces Chirp 3 HD voices in Google Cloud Text-to-Speech and shows how to configure a project, endpoint, and client. It demonstrates online synthesis with synthesize_speech returning MP3 bytes, then streaming synthesis by splitting text into sentences and sending StreamingSynthesizeRequest messages. The generated audio is played inline with IPython Audio.
Key code patterns
Configure TTS client
API_ENDPOINT = "texttospeech.googleapis.com"
client = texttospeech.TextToSpeechClient(
client_options=ClientOptions(api_endpoint=API_ENDPOINT)
)Creates a Text-to-Speech client against the selected global or regional endpoint.
Select Chirp 3 HD voice
voice_name = f"{language_code}-Chirp3-HD-{voice}"
voice = texttospeech.VoiceSelectionParams(
name=voice_name,
language_code=language_code,
)Builds the Chirp 3 HD voice name from language code and voice option.
Online synthesis
response = client.synthesize_speech(
input=texttospeech.SynthesisInput(text=prompt),
voice=voice,
audio_config=texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.MP3
),
)Converts a single text prompt into MP3 audio bytes.
Streaming synthesis
yield texttospeech.StreamingSynthesizeRequest(
streaming_config=texttospeech.StreamingSynthesizeConfig(voice=voice)
)
for text in text_iterator:
yield texttospeech.StreamingSynthesizeRequest(
input=texttospeech.StreamingSynthesisInput(text=text)
)Sends one streaming config request followed by text input requests.
Models & APIs used
- Models: en-US-Chirp3-HD-Aoede
- APIs / services: Cloud Text-to-Speech API, Vertex AI
- SDKs / libraries:
google-cloud-texttospeech
When to use this
Use this pattern to add Chirp 3 HD Text-to-Speech output to apps that need online or streamed voice generation.
Gotchas & caveats
- Requires an existing Google Cloud project with the Text-to-Speech API enabled.
- Colab requires authenticate_user before using Google Cloud credentials.
- The notebook sets an application default quota project and runs application-default login.
- Chirp 3 availability depends on supported regions and endpoints.
- ffmpeg is installed separately for Linux or macOS.
- Streaming playback uses int16 chunks at a 24000 Hz rate.
Best practices
- Use PROJECT_ID from GOOGLE_CLOUD_PROJECT when no explicit project ID is provided.
- Build API_ENDPOINT from TTS_LOCATION so global and regional endpoints are handled consistently.
- Use ClientOptions to pass the Text-to-Speech API endpoint explicitly.
- Split long text into sentence chunks before streaming synthesis.
- Send the streaming configuration before streaming text inputs.
Related
- Concepts: Getting Started · Audio & Speech
- Entities: Vertex AI · Chirp
- Area: Audio Notebooks
- Best practices: Getting Started - Best Practices · Audio & Speech - Best Practices