I'm using OpenAI's Realtime Model for STT+LLM (usi...
# ask-ai
m
I'm using OpenAI's Realtime Model for STT+LLM (using
text
modalities). How do I capture the user's transcription BEFORE the
on_user_state_changed
=
listening
? Right now I have a hook on
user_input_transcribed
but it's getting triggered after the
on_user_state_changed
.
t
Thanks for reaching out, Anas. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for your question! The
user_input_transcribed
hook is triggered right after the
on_user_state_changed
event changes the user state to "listening". This happens because of the way the OpenAI Realtime Model handles transcription events. When the Realtime Model’s built-in transcription is on, it listens for when the user finishes speaking and then creates the transcription internally. The
user_state_changed
event switches to "listening" before the transcription is fully done, and then the
user_input_transcribed
event follows immediately with the final transcript. If you’re looking to capture the transcription a bit earlier, you might want to tweak the event handling or consider using external STT systems that provide intermediate transcription updates. Please feel free to reach out if you’d like me to help you explore these options further—I’m here to support you! Sources: livekit-agents/livekit/agents/voice/agent_session.py | plugins/openai/src/realtime/realtime_model.ts | Events and error handling | LiveKit Docs
m
is there a way to do it from the openai's realtime model session directly? like using internal events instead of using a separate STT
t
Thank you for reaching out! I understand you're looking to capture transcription before the
on_user_state_changed
event switches to "listening." Currently, the
user_input_transcribed
event happens right after the transcription is done, usually following that state change. If you’re hoping to work with the transcription a bit earlier, one idea might be to tweak your event handling or explore some intermediate transcription events within the Realtime Model’s processing. I’m here to help if you want to dive deeper into this or explore other options together—just let me know! Sources: agents/src/voice/agent_activity.ts | Events and error handling | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py
m
yes, can you help me explore some intermediate transcription events within the realtime model?
t
Thanks for your question! The OpenAI Realtime Model offers intermediate transcription events for agent responses through the
response.audio_transcript.delta
event. These events provide partial transcripts bit by bit, which is great for real-time processing or showing the response text as it’s being generated. However, when it comes to user input, the model doesn’t automatically give interim transcription results by default. If you’re looking to get intermediate transcription for user input, usually you’d want to use a separate STT plugin that can emit partial transcription events. If you’d like, I’d be happy to guide you through implementing this or help you understand how to work with the
response.audio_transcript.delta
events better—just let me know! Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | plugins/google/src/beta/realtime/realtime_api.ts | Realtime model integrations | LiveKit Docs | LiveKit turn detector plugin | LiveKit Docs | agent/main.py
m
yes please guide me through implementing this
t
To help you implement intermediate transcription for user input using a separate STT plugin, here’s a friendly step-by-step guide you can follow: 1. Choose an STT Plugin: Start by selecting a plugin that supports real-time transcription and provides partial transcription events. Some great options are Google Cloud Speech-to-Text, AWS Transcribe, or similar services that fit your needs. 2. Integrate the Plugin: Next, set up the STT plugin to handle audio input from your application. Make sure it’s configured to emit those helpful partial transcription events while the audio is being processed. 3. Subscribe to Partial Transcription Events: Use the plugin’s API to listen for updates on partial transcriptions. For example, if you’re working in Python, it might look like this:
Copy code
def on_partial_transcription(event):
    print(f"Partial transcript: {event.transcript}")

stt_plugin.on("partial_transcription", on_partial_transcription)
1. Forward Transcriptions to the Realtime Model: When you get those partial transcriptions, you can send them to the OpenAI Realtime Model if you want to process them further or update the context dynamically. 2. Handle Final Transcriptions: Finally, be sure to capture and properly process the final transcription to complete the user input flow smoothly. If you’d like, I’m here to help with any specific STT plugin you’re working with or to provide more details on integrating it with the OpenAI Realtime Model. Just let me know!