Google Cloud TTS
The GoogleHttpTTSService provides professional, high-quality text-to-speech synthesis using Google Cloud's extensive library of neural and standard voices. It supports comprehensive SSML for fine-grained control and features advanced Chirp and Journey models for conversational excellence.
Installation
To use Google Cloud TTS, install the required dependencies:
pip install "piopiy-ai[google]"
Prerequisites
- A Google Cloud project with the Text-to-Speech API enabled (Get yours here).
- Set your credentials in your environment:
export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/service-account.json"
Configuration
GoogleHttpTTSService Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
credentials | str | None | JSON string of service account credentials. |
credentials_path | str | None | Path to service account JSON file. |
voice_id | str | "en-US-Chirp3-HD-Charon" | Google TTS voice ID. |
sample_rate | int | None | Audio sample rate in Hz. |
params | InputParams | InputParams() | Advanced styling and prosody settings. |
InputParams
| Parameter | Type | Default | Description |
|---|---|---|---|
pitch | str | None | Voice pitch adjustment (e.g., "+2st", "-50%"). |
rate | str | None | Speaking rate (SSML) (e.g., "slow", "fast"). |
speaking_rate | float | None | Speaking rate (Chirp/Journey) [0.25, 2.0]. |
volume | str | None | Volume adjustment (e.g., "loud", "+6dB"). |
emphasis | str | None | Text emphasis level (strong, moderate, etc.). |
language | Language | Language.EN | Language for synthesis. |
gender | str | None | Preferred voice gender. |
google_style | str | None | Speaking style (apologetic, calm, empathetic, etc.). |
Usage
Basic Setup
import os
from piopiy.services.google.tts import GoogleHttpTTSService
tts = GoogleHttpTTSService(
voice_id="en-US-Journey-F"
)
With Advanced Styles (Chirp 3)
from piopiy.services.google.tts import GoogleHttpTTSService
tts = GoogleHttpTTSService(
voice_id="en-US-Chirp3-HD-Charon",
params=GoogleHttpTTSService.InputParams(
speaking_rate=1.1,
gender="male"
)
)
Notes
- Service Authenticated: This service requires valid Google Cloud credentials to be available via environment variables or explicitly passed.
- Model Support: Chirp and Journey voices represent Google's latest conversational technology and do not support standard SSML tags; use
speaking_ratefor these models instead. - Output Format: Piopiy automatically handles the removal of WAV headers for seamless streaming playback.