early-restaurant-74591
08/02/2025, 3:24 AMtall-airline-16756
08/02/2025, 3:24 AMtall-airline-16756
08/02/2025, 3:25 AMpip install "livekit-agents[turn-detector,openai]" openai
2. Initialize Components: Use Deepgram STT and OpenAI's real-time API while disabling OpenAI's built-in turn detection.
3. Configure the Agent Session: Set up the AgentSession with the necessary components.
Here is a complete Python code example:
from livekit.agents import (
Agent,
AgentSession,
JobContext,
WorkerOptions,
cli,
)
from livekit.plugins import (
deepgram,
openai,
silero,
)
from livekit.plugins.turn_detector.multilingual import MultilingualModel
from dotenv import load_dotenv
load_dotenv()
async def entrypoint(ctx: JobContext):
stt = deepgram.STT(model="nova-3", language="multi")
turn_detection = MultilingualModel()
llm = openai.realtime.RealtimeModel(
voice="alloy",
turn_detection=None,
input_audio_transcription=None,
)
session = AgentSession(
turn_detection=turn_detection,
vad=silero.VAD.load(),
stt=stt,
llm=llm,
)
agent = Agent(instructions="You are a helpful assistant.")
await session.start(agent=agent, room=ctx.room)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
Key Points:
• Use Deepgram STT for multi-language support.
• Leverage the MultilingualModel for turn detection.
• Disable OpenAI's built-in turn detection to avoid conflicts.
Ensure you have the necessary API keys for OpenAI and Deepgram set in your environment variables before running the script.early-restaurant-74591
08/02/2025, 3:57 AMtall-airline-16756
08/02/2025, 3:58 AMSpeechEvent objects that include the text and language details.
2. OpenAI Real-time API: This API takes in audio frames via WebSocket and keeps the transcriptions updated in real-time. It handles interim transcriptions through delta updates, and once the audio finishes, it processes the final transcriptions.
3. Turn Detection: The MultilingualModel steps in here to spot when the conversation switches between speakers, making sure the user’s and agent’s speech are neatly separated.
In the code you have, most of the transcription magic happens with the stt component (Deepgram STT) and the llm component (OpenAI real-time API). After that, the transcriptions are handed off to the AgentSession, which keeps the conversation flowing and outputs the transcribed text.
If anything’s unclear or you want to dive deeper into any part of the transcription process, just give me a shout—I’m here to help!
Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real...early-restaurant-74591
08/02/2025, 4:01 AMtall-airline-16756
08/02/2025, 4:01 AM