2

I am currently building a voice AI agent using LiveKit. My current code base is from LiveKit.

from dotenv import load_dotenv
from livekit import agents
from livekit.agents import AgentSession, Agent, RoomInputOptions
from livekit.plugins import (
 openai,
 noise_cancellation,
)
load_dotenv(".env")
class Assistant(Agent):
 def __init__(self) -> None:
 super().__init__(instructions="You are a helpful voice AI assistant.")
async def entrypoint(ctx: agents.JobContext):
 session = AgentSession(
 llm=openai.realtime.RealtimeModel(
 voice="coral"
 )
 )
 await session.start(
 room=ctx.room,
 agent=Assistant(),
 room_input_options=RoomInputOptions(
 # For telephony applications, use `BVCTelephony` instead for best results
 noise_cancellation=noise_cancellation.BVC(),
 ),
 )
 await session.generate_reply(
 instructions="Greet the user and offer your assistance. You should start by speaking in English."
 )
if __name__ == "__main__":
 agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))

I met the following errors when I tried: uv run agent.py console:

 await session.start(
 File "/home/sh1nata/Downloads/NailAIHub/backend/.venv/lib/python3.12/site-packages/opentelemetry/util/_decorator.py", line 71, in async_wrapper
 return await func(*args, **kwargs) # type: ignore
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/sh1nata/Downloads/NailAIHub/backend/.venv/lib/python3.12/site-packages/livekit/agents/voice/agent_session.py", line 568, in start
 await asyncio.gather(*tasks)
 File "/home/sh1nata/Downloads/NailAIHub/backend/.venv/lib/python3.12/site-packages/livekit/agents/voice/chat_cli.py", line 271, in start
 self._update_microphone(enable=True)
 File "/home/sh1nata/Downloads/NailAIHub/backend/.venv/lib/python3.12/site-packages/livekit/agents/voice/chat_cli.py", line 339, in _update_microphone
 self._input_stream = sd.InputStream(
 ^^^^^^^^^^^^^^^
 File "/home/sh1nata/Downloads/NailAIHub/backend/.venv/lib/python3.12/site-packages/sounddevice.py", line 1452, in __init__
 _StreamBase.__init__(self, kind='input', wrap_callback='array',
 File "/home/sh1nata/Downloads/NailAIHub/backend/.venv/lib/python3.12/site-packages/sounddevice.py", line 909, in __init__
 _check(_lib.Pa_OpenStream(self._ptr, iparameters, oparameters,
 File "/home/sh1nata/Downloads/NailAIHub/backend/.venv/lib/python3.12/site-packages/sounddevice.py", line 2823, in _check
 raise PortAudioError(errormsg, err)
sounddevice.PortAudioError: Error opening InputStream: Invalid sample rate [PaErrorCode -9997]

I am using Ubuntu 24.04 LTS. I'm glad for your help!

T3 H40
2,8338 gold badges45 silver badges57 bronze badges
asked Oct 31, 2025 at 9:40
1

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.