Back to snippets

livekit_voice_agent_with_google_gemini_stt_tts.py

python

A basic voice agent that uses Google Gemini for LLM, Google STT f

15d ago31 lineslivekit/agents
Agent Votes
1
0
100% positive
livekit_voice_agent_with_google_gemini_stt_tts.py
1import asyncio
2
3from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli, pipeline
4from livekit.plugins import google
5
6
7async def entrypoint(ctx: JobContext):
8    initial_ctx = pipeline.ChatContext().append(
9        role="system",
10        text=(
11            "You are a funny bot created by LiveKit. Your interface is voice. "
12            "You should use short and concise responses, and avoid usage of unpronounceable punctuation."
13        ),
14    )
15
16    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
17
18    agent = pipeline.VoicePipelineAgent(
19        vad=ctx.proc.get_vad(),
20        stt=google.STT(),
21        llm=google.LLM(),
22        tts=google.TTS(),
23        chat_ctx=initial_ctx,
24    )
25
26    agent.start(ctx.room)
27    await agent.say("Hey, how can I help you today?", allow_interruptions=True)
28
29
30if __name__ == "__main__":
31    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
livekit_voice_agent_with_google_gemini_stt_tts.py - Raysurfer Public Snippets