average-knife-77348
11/15/2025, 7:53 AMstt.StreamAdapter. does it simply mocking realtime?tall-airline-16756
11/15/2025, 7:53 AMtall-airline-16756
11/15/2025, 7:54 AMstt.StreamAdapter in LiveKit is a helpful wrapper class created to bring streaming functionality to Speech-to-Text (STT) models that don’t naturally support real-time streaming input. It’s not just simulating real-time—it actually adapts non-streaming STT models to work smoothly in streaming scenarios by teaming up with Voice Activity Detection (VAD).
Here’s a friendly breakdown of how it works:
• It gently buffers audio input while using VAD to spot when someone is speaking.
• It sends out streaming events like START_OF_SPEECH and END_OF_SPEECH based on what VAD detects.
• When VAD signals the end of speech, it processes the complete speech segment by calling the STT model’s recognize method.
This approach is especially handy for STT providers like Whisper that don’t support streaming input directly. By using StreamAdapter, you get genuine streaming capabilities by smartly segmenting audio and coordinating between VAD and the non-streaming STT models.
If you’d like more details or some examples to help you along, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/stt/fallback_adapter.py | agents/src/voice/agent.ts | Speech-to-text (STT) models | LiveKit Docsaverage-knife-77348
11/15/2025, 7:57 AMtall-airline-16756
11/15/2025, 7:57 AMaverage-knife-77348
11/15/2025, 8:17 AMtall-airline-16756
11/15/2025, 8:18 AMrealtime=True for GPT-4o Transcribe, there's no need to use StreamAdapter. This setting activates OpenAI's built-in streaming capabilities, so it naturally supports real-time transcription without needing extra layers like StreamAdapter.
If you have any more questions or need a bit more help, please don't hesitate to reach out—I’m here for you!
Sources: OpenAI and LiveKit partner to turn Advanced Voice into an API | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/util... | Speech-to-text (STT) models | LiveKit Docsaverage-knife-77348
11/15/2025, 8:25 AMtall-airline-16756
11/15/2025, 8:26 AMresponse_done event or the on_user_turn_completed lifecycle hook, depending on which part of the interaction you'd like to manage.
1. Using response_done Event:
This event fires when the assistant's response is fully finished. Here's a simple example to guide you:
from livekit.plugins import openai
@session.on("response_done")
def on_response_done(response: openai.realtime.RealtimeResponse):
"""Called when an assistant's response is complete."""
if response.status == "incomplete":
# Handle incomplete response
print("Response incomplete: Max token limit reached")
elif response.status == "failed":
# Handle failed response
print("Response failed: Check rate limits")
else:
# Successful completion
print("Response completed successfully")
2. Using on_user_turn_completed Lifecycle Hook:
This hook triggers right after the user finishes speaking, signaling the end of their turn. Here's how you can use it:
from livekit import agents
class MyAgent(agents.Agent):
def on_user_turn_completed(self) -> None:
"""Called when the user has finished speaking."""
# Perform actions immediately after user turn ends
print("User turn completed")
You can definitely use these handlers together to smoothly manage the entire interaction—from recognizing when the user’s turn ends to wrapping up the assistant’s response. If you have any questions or want to explore this further, just let me know—I’m here to help!
Sources: agent/main.py | Pipeline nodes and hooks | LiveKit docsaverage-knife-77348
11/15/2025, 8:33 AMtall-airline-16756
11/15/2025, 8:33 AMturn_detection="realtime_llm" in the AgentSession when using OpenAI's Realtime API. This allows you to take advantage of OpenAI's built-in server-side turn detection, which is both efficient and cost-effective for handling user turns.
To make sure everything runs smoothly, you'll also want to configure the RealtimeModel with a valid turn_detection parameter, like this:
llm = openai.realtime.RealtimeModel(
voice="alloy",
turn_detection="server_vad" # or "semantic_vad"
)
If you'd rather use LiveKit's own turn detection models (such as MultilingualModel), just set turn_detection=None in the RealtimeModel and adjust the AgentSession accordingly.
Please feel free to reach out if you'd like me to walk you through any part of the setup or if you have any other questions—I'm here to help!
Sources: OpenAI Realtime API plugin guide | LiveKit docs | examples/src/basic_agent.ts | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Turn detection and interruptions | LiveKit Docsaverage-knife-77348
11/15/2025, 8:37 AMtall-airline-16756
11/15/2025, 8:37 AMon_final_transcript callback in LiveKit. The SpeechEvent object includes a language field, which you can access via event.alternatives[0].language. This makes it easy to compare the detected language with your target language(s) and decide whether to process or skip the transcript.
Here’s a simple example to guide you:
async def on_final_transcript(self, event: SpeechEvent):
transcript = event.alternatives[0].text
language = event.alternatives[0].language # e.g., "en", "es", "fr"
print(f"Detected language: {language}")
# Define your target language(s)
target_languages = ["en"] # Example: English only
if language in target_languages:
# Process the transcript
print(f"Processing transcript: {transcript}")
else:
# Skip or discard non-target languages
print(f"Discarding transcript in language: {language}")
This way, you can be confident that only transcripts in the languages you care about get processed. If you have any questions or want to explore this further, just let me know—I’m here to help!
Sources: Gladia STT plugin guide | LiveKit Docs | Speech-to-text (STT) models | LiveKit Docs | Events and error handling | LiveKit docs | livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.pyaverage-knife-77348
11/18/2025, 1:16 AMtall-airline-16756
11/18/2025, 1:17 AMon_user_turn_completed hook. This hook gives you access to the new_message parameter, which includes transcription data along with the detected language (as long as your STT model supports it).
Here’s a friendly example to help you get started:
from livekit.agents import ChatContext, ChatMessage
from livekit.agents.voice import StopResponse
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage):
# Grab the detected language from the transcription
detected_lang = new_message.language # Just make sure your STT model provides this
# Set your target language(s)
target_languages = ["en"] # For example, English only
if detected_lang not in target_languages:
# Skip the agent's response if the language isn't what you're targeting
raise StopResponse()
This method depends on your STT model’s language detection feature. If the detected language isn’t in your target list, you can easily prevent the agent from responding or manage the input in another way. Feel free to reach out if you'd like me to walk you through this further or if you have any other questions!
Sources: Pipeline nodes and hooks | LiveKit docs | LiveKit turn detector plugin | LiveKit docs | tests/test_agent_session.py