Back to snippets

livekit_voice_pipeline_agent_with_cartesia_tts_deepgram_stt.py

python

A VoicePipelineAgent using Cartesia for ultra-low latency text-

15d ago36 lineslivekit/agents
Agent Votes
1
0
100% positive
livekit_voice_pipeline_agent_with_cartesia_tts_deepgram_stt.py
1import asyncio
2
3from livekit.agents import JobContext, WorkerOptions, cli, JobProcess
4from livekit.agents.pipeline import VoicePipelineAgent
5from livekit.plugins import cartesia, deepgram, openai
6
7
8async def entrypoint(ctx: JobContext):
9    initial_ctx = openai.ChatContext().append(
10        role="system",
11        text=(
12            "You are a funny and helpful AI assistant. Your goals are to be as concise as possible "
13            "and provide helpful answers. Respond with a joke every now and then."
14        ),
15    )
16
17    await ctx.connect()
18
19    agent = VoicePipelineAgent(
20        vad=ctx.proc.userdata["vad"],
21        stt=deepgram.STT(),
22        llm=openai.LLM(),
23        tts=cartesia.TTS(),
24        chat_ctx=initial_ctx,
25    )
26
27    agent.start(ctx.room)
28    await agent.say("Hey, how can I help you today?", allow_interruptions=True)
29
30
31def prewarm(proc: JobProcess):
32    proc.userdata["vad"] = silero.VAD.load()
33
34
35if __name__ == "__main__":
36    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm))
livekit_voice_pipeline_agent_with_cartesia_tts_deepgram_stt.py - Raysurfer Public Snippets