My tts is using google voice and currently setup l...
# ask-ai
b
My tts is using google voice and currently setup like in agent.py this: tts=google.TTS( language="en-US", gender="female", _voice_name_="en-US-Chirp3-HD-Leda", _audio_encoding_=texttospeech.AudioEncoding.LINEAR16, ), But this is using the Chirp3 models, how to use the newer gemmini flash models? Here's the difference in config from google provided json: new:
Copy code
{
  "audioConfig": {
    "audioEncoding": "LINEAR16",
    "pitch": 0,
    "speakingRate": 1
  },
  "input": {
    "text": "Movies, oh my gosh, I just just absolutely love them. They're like time machines taking you to different worlds and landscapes, and um, and [whisper] I just can't get enough of it."
  },
  "voice": {
    "languageCode": "en-US",
    "modelName": "gemini-2.5-flash-preview-tts",
    "name": "Achernar"
  }
}
old:
Copy code
{
  "audioConfig": {
    "audioEncoding": "LINEAR16",
    "pitch": 0,
    "speakingRate": 1
  },
  "input": {
    "text": "Movies, oh my gosh, I just just absolutely love them. They're like time machines taking you to different worlds and landscapes, and um, and [whisper] I just can't get enough of it."
  },
  "voice": {
    "languageCode": "en-US",
    "modelName": "gemini-2.5-flash-preview-tts",
    "name": "Achernar"
  }
}
t
Thanks for reaching out, Alex. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you get started with the newer Gemini Flash models for Google TTS in your setup! You can easily integrate the
GeminiTTS
class from the LiveKit Google plugin. Let me walk you through the configuration step-by-step: Installation: • If you're using Python, just run:
pip install "livekit-agents[google]~=1.2"
Authentication: • Make sure to set the
GOOGLE_APPLICATION_CREDENTIALS
environment variable to point to your service account key file for Vertex AI. • Alternatively, you can set the
GOOGLE_API_KEY
environment variable or pass the API key directly when creating the Google Gemini API instance. Configuration: Here’s a simple example to configure the Gemini Flash model in Python:
Copy code
from livekit.plugins import google
session = AgentSession(
  tts=google.beta.GeminiTTS(
    model="gemini-2.5-flash-preview-tts",
    voice_name="Achernar",
    instructions="Speak in a friendly and engaging tone.",
  ),
  # ... other configurations (LLM, STT, etc.)
)
Key Parameters: • `model`: Use
gemini-2.5-flash-preview-tts
for the latest voice. • `voice_name`: Choose the voice you like, for example,
Achernar
. • `instructions`: This helps you customize the tone, style, and pace of the speech. Just a quick note: streaming isn’t supported yet, and the audio sample rate is fixed at 24000 Hz. If you have any questions or need more help, please don’t hesitate to ask—I’m here to support you! Sources: Docs::Agents | plugins/google/README.md
b
mispasted the old one, one sec:
Copy code
{
  "audioConfig": {
    "audioEncoding": "LINEAR16",
    "pitch": 0,
    "speakingRate": 1
  },
  "input": {
    "text": "Movies, oh my gosh, I just just absolutely love them. They're like time machines taking you to different worlds and landscapes, and um, and [whisper] I just can't get enough of it."
  },
  "voice": {
    "languageCode": "en-US",
    "name": "en-US-Chirp3-HD-Achernar"
  }
}
t
Thanks so much for sharing the updated configuration! The main difference between the older Chirp3 models and the newer Gemini Flash models is in the
modelName
parameter. To switch over to the Gemini Flash models, you’ll want to update your configuration to include the
modelName
field like this:
Copy code
{
  "audioConfig": {
    "audioEncoding": "LINEAR16",
    "pitch": 0,
    "speakingRate": 1
  },
  "input": {
    "text": "Movies, oh my gosh, I just just absolutely love them. They're like time machines taking you to different worlds and landscapes, and um, and [whisper] I just can't get enough of it."
  },
  "voice": {
    "languageCode": "en-US",
    "modelName": "gemini-2.5-flash-preview-tts",
    "name": "Achernar"
  }
}
Make sure your TTS setup in the code reflects this update. If you have any questions or need a hand with anything else, just let me know—I’m here to help!
b
here's my full current setup, can you give me the full updated one in return.
Copy code
session = AgentSession(

        # A Large Language Model (LLM) is your agent's brain, processing user input and generating a response
        # See all providers at https://docs.livekit.io/agents/integrations/llm/
        llm=openai.LLM(model="gpt-4o-mini"),
        # Speech-to-text (STT) is your agent's ears, turning the user's speech into text that the LLM can understand
        # See all providers at https://docs.livekit.io/agents/integrations/stt/
        stt=deepgram.STT(model="nova-3", language="multi"),
        # Text-to-speech (TTS) is your agent's voice, turning the LLM's text into speech that the user can hear
        # See all providers at https://docs.livekit.io/agents/integrations/tts/
        tts=google.beta.GeminiTTS(
    model="gemini-2.5-flash-preview-tts",
    voice_name="Achernar", 
        ),

        # VAD and turn detection are used to determine when the user is speaking and when the agent should respond

        # See more at https://docs.livekit.io/agents/build/turns
        #   # Temporarily disabled due to PyTorch dependency
        vad=ctx.proc.userdata["vad"],
        # allow the LLM to generate a response while waiting for the end of turn
        # See more at https://docs.livekit.io/agents/build/audio/#preemptive-generation
        preemptive_generation=True,
    )
t
Here’s the updated configuration for your setup, now including the Gemini Flash model for TTS. I’ve added the
instructions
parameter to help the voice sound friendly and engaging, just as you wanted:
Copy code
session = AgentSession(

    # A Large Language Model (LLM) is your agent's brain, processing user input and generating a response
    llm=openai.LLM(model="gpt-4o-mini"),

    # Speech-to-text (STT) is your agent's ears, turning the user's speech into text that the LLM can understand
    stt=deepgram.STT(model="nova-3", language="multi"),

    # Text-to-speech (TTS) is your agent's voice, turning the LLM's text into speech that the user can hear
    tts=google.beta.GeminiTTS(
        model="gemini-2.5-flash-preview-tts",
        voice_name="Achernar",
        instructions="Speak in a friendly and engaging tone.",
    ),

    # VAD and turn detection are used to determine when the user is speaking and when the agent should respond
    vad=ctx.proc.userdata["vad"],

    # Allow the LLM to generate a response while waiting for the end of turn
    preemptive_generation=True,
)
If you have any questions or want to tweak anything further, just let me know—I’m here to help!
b
so here is my code:
Copy code
session = AgentSession(

        # A Large Language Model (LLM) is your agent's brain, processing user input and generating a response
        # See all providers at https://docs.livekit.io/agents/integrations/llm/
        llm=openai.LLM(model="gpt-4o-mini"),
        # Speech-to-text (STT) is your agent's ears, turning the user's speech into text that the LLM can understand
        # See all providers at https://docs.livekit.io/agents/integrations/stt/
        stt=deepgram.STT(model="nova-3", language="multi"),
        # Text-to-speech (TTS) is your agent's voice, turning the LLM's text into speech that the user can hear
        # See all providers at https://docs.livekit.io/agents/integrations/tts/
        tts=google.TTS(
            language="en-US",
            gender="female",
            voice_name="en-US-Chirp3-HD-Leda",
            audio_encoding=texttospeech.AudioEncoding.LINEAR16,
        ),
When using this, everything is working. But when I add/use yours, the exact code you gave me above, I get credential errors
t
It looks like the credential errors you're seeing might be because the Gemini Flash models authenticate a bit differently than the Chirp3 models. No worries though—let's work through this together! Here are a few things to check: 1. Authentication Setup: • For Vertex AI: Make sure the
GOOGLE_APPLICATION_CREDENTIALS
environment variable is set to the path of your service account key file. • For Google Gemini API: Double-check that the
GOOGLE_API_KEY
environment variable is set, or that you’re passing the API key directly in the constructor. 2. Verify Permissions: • It’s important to confirm that your service account or API key has the right permissions to access the Gemini Flash models. 3. Debugging: • Take a close look at the exact error message—it often gives clues about whether the problem is missing credentials, incorrect file paths, or permissions issues. If you’d like, I’m here to help you set up the credentials or dig deeper into the troubleshooting. Just let me know!
b
is this true even though we are just using tts?
t
I completely understand your question! Even if you're just using TTS, the Gemini Flash models do require proper authentication to access Google's services. This is because the Gemini Flash models are part of the Google Gemini API, which makes sure every request, including TTS, is authenticated for security. To keep things running smoothly, you'll want to set up one of the following: • Service Account Key: You can use the
GOOGLE_APPLICATION_CREDENTIALS
environment variable to point to your service account key file. • API Key: Alternatively, use the
GOOGLE_API_KEY
environment variable or pass the API key directly in the TTS constructor. If you'd like, I’m here to help you step-by-step with setting up these credentials—just let me know!
b
the new flash models are supposed to be fast but feel really slow... Anything we can do to improve this? here's an example 2025-09-26 171132,514 - INFO google_genai.models - AFC is enabled with max remote calls: 10. {"room": "playground-fb8n-PoJF", "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171134,016 - INFO livekit.agents - STT metrics {"room": "playground-fb8n-PoJF", "audio_duration": 5.05, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171140,569 - INFO livekit.agents - TTS metrics {"room": "playground-fb8n-PoJF", "ttfb": 4.654983006999828, "audio_duration": 3.13, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171142,346 - INFO livekit.agents - STT metrics {"room": "playground-fb8n-PoJF", "audio_duration": 5.0, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171145,118 - DEBUG livekit.agents - received user transcript {"room": "playground-fb8n-PoJF", "user_transcript": "Hey. How are you doing?", "language": "en", "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171145,247 - DEBUG livekit.agents - using preemptive generation {"room": "playground-fb8n-PoJF", "preemptive_lead_time": 0.12870359420776367, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171145,247 - INFO livekit.agents - EOU metrics {"room": "playground-fb8n-PoJF", "end_of_utterance_delay": 0.58, "transcription_delay": 0.45, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171146,163 - INFO google_genai.models - AFC is enabled with max remote calls: 10. {"room": "playground-fb8n-PoJF", "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171146,206 - INFO livekit.agents - LLM metrics {"room": "playground-fb8n-PoJF", "ttft": 0.91, "prompt_tokens": 189, "prompt_cached_tokens": 0, "completion_tokens": 13, "tokens_per_second": 11.96, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171147,396 - INFO livekit.agents - STT metrics {"room": "playground-fb8n-PoJF", "audio_duration": 5.05, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171149,065 - INFO livekit.agents - TTS metrics {"room": "playground-fb8n-PoJF", "ttfb": 2.8876631159946555, "audio_duration": 2.61, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171149,065 - INFO google_genai.models - AFC is enabled with max remote calls: 10. {"room": "playground-fb8n-PoJF", "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171151,292 - INFO livekit.agents - TTS metrics {"room": "playground-fb8n-PoJF", "ttfb": 2.207690775991068, "audio_duration": 1.33, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171152,396 - INFO livekit.agents - STT metrics {"room": "playground-fb8n-PoJF", "audio_duration": 5.0, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171157,397 - INFO livekit.agents - STT metrics {"room": "playground-fb8n-PoJF", "audio_duration": 5.0, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171158,256 - DEBUG livekit.agents - received user transcript {"room": "playground-fb8n-PoJF", "user_transcript": "Good. You're slow. Why are you slow?", "language": "en", "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171158,347 - DEBUG livekit.agents - using preemptive generation {"room": "playground-fb8n-PoJF", "preemptive_lead_time": 0.09048199653625488, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171158,347 - INFO livekit.agents - EOU metrics {"room": "playground-fb8n-PoJF", "end_of_utterance_delay": 0.58, "transcription_delay": 0.49, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171159,215 - INFO google_genai.models - AFC is enabled with max remote calls: 10. {"room": "playground-fb8n-PoJF", "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171159,642 - INFO livekit.agents - LLM metrics {"room": "playground-fb8n-PoJF", "ttft": 0.66, "prompt_tokens": 219, "prompt_cached_tokens": 0, "completion_tokens": 26, "tokens_per_second": 18.79, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171202,345 - INFO livekit.agents - TTS metrics {"room": "playground-fb8n-PoJF", "ttfb": 3.115475390004576, "audio_duration": 2.77, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171202,346 - INFO google_genai.models - AFC is enabled with max remote calls: 10. {"room": "playground-fb8n-PoJF", "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171202,446 - INFO livekit.agents - STT metrics {"room": "playground-fb8n-PoJF", "audio_duration": 5.05, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171206,602 - INFO livekit.agents - TTS metrics {"room": "playground-fb8n-PoJF", "ttfb": 4.197618780002813, "audio_duration": 3.73, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171206,602 - INFO google_genai.models - AFC is enabled with max remote calls: 10. {"room": "playground-fb8n-PoJF", "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171207,447 - INFO livekit.agents - STT metrics {"room": "playground-fb8n-PoJF", "audio_duration": 5.0, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171211,336 - DEBUG livekit.agents - received user transcript {"room": "playground-fb8n-PoJF", "user_transcript": "Why do you sound like a psycho?", "language": "en", "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"} 2025-09-26 171211,342 - INFO livekit.agents - TTS metrics {"room": "playground-fb8n-PoJF", "ttfb": -1.0, "audio_duration": 0.0, "pid": 52663, "job_id": "AJ_ystpXMvwoq4o"}
t
I'm glad you're looking to enhance the performance and reduce latency for the Gemini Flash TTS models! Here are some friendly suggestions that might help: 1. Optimize Network Latency: • It’s a good idea to have your server located near Google's TTS servers to keep network delays low. • Also, double-check your internet connection to make sure there aren’t any slowdowns or bottlenecks. 2. Batch Requests: • If you can, try batching multiple TTS requests together. This can really help cut down on the overhead from making individual API calls. 3. Preload and Cache: • Preloading and caching frequently used phrases or sentences can save time by avoiding repeated synthesis. 4. Debugging: • Take a look at your logs for any delays or errors. For instance, the
ttfb
(time to first byte) metric shows how quickly the TTS service starts responding. If you notice high
ttfb
values, it might indicate server-side delays or authentication hiccups. If you'd like, I’m here to help you walk through these steps or troubleshoot further. Just let me know!
b
it looks like it's reconnecting every time, can we not maintain a connection or something like that?
t
I completely understand your curiosity about how the Google Gemini Flash TTS models work in LiveKit. Right now, these models don’t support persistent connections or session reuse. This means that each TTS request is treated as a separate, stateless API call, so a new connection is made every time you request synthesis. I know this might feel a bit limiting, but this behavior is built into the TTS implementation and can’t be changed at the moment. That said, there are some great ways to help improve performance: • Try preloading and caching phrases you use often to avoid making the same requests repeatedly. • Consider batching multiple TTS requests together when you can, which helps reduce connection overhead. • Also, having a low-latency network connection to Google's servers can make a noticeable difference. If you have any more questions or need a hand with anything else, please don’t hesitate to reach out—I’m here to help! Sources: plugins/google/src/llm.ts | livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py
b
is this streaming or waiting for the full thing to be generated. Are the older tts models just better?
t
Thank you for reaching out! I wanted to share that the Google Gemini Flash TTS models in LiveKit currently don’t support streaming synthesis. This means each request waits until the full audio is ready before it starts playing, which can sometimes lead to a bit more delay compared to streaming models that play audio as it’s generated. On the other hand, older TTS models like Chirp3 might feel quicker since they’re optimized for lower latency and often support streaming synthesis. The Gemini Flash models, though, are crafted to deliver richer, more natural-sounding speech, which can take a little extra processing time. If having low latency is really important for your experience, you might want to consider using the older models or checking out other TTS options that offer streaming. I’m here to help if you’d like guidance on switching back or making the most of your current setup—just let me know!
b
stt=deepgram.STT(model="nova-3", language="multi"), What's the correct format to make this english instead of multi?
t
To set Deepgram STT to English instead of "multi," you can simply use either of these options: •
language="en"
•
language="en-US"
Both work perfectly! If you have any questions or need a hand with this, just let me know—I’m here to help! Sources: Deepgram STT integration guide | LiveKit Docs | Deepgram integration guide | LiveKit Docs | plugins/deepgram/src/models.ts | livekit-plugins/livekit-plugins-speechmatics/livekit/plugins/speechmatics/s... | Deepgram STT integration guide | LiveKit Docs