import asyncio
from livekit import agents
from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli
from livekit.agents.voice_assistant import VoiceAssistant
from livekit.plugins import kugelaudio, silero, openai
async def entrypoint(ctx: JobContext):
# Connect to the room
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
# Wait for a participant
participant = await ctx.wait_for_participant()
# Create the voice assistant
assistant = VoiceAssistant(
# Voice Activity Detection
vad=silero.VAD.load(),
# Speech-to-Text
stt=openai.STT(),
# Language Model
llm=openai.LLM(model="gpt-4o-mini"),
# Text-to-Speech with KugelAudio
tts=kugelaudio.TTS(
model="kugel-1-turbo",
voice_id=123,
cfg_scale=2.0,
),
)
# Start the assistant
assistant.start(ctx.room, participant)
# Initial greeting
await assistant.say("Hello! I'm your AI assistant. How can I help you today?")
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))