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))
При попытке я обнаружил следующие ошибки: uv run Agent.py console:
В настоящее время я создаю агент голосового искусственного интеллекта с помощью LiveKit. Моя текущая база кода взята из LiveKit. [code]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.")
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))
[/code] При попытке я обнаружил следующие ошибки: uv run Agent.py console: [code] 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] [/code] Я использую Ubuntu 24.04 LTS. Рад за вашу помощь!