I am trying to use google.TTS plugin and need to s...
# ask-ai
a
I am trying to use google.TTS plugin and need to set credentials. I have an API key to google but this one wants a dict or json location. Im a bit unsure how these credentials work? And cant seem to find much documentation for it. How to set it up?
t
Thanks for reaching out, Malte. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let's walk through how you can set up credentials for the
google.TTS
plugin. You have a few friendly options to choose from: 1. Passing credentials directly via `credentials_info`: Here, you provide a dictionary with your Google Cloud service account credentials when you create the
TTS
object. This dictionary should include keys like
project_id
,
private_key
,
client_email
, and others from your service account JSON key file.
Copy code
from livekit.plugins import google

tts = google.TTS(
    credentials_info={
        "type": "service_account",
        "project_id": "your-project-id",
        "private_key_id": "your-private-key-id",
        "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
        "client_email": "your-service-account@your-project.iam.gserviceaccount.com",
        "client_id": "your-client-id",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/..."
    }
)
2. Using a credentials JSON file with `credentials_file`: Simply save your Google Cloud service account key as a JSON file and pass its path using the
credentials_file
parameter.
tts = google.TTS(credentials_file="path/to/your-service-account-key.json")
3. Setting the
GOOGLE_APPLICATION_CREDENTIALS
environment variable:
You can point the
GOOGLE_APPLICATION_CREDENTIALS
environment variable to your service account key file’s path. The plugin will then automatically use Application Default Credentials (ADC).
Copy code
# In shell
export GOOGLE_APPLICATION_CREDENTIALS="path/to/your-service-account-key.json"

# In Python
tts = google.TTS()  # No need to pass credentials explicitly
Just a quick reminder: please make sure the Cloud Text-to-Speech API is enabled in your Google Cloud project. If you have any questions or need a hand with any step, feel free to reach out—I'm here to help! Sources: Google Cloud TTS integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-fishaudio/README.md