how to use google.TTS
# ask-ai
n
how to use google.TTS
t
Thanks for reaching out, Sajjad. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking how to use
google.TTS
. I’ll cover installation, authentication, basic usage, and where to find voice/SSML options. Installation • Install the Google TTS plugin for LiveKit (Python only):
Copy code
uv add "livekit-agents[google]~=1.5"
Authentication • Provide Google credentials via one of: ◦
credentials_info
(dictionary) ◦
credentials_file
(path; can be set with
GOOGLE_APPLICATION_CREDENTIALS
) ◦ Application Default Credentials (ADC) Basic usage • Create an
AgentSession
with `google.TTS`:
Copy code
from livekit.plugins import google
session = AgentSession(
    tts = google.TTS(
        gender="female",
        voice_name="en-US-Standard-H",
    ),
    # ... llm, stt, etc.
)
Key parameters •
language
(default
en-US
) — output language code •
gender
(
male
,
female
,
neutral
) •
voice_name
— specific voice (see Google’s voices list) •
voice_cloning_key
— for custom/cloned voices (Chirp 3) •
credentials_info
/
credentials_file
— authentication Customizing speech • SSML is supported for pronunciation, pitch, rate, pauses. Use Google’s SSML reference to craft inputs. References • Google Cloud TTS integration guide: https://docs.livekit.io/agents/models/tts/google • Plugin reference: https://docs.livekit.io/reference/python/livekit/plugins/google/index.html#livekit.plugins.google.TTS • Google TTS voices and SSML: https://cloud.google.com/text-to-speech/docs Would you like a full example showing SSML usage or help wiring credentials into your app? Sources: Google Cloud TTS integration guide | LiveKit Documentation, with interactive elements
n
help wiring credentials into your app?
t
You're asking how to wire Google Cloud credentials for
google.TTS
. Below are three supported ways and short examples so you can pick the one that fits your deployment. 1) Use
GOOGLE_APPLICATION_CREDENTIALS
(credentials file) • Save your service-account JSON to a secure path (e.g.,
/secrets/gcloud-sa.json
). • Set the env var in your environment/container: ◦ Linux/macOS:
export GOOGLE_APPLICATION_CREDENTIALS="/secrets/gcloud-sa.json"
◦ Docker: use
-e GOOGLE_APPLICATION_CREDENTIALS=/secrets/gcloud-sa.json
and mount the file. • No additional code required;
google.TTS
will use ADC and the file. 2) Pass
credentials_file
to
google.TTS
• Point the plugin directly at the file path:
Copy code
from livekit.plugins import google

session = AgentSession(
    tts = google.TTS(
        credentials_file="/secrets/gcloud-sa.json",
        voice_name="en-US-Standard-H",
    ),
)
3) Pass credentials inline via
credentials_info
(dictionary) • Load the JSON and pass it as a dict (useful if you store secrets in a vault):
Copy code
import json
from livekit.plugins import google

with open("/secrets/gcloud-sa.json") as f:
    creds = json.load(f)

session = AgentSession(
    tts = google.TTS(
        credentials_info=creds,
        voice_name="en-US-Standard-H",
    ),
)
Security notes • Keep service-account keys restricted and stored in a secure secret store where possible. • Prefer ADC or secret manager → environment file over committing keys in source code. Would you like a sample Docker Compose snippet or an example using a secret manager (AWS Secrets Manager / GCP Secret Manager)? , with interactive elements
n
wher this file is placed
t
Good question — here are recommended places to put the Google service-account JSON and how to reference it for each environment. Local development • Put the file somewhere not in your repo, e.g.
~/secrets/gcloud-sa.json
or a project-level
./secrets/gcloud-sa.json
. • Set the env var: ◦ macOS/Linux:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/secrets/gcloud-sa.json"
◦ Windows (PowerShell):
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\path\to\secrets\gcloud-sa.json"
Containerized (Docker) • Store the file on the host (outside source tree) and mount it into the container: ◦
docker run -v /host/secrets/gcloud-sa.json:/secrets/gcloud-sa.json -e GOOGLE_APPLICATION_CREDENTIALS=/secrets/gcloud-sa.json your-image
• Or inject via your container orchestrator’s secret mechanism (Kubernetes Secret, Docker secrets) and set
GOOGLE_APPLICATION_CREDENTIALS
to the mounted path. Production / Cloud • Prefer a secret manager (GCP Secret Manager, AWS Secrets Manager, HashiCorp Vault). Retrieve the secret at startup and either: ◦ Write to a local file path and set
GOOGLE_APPLICATION_CREDENTIALS
to that path, or ◦ Pass the JSON into
google.TTS
with
credentials_info
(dictionary) so you never write the file to disk. Examples of referencing the path in code • Environment-based (no code changes): rely on ADC after setting
GOOGLE_APPLICATION_CREDENTIALS
. • Direct plugin:
google.TTS(credentials_file="/secrets/gcloud-sa.json", ...)
• Inline: load secret and pass
credentials_info=creds_dict
Security tips • Don’t commit the JSON to source control. • Limit the service account permissions to only needed TTS scopes. • Rotate keys and store them in a secrets manager when possible. Do you want a Docker Compose example or a Kubernetes Secret + deployment example? , with interactive elements
n
where this file is passed
t
You're asking where to pass the Google service-account JSON so
google.TTS
can authenticate. Here are the three ways and exactly where to pass the file/data in each case. 1) Environment variable (ADC) • Place the JSON on disk (outside your repo), e.g.
/secrets/gcloud-sa.json
. • Set the env var so the runtime picks it up: ◦ Linux/macOS:
export GOOGLE_APPLICATION_CREDENTIALS="/secrets/gcloud-sa.json"
◦ Docker:
-e GOOGLE_APPLICATION_CREDENTIALS=/secrets/gcloud-sa.json -v /host/secrets/gcloud-sa.json:/secrets/gcloud-sa.json
• Where it’s passed: the Google client library reads the path from `GOOGLE_APPLICATION_CREDENTIALS`; no code changes required. 2)
credentials_file
argument to
google.TTS
• Place the JSON file on disk and point the plugin at it:
Copy code
from livekit.plugins import google

session = AgentSession(
    tts=google.TTS(
        credentials_file="/secrets/gcloud-sa.json",
        voice_name="en-US-Standard-H",
    ),
)
• Where it’s passed: directly into the plugin via the
credentials_file
parameter. 3) Inline
credentials_info
(dict) • Retrieve the JSON from your secret store at runtime (vault, secret manager, env var) and load it into a dict:
Copy code
import json
from livekit.plugins import google

creds = json.loads(os.environ["GC_SA_JSON"])  # or load from secret manager
session = AgentSession(
    tts=google.TTS(
        credentials_info=creds,
        voice_name="en-US-Standard-H",
    ),
)
• Where it’s passed: as the
credentials_info
parameter in code — no file necessary. Recommended placements by environment • Local dev:
~/secrets/gcloud-sa.json
and set
GOOGLE_APPLICATION_CREDENTIALS
. • Docker: host path mounted into container at
/secrets/gcloud-sa.json
and set env var or use
credentials_file
. • Kubernetes / Production: use your secret manager (GCP Secret Manager, Kubernetes Secret, Vault). Either: ◦ Mount the secret to a file path and set
GOOGLE_APPLICATION_CREDENTIALS
, or ◦ Fetch secret at startup and pass it as
credentials_info
to avoid writing to disk. Security reminders • Don’t commit the JSON to source control. • Prefer secret managers or ADC. • Least-privilege the service account. Do you want a Docker Compose snippet or a Kubernetes Secret + Deployment example for your environment? , with interactive elements