fast-egg-39595
08/25/2025, 6:40 PMtall-airline-16756
08/25/2025, 6:40 PMtall-airline-16756
08/25/2025, 6:41 PMfast-egg-39595
08/25/2025, 6:42 PMtall-airline-16756
08/25/2025, 6:43 PMfast-egg-39595
08/25/2025, 6:45 PMtall-airline-16756
08/25/2025, 6:47 PMfast-egg-39595
08/25/2025, 6:55 PMtall-airline-16756
08/25/2025, 6:55 PMfrom livekit.agents import AgentSession, UserInputTranscribedEvent
from livekit.plugins import speechmatics, google
# Step 1: Set up Speechmatics STT with diarization
stt = speechmatics.STT(
transcription_config=speechmatics.types.TranscriptionConfig(
language="en",
operating_point="enhanced",
enable_partials=True,
diarization="speaker",
speaker_diarization_config={"max_speakers": 2},
),
speaker_active_format="[Speaker {speaker_id}]: {text}",
)
# Step 2: Configure Gemini Live API to work in text-only mode
llm = google.beta.realtime.RealtimeModel(
model="gemini-2.0-flash-exp",
temperature=0.8,
instructions="You are conversing with multiple speakers. Speaker IDs are marked as [Speaker X]. Respond appropriately to each speaker.",
modalities=["TEXT"] # Text-only mode
)
# Step 3: Create an AgentSession with both STT and LLM
session = AgentSession(
stt=stt,
llm=llm,
# Feel free to add your preferred TTS here if you want
)
# Step 4: Handle transcriptions and keep track of speaker context
@session.on("user_input_transcribed")
def on_user_input_transcribed(event: UserInputTranscribedEvent):
print(f"Transcription: [Speaker {event.speaker_id}]: {event.transcript}")
# Step 5: Start the session
session.start()
Here are some key things to keep in mind:
• Speaker Formatting: Using speaker_active_format makes sure transcripts include speaker IDs, which Gemini uses to understand who’s talking.
• Gemini Instructions: The instructions parameter guides Gemini on how to interpret the speaker-tagged text properly.
• Text-Only Mode: Setting modalities=["TEXT"] tells Gemini to focus on processing text input while keeping speaker context intact.
This setup gives you a working agent that smoothly combines Speechmatics diarization with the Gemini Live API in text-only mode. If you have any questions or want to explore more features, just let me know—I’m here to help!fast-egg-39595
08/25/2025, 9:01 PMlist[Modality]
Optional
Default:
["AUDIO"]
List of response modalities to use. Set to ["TEXT"] to use the model in text-only mode with a separate TTS plugin."tall-airline-16756
08/25/2025, 9:02 PMmodalities=["TEXT"], TTS is needed because the model is set up to output text only, not audio. This way, you get to take advantage of Gemini’s smart speech understanding while having the freedom to decide how your audio responses sound.
To get speech output in a voice conversation, you'll want a separate TTS (Text-to-Speech) component that turns those text responses into audio. Here’s an example:
from google.genai.types import Modality
session = AgentSession(
llm=google.beta.realtime.RealtimeModel(modalities=[Modality.TEXT]),
tts=cartesia.TTS(),
)
With this setup, LiveKit automatically uses the TTS model to convert text into audio whenever the Gemini API is running in text-only mode. Plus, it lets you pick custom TTS providers and voices to match what you’re looking for.
If you’d like a hand setting up a TTS component for your agent, just let me know—I’m here to help!
Sources: examples/voice_agents/realtime_with_tts.py | Gemini Live API integration guide | LiveKit Docsfast-egg-39595
08/25/2025, 9:14 PMtall-airline-16756
08/25/2025, 9:16 PMmodalities=["TEXT"], it will only work with text input and won’t expect any audio. But if audio is sent without the right setup, that’s when this error pops up.
• Speechmatics STT can handle diarization and give you speaker-attributed text, which you can then send to Gemini in text-only mode.
Here’s how you can fix it:
1. Make sure Gemini Live API is configured with modalities=["TEXT"] if you’re not sending audio.
2. Double-check that Speechmatics STT is correctly processing the audio and giving you diarized text output.
3. If you want audio output, you’ll need to add a TTS component to convert the text back to speech.
Would you like me to walk you through some detailed troubleshooting steps or help you design a specific integration pipeline? I’m here to help!
Sources: Gemini Live API integration guide | LiveKit Docs | Speechmatics STT integration guide | LiveKit Docsfast-egg-39595
08/25/2025, 9:20 PMtall-airline-16756
08/25/2025, 9:21 PM["AUDIO", "TEXT"] modalities, the model creates audio right away, so you don’t need any extra TTS. But if you choose ["TEXT"] only, the API will give you text responses, and LiveKit will step in to use a separate TTS provider to turn that text into audio.
This setup gives you some nice flexibility:
• With ["AUDIO", "TEXT"], you get to use Gemini’s built-in voice synthesis for audio output.
• With ["TEXT"], you can plug in your own TTS provider if you want more control over the voice style, language, or quality.
The fallback system makes sure you always get audio, no matter how you configure it, while giving you the freedom to pick what works best for you. If you want me to walk you through it or help with your setup, just let me know—I’m happy to help!
Sources: Gemini Live API integration guide | LiveKit Docs | examples/voice_agents/realtime_with_tts.pytall-airline-16756
10/06/2025, 7:53 PM