billowy-psychiatrist-32507
09/05/2025, 9:36 AMtall-airline-16756
09/05/2025, 9:36 AMtall-airline-16756
09/05/2025, 9:36 AMgpt-4o-mini-transcribe model is fully supported for speech-to-text (STT) functionality, so you’ll receive user speech transcriptions as soon as they’re ready from the STT service.
If you have any more questions or need a hand with anything else, just let me know—I’m here to help!
Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | AI voice agents | LiveKit Docs | plugins/openai/src/models.tsbillowy-psychiatrist-32507
09/05/2025, 9:38 AMtall-airline-16756
09/05/2025, 9:39 AMbillowy-psychiatrist-32507
09/05/2025, 9:39 AMtall-airline-16756
09/05/2025, 9:40 AMgpt-4o-mini-transcribe model is great for this since it supports real-time transcription and sends out both interim and final transcript events.
Here’s a simple way to log those user transcripts:
• First, set up the OpenAI STT class to use the gpt-4o-mini-transcribe model.
• Then, subscribe to transcript events via the SpeechStream interface—it handles audio frames and gives you INTERIM_TRANSCRIPT and FINAL_TRANSCRIPT events.
• Be sure to capture the FINAL_TRANSCRIPT events to get the complete and accurate user utterances logged.
Also, if you want to show live transcriptions on your frontend, you can use the RoomOutputOptions parameter with transcription_enabled=True. For logging on the server side, just listen for agent events like user_speech_committed.
If you’d like, I’m happy to help with more details or share some code examples—just let me know!
Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/models.py | OpenAI and LiveKit | LiveKit Docs | Recording agent sessions | LiveKit Docsbillowy-psychiatrist-32507
09/05/2025, 9:45 AMtall-airline-16756
09/05/2025, 9:46 AMimport asyncio
import logging
from livekit.agents import (
AgentSession,
JobContext,
JobProcess,
WorkerOptions,
cli,
metrics,
AgentFalseInterruptionEvent,
RoomInputOptions,
UserStateChangedEvent,
MetricsCollectedEvent,
)
from livekit.plugins import openai, silero, noise_cancellation
from src.api.routes import run_fastapi
from src.utils.config import (
LLM_MODEL_NAME,
LOG_LEVEL,
STT_MODEL_NAME,
VoiceConfig,
LoadBalancingConfig,
)
from src.utils.logger import setup_logging
from src.voice_assistant import Assistant
from dotenv import load_dotenv
from src.utils.tts_provider import create_tts
load_dotenv()
disconnect_task = None
def prewarm(proc: JobProcess) -> None:
proc.userdata["vad"] = silero.VAD.load(
min_speech_duration=VoiceConfig.min_speech_duration,
min_silence_duration=VoiceConfig.min_silence_duration,
activation_threshold=VoiceConfig.activation_threshold,
force_cpu=VoiceConfig.force_cpu,
padding_duration=VoiceConfig.padding_duration,
max_buffered_speech=VoiceConfig.max_buffered_speech,
)
async def entrypoint(ctx: JobContext) -> None:
logger = logging.getLogger("support-assistant")
logger.info("Initializing support assistant...")
await ctx.connect()
tts_instance = create_tts()
session = AgentSession(
llm=openai.LLM(model=LLM_MODEL_NAME),
stt=openai.STT(language=VoiceConfig.language, model=STT_MODEL_NAME),
tts=tts_instance,
vad=ctx.proc.userdata["vad"],
preemptive_generation=True,
user_away_timeout=15,
)
@session.on("user_state_changed")
def _on_user_state_changed(ev: UserStateChangedEvent):
global disconnect_task
if ev.new_state == "away":
logger.info("User inactive 30s → asking if they are still there...")
session.generate_reply(
instructions="ask user if they are still there in conversation or not"
)
async def delayed_disconnect():
await asyncio.sleep(15)
if session.user_state == "away":
logger.info("No response after warning → disconnecting")
try:
await ctx.delete_room()
except Exception as e:
logger.warning(f"Room deletion raised (likely already closed): {e}")
disconnect_task = asyncio.create_task(delayed_disconnect())
elif ev.new_state == "active":
logger.info("User became active again, cancelling pending disconnect")
if disconnect_task and not disconnect_task.done():
disconnect_task.cancel()
disconnect_task = None
@session.on("agent_false_interruption")
def _on_false_interrupt(ev: AgentFalseInterruptionEvent):
logger.info("False positive interruption detected, resuming...")
session.generate_reply(instructions=ev.extra_instructions or "")
@session.on("transcription")
def _on_transcription(ev):
if ev.type == "FINAL_TRANSCRIPT":
logger.info(f"User transcript: {ev.text}")
usage_collector = metrics.UsageCollector()
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
metrics.log_metrics(ev.metrics)
usage_collector.collect(ev.metrics)
async def log_usage():
summary = usage_collector.get_summary()
logger.info(f"Usage summary: {summary}")
ctx.add_shutdown_callback(log_usage)
await session.start(
agent=Assistant(room=ctx.room),
room=ctx.room,
room_input_options=RoomInputOptions(
noise_cancellation=noise_cancellation.BVC(),
),
)
try:
await session.say(
"Hi there! I'm Maya, your voice assistant specialized in personalized skincare consultations. "
"Are you looking for skincare products, or a gift for someone?",
allow_interruptions=False,
)
logger.info("Initial greeting delivered to user")
except Exception as e:
logger.error(f"Failed to deliver greeting: {e}")
if __name__ == "__main__":
setup_logging()
worker_opts = WorkerOptions(
entrypoint_fnc=entrypoint,
load_threshold=LoadBalancingConfig.load_threshold,
num_idle_processes=LoadBalancingConfig.num_idle_processes,
max_retry=LoadBalancingConfig.max_retry,
shutdown_process_timeout=LoadBalancingConfig.shutdown_timeout,
initialize_process_timeout=LoadBalancingConfig.initialize_timeout,
prewarm_fnc=prewarm,
)
cli.run_app(worker_opts)
This way, your app listens for transcription events and logs the final transcripts whenever they come in. If anything’s unclear or you want me to help with the next steps, just let me know—I’m here to help!billowy-psychiatrist-32507
09/05/2025, 9:50 AMRoomInputOptions.close_on_disconnect=False)
{"message": "closing agent session due to participant disconnect (disable via RoomInputOptions.close_on_disconnect=False)", "level": "INFO", "name": "livekit.agents", "participant": "identity-oyfm", "reason": "CLIENT_INITIATED", "timestamp": "2025-09-05T094826.173464+00:00"}
[2025-09-05 151826] [INFO] livekit.agents: TTS metrics
{"message": "TTS metrics", "level": "INFO", "name": "livekit.agents", "ttfb": -1.0, "audio_duration": 0.0, "timestamp": "2025-09-05T094826.209943+00:00"}
[2025-09-05 151826] [WARNING] livekit.agents: rotate_segment called while previous segment is still being rotated
{"message": "rotate_segment called while previous segment is still being rotated", "level": "WARNING", "name": "livekit.agents", "timestamp": "2025-09-05T094826.229050+00:00"}
[2025-09-05 151850] [WARNING] livekit: livekit:rtc engine453livekit:rtc_engine - received session close: "signal client closed: \"stream closed\"" UnknownReason Resume
{"message": "livekit:rtc engine453livekit:rtc_engine - received session close: \"signal client closed: \\\"stream closed\\\"\" UnknownReason Resume", "level": "WARNING", "name": "livekit", "timestamp": "2025-09-05T094850.724526+00:00"}
[2025-09-05 151850] [INFO] support-assistant: Usage summary: UsageSummary(llm_prompt_tokens=1390, llm_prompt_cached_tokens=0, llm_input_audio_tokens=0, llm_completion_tokens=38, llm_output_audio_tokens=0, tts_characters_count=246, tts_audio_duration=12.348000000000003, stt_audio_duration=3.092)
{"message": "Usage summary: UsageSummary(llm_prompt_tokens=1390, llm_prompt_cached_tokens=0, llm_input_audio_tokens=0, llm_completion_tokens=38, llm_output_audio_tokens=0, tts_characters_count=246, tts_audio_duration=12.348000000000003, stt_audio_duration=3.092)", "level": "INFO", "name": "support-assistant", "timestamp": "2025-09-05T094850.733679+00:00"}tall-airline-16756
09/05/2025, 9:51 AMgpt-4o-transcribe instead of gpt-4o-mini-transcribe.
2. Enable Debug Logging: Adding debug-level logging can give you a clearer picture of what’s happening with transcription events and any errors:
import logging
logging.getLogger("livekit").setLevel(logging.DEBUG)
3. Check Frontend Subscription: Make sure your frontend is subscribed to the lk.transcription data track so it can receive and log those transcripts.
4. Confirm Audio Input: Verify that the agent is actually getting audio from the participant. Using RoomOutputOptions(transcription_enabled=True) helps ensure transcription is turned on.
5. Test with Known Configuration: Try this setup to see if it works:
session = AgentSession(
stt=openai.STT(model="gpt-4o-transcribe"),
room_output_options=RoomOutputOptions(transcription_enabled=True),
)
6. Check API Key and Authentication: Lastly, double-check that your OpenAI or Azure API keys and endpoints are set up correctly.
If you hit any bumps or want a hand with any of these steps, just let me know—I’m here to help!
Sources: OpenAI STT integration guide | LiveKit Docs | README.md | plugins/openai/src/realtime/realtime_model.ts | main.py | Azure OpenAI STT integration guide | LiveKit Docsbillowy-psychiatrist-32507
09/05/2025, 9:56 AMtall-airline-16756
09/05/2025, 9:56 AM@session.on("user_input_transcribed") did the trick! This event is really handy because it's made just for catching and managing user input transcriptions, so it works perfectly for logging transcripts.
If you have any more questions or need a hand with anything else, just let me know—I’m here to help!billowy-psychiatrist-32507
09/05/2025, 10:03 AMtall-airline-16756
09/05/2025, 10:04 AMEnglishModel from the turn detector plugin to catch speech turns in English:
`from livekit.plugins.turn_detector.english import EnglishModel
session = AgentSession(
turn_detection=EnglishModel(),
# ... other configurations
)`Before you run the agent, just download the model files by running:
python agent.py download-files
2. Set STT Plugin for English:
Make sure your STT plugin is set up to handle only English audio. For example, with OpenAI STT, you’d do:
`stt=openai.STT(model="gpt-4o-transcribe", language="en", detect_language=False)`If you’re using other STT plugins like Deepgram, Groq, or CLOVA, they also support English-only settings. Just let me know if you want me to share examples for those!
This way, your agent will focus solely on English input. Feel free to reach out if you need any more help!
Sources: livekit-plugins/livekit-plugins-rime/livekit/plugins/rime/langs.py | Groq integration guide | LiveKit Docs | Groq integration guide | LiveKit Docs | LiveKit turn detector plugin | LiveKit Docs