strong-pizza-31661
08/03/2025, 12:54 PMboundless-truck-87206
08/03/2025, 1:09 PMmysterious-agent-76276
08/03/2025, 1:59 PM["text"+"audio"]
it overrides my TTS model with the OpenAI model.brief-vase-33757
08/03/2025, 3:17 PMambitious-ice-35806
08/03/2025, 3:43 PMfrom dotenv import load_dotenv
from livekit import agents
from livekit.agents import AgentSession, Agent, RoomInputOptions
from livekit.plugins import elevenlabs,google,deepgram,noise_cancellation,silero
from livekit.plugins.turn_detector.multilingual import MultilingualModel
from Config import saveQualifiedLead,disqualifyLead,CallbackTime
from Prompts import SYSTEM_PROMPT
load_dotenv()
class Assistant(Agent):
def __init__(self) -> None:
super().__init__(instructions=SYSTEM_PROMPT,
stt=deepgram.STT(model="nova-2-phonecall"),
llm=google.LLM(model="gemini-2.5-flash-preview-05-20"),
tts=elevenlabs.TTS(model="eleven_turbo_v2_5",voice_id="UgBBYS2sOqTuMpoF3BR0"),
vad=silero.VAD.load(),
turn_detection=MultilingualModel(),
tools=[saveQualifiedLead,disqualifyLead,CallbackTime]
)
async def entrypoint(ctx: agents.JobContext):
session = AgentSession(allow_interruptions=False)
await session.start(
room=ctx.room,
agent=Assistant(),
room_input_options=RoomInputOptions(
audio_enabled=True,
video_enabled=False,
noise_cancellation=noise_cancellation.BVC(),
),
)
await session.generate_reply( instructions="Simply Say 'Hello!! How are you Doing!!' ")
if __name__ == "__main__":
agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint,agent_name="Umer"))
❌ Error:
2025-08-03 20:39:17,262 - INFO livekit.agents - initializing process {"pid": 3276, "inference": true}
2025-08-03 20:39:20,104 - DEBUG livekit.agents - initializing inference runner {"runner": "lk_end_of_utterance_multilingual", "pid": 3276, "inference": true}
2025-08-03 20:39:27,270 - INFO livekit.agents - killing process {"pid": 3276, "inference": true}
2025-08-03 20:39:27,270 - ERROR livekit.agents - worker failed
Traceback (most recent call last):
File "C:\Python313\Lib\asyncio\tasks.py", line 507, in wait_for
return await fut
^^^^^^^^^
File "D:\livekit-Agent-development\.venv\Lib\site-packages\livekit\agents\ipc\channel.py", line 47, in arecv_message
return _read_message(await dplx.recv_bytes(), messages)
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\livekit-Agent-development\.venv\Lib\site-packages\livekit\agents\utils\aio\duplex_unix.py", line 35, in recv_bytes
len_bytes = await self._reader.readexactly(4)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\asyncio\streams.py", line 769, in readexactly
await self._wait_for_data('readexactly')
File "C:\Python313\Lib\asyncio\streams.py", line 539, in _wait_for_data
await self._waiter
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\livekit-Agent-development\.venv\Lib\site-packages\livekit\agents\cli\_run.py", line 79, in _worker_run
await worker.run()
File "D:\livekit-Agent-development\.venv\Lib\site-packages\livekit\agents\worker.py", line 387, in run
await self._inference_executor.initialize()
File "D:\livekit-Agent-development\.venv\Lib\site-packages\livekit\agents\ipc\supervised_proc.py", line 169, in initialize
init_res = await asyncio.wait_for(
^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
)
^
File "C:\Python313\Lib\asyncio\tasks.py", line 506, in wait_for
async with timeouts.timeout(timeout):
~~~~~~~~~~~~~~~~^^^^^^^^^
File "C:\Python313\Lib\asyncio\timeouts.py", line 116, in __aexit__
raise TimeoutError from exc_val
TimeoutError
2025-08-03 20:39:27,277 - ERROR livekit.agents - Error in _read_ipc_task
Traceback (most recent call last):
File "D:\livekit-Agent-development\.venv\Lib\site-packages\livekit\agents\utils\aio\duplex_unix.py", line 35, in recv_bytes
len_bytes = await self._reader.readexactly(4)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\asyncio\streams.py", line 767, in readexactly
raise exceptions.IncompleteReadError(incomplete, n)
asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of 4 expected bytes
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\livekit-Agent-development\.venv\Lib\site-packages\livekit\agents\utils\log.py", line 16, in async_fn_logs
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\livekit-Agent-development\.venv\Lib\site-packages\livekit\agents\cli\watcher.py", line 120, in _read_ipc_task
msg = await channel.arecv_message(self._pch, proto.IPC_MESSAGES)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\livekit-Agent-development\.venv\Lib\site-packages\livekit\agents\ipc\channel.py", line 47, in arecv_message
return _read_message(await dplx.recv_bytes(), messages)
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\livekit-Agent-development\.venv\Lib\site-packages\livekit\agents\utils\aio\duplex_unix.py", line 43, in recv_bytes
raise DuplexClosed() from e
livekit.agents.utils.aio.duplex_unix.DuplexClosed
boundless-truck-87206
08/03/2025, 4:45 PMchilly-motorcycle-32290
08/03/2025, 4:58 PMvictorious-summer-64766
08/03/2025, 5:03 PMboundless-truck-87206
08/03/2025, 5:28 PMmany-hair-70963
08/03/2025, 5:38 PMboundless-truck-87206
08/03/2025, 5:55 PMmany-fall-81099
08/03/2025, 9:03 PMstrong-pizza-31661
08/03/2025, 9:19 PMvoiceAgentMultiLogging.py
so that # automatic activity detection and related sensitivities are aligned across # our agents. rt_cfg = genai_types.RealtimeInputConfig( automatic_activity_detection={ "disabled": False, "start_of_speech_sensitivity": "START_SENSITIVITY_LOW", "end_of_speech_sensitivity": "END_SENSITIVITY_LOW", "prefix_padding_ms": 20, "silence_duration_ms": 100, } ) import os load_dotenv() # Load Pronet agent prompt (English) PRONET_PROMPT = Path("pronet_agent_prompt_en.txt").read_text(encoding="utf-8") class Assistant(Agent): def __init__(self) -> None: super().__init__(instructions=PRONET_PROMPT) async def entrypoint(ctx: agents.JobContext): await ctx.connect() model = google.beta.realtime.RealtimeModel( api_key=os.getenv("GEMINI_API_KEY"), model="gemini-live-2.5-flash-preview", modalities=["text"], temperature=0.8, #input_audio_transcription=None, realtime_input_config=rt_cfg, # <- typed object with the attr LK needs ) # Create AgentSession with the multimodal model session = AgentSession( llm=model, tts=elevenlabs.TTS( voice_id="cgSgspJ2msm6clMCkdW9", language="en", streaming_latency=3, ), ) # -------------------------------------------------- # DATA COLLECTION: track conversation items # -------------------------------------------------- chat_history: list[dict] = [] @session.on("conversation_item_added") def _on_item(ev): if hasattr(ev.item, "role"): role = ev.item.role text_content = getattr(ev.item, "text_content", "") or "" chat_history.append({"role": role, "text": text_content}) # Instantiate your Assistant agent and start the voice session agent_instance = Assistant() await session.start( room=ctx.room, agent=agent_instance, ) # -------------------------------------------------- # OUTPUT COLLECTED DATA # -------------------------------------------------- print("\n=== Conversation Transcript ===") for turn in chat_history: print(f"{turn['role']}: {turn['text']}") print("=== End of Transcript ===\n") if name == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))helpful-salesclerk-77327
08/04/2025, 12:48 AMnutritious-policeman-86688
08/04/2025, 1:34 AMabundant-magician-17307
08/04/2025, 1:39 AMkind-iron-94532
08/04/2025, 3:17 AMancient-hospital-67205
08/04/2025, 3:29 AMpolite-oil-10264
08/04/2025, 3:30 AMhelpful-salesclerk-77327
08/04/2025, 4:23 AMcalm-train-17221
08/04/2025, 5:14 AMhelpful-salesclerk-77327
08/04/2025, 5:44 AMhelpful-salesclerk-77327
08/04/2025, 5:48 AMnice-fish-21757
08/04/2025, 5:49 AMabundant-magician-17307
08/04/2025, 5:58 AMfuture-stone-69754
08/04/2025, 6:12 AMopenai
plugin.
Install the plugin from PyPI:
pip install "livekit-agents[openai]~=1.0"
Authentication
The Azure OpenAI TTS requires authentication
using an API key or a managed identity.
Set the following environment variables in your .env
file:
AZURE_OPENAI_API_KEY=<azure-openai-api-key>
AZURE_OPENAI_AD_TOKEN=<azure-openai-ad-token>
AZURE_OPENAI_ENDPOINT=<azure-openai-endpoint>
Usage
Use Azure OpenAI TTS within an AgentSession
or as a standalone speech generator. For example, you can use this TTS in the Voice AI quickstart.
from livekit.plugins import openai
session = AgentSession(
tts=openai.TTS.with_azure(
model="gpt-4o-mini-tts",
voice="coral",
)
# ... llm, stt, etc.
)
adamant-sandwich-74490
08/04/2025, 7:03 AMtts_request
or stt_request
as such? The goal is to easily track TTS and STT model usage and costs from Langfuse's dashboard.
Is there anything that can be done from Livekit's end to achieve this?salmon-motherboard-10077
08/04/2025, 7:34 AMmysterious-agent-76276
08/04/2025, 7:37 AMon_user_turn_completed
?
the idea is that I want the LLM to always return a JSON, not text. And I want the agent to be able to access the JSON response.
tis there a way to makesalmon-motherboard-10077
08/04/2025, 7:45 AM