faint-arm-51818
09/10/2025, 5:44 PMtall-airline-16756
09/10/2025, 5:44 PMtall-airline-16756
09/10/2025, 5:45 PMsession.on("user_input_transcribed")
right within your Agent definition in LiveKit. This is a wonderful feature of the LiveKit Agents framework that lets you handle user input transcriptions in real-time, making your agents truly interactive.
For instance, if you're working with Python, you can use the @session.on("user_input_transcribed")
decorator to set up an event handler like this:
from livekit.agents.voice import AgentSession
from livekit.plugins import deepgram
session = AgentSession()
@session.on("user_input_transcribed")
def on_transcript(event):
if event.is_final:
print(f"Final transcript: {event.transcript}")
session.say(event.transcript)
await session.start(
agent=Agent(stt=deepgram.STT()),
room=ctx.room
)
And if you’re using Node.js, here’s a similar approach:
import { AgentSession } from '@livekit/agents';
import { DeepgramSTT } from '@livekit/plugins-deepgram';
const session = new AgentSession();
session.on("user_input_transcribed", (event) => {
if (event.is_final) {
console.log(`Final transcript: ${event.transcript}`);
session.say(event.transcript);
}
});
await session.start({
agent: new Agent({ stt: new DeepgramSTT() }),
room
});
The user_input_transcribed
event comes with helpful properties like transcript
, is_final
, and you can also access language
and speaker_id
if needed. This flexibility really empowers you to create responsive and engaging agents. If you have any questions or want to explore this further, I’m here to help!
Sources: translators/tts_translator.py | Events and error handling | LiveKit Docsfaint-arm-51818
09/10/2025, 5:47 PMtall-airline-16756
09/10/2025, 5:48 PMsession.on("user_input_transcribed")
aren’t meant to be defined directly inside the Agent
class. Instead, they work best when you attach listeners to the AgentSession
instance, since these events are all about the session level.
Here’s a friendly example to illustrate how you can define the event listener outside the Agent
class:
session = AgentSession()
@session.on("user_input_transcribed")
def on_transcript(event):
if event.is_final:
session.say(event.transcript)
Another approach is to register event listeners dynamically inside the Agent
class during runtime—maybe in an initialization or setup method—by using self.session
. Just a heads up, this isn’t the usual way and is a bit less common.
If you’d like me to walk you through this with more examples or if anything feels unclear, please don’t hesitate to ask. I’m here to help!
Sources: Events and error handling | LiveKit Docs | translators/tts_translator.py | livekit-agents/livekit/agents/voice/agent_session.py