<#C088ZNU7QQ5|ask-ai> generate an example of sampl...
# ask-ai
i
#ask-ai generate an example of sample agent which uses google services like google text to speech ,llm and google speech to text
t
Thanks for reaching out, Maaz. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you want a sample agent that uses Google Speech-to-Text, a Google LLM (Gemini), and Google Text-to-Speech. Below is a concise runnable example (Python) that demonstrates how to wire those services into a LiveKit agent session. It shows authentication, minimal setup, and the core flow: STT → LLM → TTS. Prerequisites • Install the LiveKit agents Google plugin: uv add "livekit-agents[google]~=1.2" • Set Google credentials: ◦
GOOGLE_API_KEY
for Gemini access, and/or ◦
GOOGLE_APPLICATION_CREDENTIALS
pointing to a service account JSON for Cloud STT/TTS. Example (Python)
Copy code
import os
from livekit import agents, rtc
from livekit.agents import AgentSession, Agent, room_io
from livekit.plugins import google, silero
from livekit.plugins.turn_detector.multilingual import MultilingualModel

# Set credentials (or use env vars outside code)
os.environ["GOOGLE_API_KEY"] = "YOUR_GEMINI_API_KEY"
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/service_account.json"

class GoogleAssistant(Agent):
    def __init__(self) -> None:
        super().__init__(
            instructions="You are a helpful voice assistant using Google AI services.",
            llm=google.LLM(model="gemini-2.0"),            # Gemini LLM
            tts=google.TTS(voice_name="en-US-Standard-H"),# Google Cloud TTS voice
        )

server = agents.AgentServer()

@server.rtc_session()
async def my_agent(ctx: agents.JobContext):
    session = AgentSession(
        stt=google.STT(model="latest_long"),          # Google Cloud STT model
        llm=google.LLM(model="gemini-2.0"),
        tts=google.TTS(voice_name="en-US-Standard-H"),
        vad=silero.VAD.load(),
        turn_detection=MultilingualModel(),
    )

    await session.start(
        room=ctx.room,
        agent=GoogleAssistant(),
        room_options=room_io.RoomOptions(
            audio_input=room_io.AudioInputOptions(),  # use default mic input from room
        ),
    )

    # Optional: greet user via TTS
    await session.generate_reply(instructions="Greet the user and ask how you can help.")

if __name__ == "__main__":
    agents.cli.run_app(server)
Notes and next steps • Adjust model names and voice parameters to match your account quotas and desired voices. • If you want sample SSML control for TTS, I can add a short snippet showing SSML usage. • Tell me whether you'll run this inside a serverless environment, container, or local dev machine so I can include any environment-specific tips. Sources: Google Cloud STT plugin guide | LiveKit Docs | Gemini Live API plugin | LiveKit docs | Gemini TTS plugin guide | LiveKit Docs | Google Cloud TTS integration guide | LiveKit Docs | Google Gemini LLM plugin guide | LiveKit Docs
i
#ask-ai python3 agent.py console Agents Starting console mode 🚀 092055.542 DEBUG asyncio Using selector: EpollSelector 092055.544 INFO livekit.agents starting worker {"version": "1.3.5", "rtc-version": "1.0.19"} 092055.546 INFO livekit.agents preloading plugins {"packages": ["livekit.plugins.google", "livekit.plugins.silero", "livekit.plugins.turn_detector", "av"]} 092055.549 INFO livekit.agents starting inference executor 092056.490 INFO livekit.agents initializing process {"pid": 121222, "inference": true} None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used. 092058.607 INFO livekit.agents process initialized {"pid": 121222, "inference": true, "elapsed_time": 2.12} 092058.611 INFO livekit.agents initializing job runner {"tid": 121305} 092058.612 INFO livekit.agents job runner initialized {"tid": 121305, "elapsed_time": 0.0} DEBUG asyncio Using selector: EpollSelector 092058.636 DEBUG google.auth._de… Checking /path/to/service_account.json for explicit credentials as part of auth process... 092058.637 ERROR livekit.agents unhandled exception while running the job task Traceback (most recent call last): File "/home/mazz-ullah/Desktop/OtherProjects/Restaurant/AI/.venv/lib/python3.10/s ite-packages/opentelemetry/util/_decorator.py", line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore File "/home/mazz-ullah/Desktop/OtherProjects/Restaurant/AI/.venv/lib/python3.10/s ite-packages/livekit/agents/ipc/job_proc_lazy_main.py", line 284, in _traceable_entrypoint await self._job_entrypoint_fnc(job_ctx) File "/home/mazz-ullah/Desktop/OtherProjects/Restaurant/AI/agent.py", line 26, in my_agent stt=google.STT(model="latest_long"), # Google Cloud STT model File "/home/mazz-ullah/Desktop/OtherProjects/Restaurant/AI/.venv/lib/python3.10/s ite-packages/livekit/plugins/google/stt.py", line 157, in init raise ValueError( ValueError: Application default credentials must be available when using Google STT without explicitly passing credentials through credentials_info or credentials_file.
t
You're seeing the error because Google STT requires Application Default Credentials when you don't pass credentials explicitly. I'll help you fix that. Please try one of the following options: 1) Set GOOGLE_APPLICATION_CREDENTIALS to a valid service account JSON file • Export the path to your service account key file before running the agent: ◦ Linux/macOS: export GOOGLE_APPLICATION_CREDENTIALS="/full/path/to/service_account.json" ◦ Windows (PowerShell): $env:GOOGLE_APPLICATION_CREDENTIALS = "C:\full\path\service_account.json" • Confirm the file exists and is a valid Google service account key. 2) Pass credentials explicitly to google.STT • Update your AgentSession STT initialization to provide
credentials_file
or `credentials_info`:
Copy code
session = AgentSession(
    stt=google.STT(model="latest_long", credentials_file="/full/path/to/service_account.json"),
    ...
)
or load the JSON and pass it as
credentials_info
. 3) Use GOOGLE_API_KEY for Gemini only (not enough for Cloud STT) •
GOOGLE_API_KEY
can authenticate Gemini, but Cloud STT/TTS needs application credentials (service account JSON). Tell me which option you'd like to try and share the OS (Linux/macOS/Windows) and whether you prefer environment variables or explicit credentials—I’ll provide the exact command or code snippet.