Skip to main content

Google 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

ParameterTypeDefaultDescription
credentialsstrNoneJSON string of service account credentials.
credentials_pathstrNonePath to service account JSON file.
voice_idstr"en-US-Chirp3-HD-Charon"Google TTS voice ID.
sample_rateintNoneAudio sample rate in Hz.
paramsInputParamsInputParams()Advanced styling and prosody settings.

InputParams

ParameterTypeDefaultDescription
pitchstrNoneVoice pitch adjustment (e.g., "+2st", "-50%").
ratestrNoneSpeaking rate (SSML) (e.g., "slow", "fast").
speaking_ratefloatNoneSpeaking rate (Chirp/Journey) [0.25, 2.0].
volumestrNoneVolume adjustment (e.g., "loud", "+6dB").
emphasisstrNoneText emphasis level (strong, moderate, etc.).
languageLanguageLanguage.ENLanguage for synthesis.
genderstrNonePreferred voice gender.
google_stylestrNoneSpeaking 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_rate for these models instead.
  • Output Format: Piopiy automatically handles the removal of WAV headers for seamless streaming playback.