Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/voice_agents/basic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
JobProcess,
MetricsCollectedEvent,
ModelSettings,
RoomInputOptions,
RoomOutputOptions,
RunContext,
WorkerOptions,
cli,
metrics,
room_io,
)
from livekit.agents.llm import function_tool
from livekit.plugins import deepgram, openai, silero
Expand Down Expand Up @@ -123,11 +122,12 @@ async def log_usage():
await session.start(
agent=MyAgent(),
room=ctx.room,
room_input_options=RoomInputOptions(
# uncomment to enable Krisp BVC noise cancellation
# noise_cancellation=noise_cancellation.BVC(),
room_options=room_io.RoomOptions(
audio_input=room_io.AudioInputOptions(
# uncomment to enable the Krisp BVC noise cancellation
# noise_cancellation=noise_cancellation.BVC(),
),
),
room_output_options=RoomOutputOptions(transcription_enabled=True),
)


Expand Down
2 changes: 2 additions & 0 deletions livekit-agents/livekit/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
UserStateChangedEvent,
avatar,
io,
room_io,
)
from .voice.background_audio import AudioConfig, BackgroundAudioPlayer, BuiltinAudioClip, PlayHandle
from .voice.room_io import RoomInputOptions, RoomIO, RoomOutputOptions
Expand Down Expand Up @@ -127,6 +128,7 @@ def __getattr__(name: str) -> typing.Any:
"function_tool",
"ChatContext",
"ChatItem",
"room_io",
"RoomIO",
"RoomInputOptions",
"RoomOutputOptions",
Expand Down
35 changes: 18 additions & 17 deletions livekit-agents/livekit/agents/voice/agent_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ async def start(
*,
capture_run: Literal[True],
room: NotGivenOr[rtc.Room] = NOT_GIVEN,
room_options: NotGivenOr[room_io.RoomOptions] = NOT_GIVEN,
# deprecated
room_input_options: NotGivenOr[room_io.RoomInputOptions] = NOT_GIVEN,
room_output_options: NotGivenOr[room_io.RoomOutputOptions] = NOT_GIVEN,
) -> RunResult: ...
Expand All @@ -425,6 +427,8 @@ async def start(
*,
capture_run: Literal[False] = False,
room: NotGivenOr[rtc.Room] = NOT_GIVEN,
room_options: NotGivenOr[room_io.RoomOptions] = NOT_GIVEN,
# deprecated
room_input_options: NotGivenOr[room_io.RoomInputOptions] = NOT_GIVEN,
room_output_options: NotGivenOr[room_io.RoomOutputOptions] = NOT_GIVEN,
) -> None: ...
Expand All @@ -436,6 +440,8 @@ async def start(
*,
capture_run: bool = False,
room: NotGivenOr[rtc.Room] = NOT_GIVEN,
room_options: NotGivenOr[room_io.RoomOptions] = NOT_GIVEN,
# deprecated
room_input_options: NotGivenOr[room_io.RoomInputOptions] = NOT_GIVEN,
room_output_options: NotGivenOr[room_io.RoomOutputOptions] = NOT_GIVEN,
) -> RunResult | None:
Expand Down Expand Up @@ -485,40 +491,35 @@ async def start(
tasks.append(asyncio.create_task(chat_cli.start(), name="_chat_cli_start"))

elif is_given(room) and not self._room_io:
room_input_options = copy.copy(
room_input_options or room_io.DEFAULT_ROOM_INPUT_OPTIONS
)
room_output_options = copy.copy(
room_output_options or room_io.DEFAULT_ROOM_OUTPUT_OPTIONS
room_options = room_io.RoomOptions._ensure_options(
room_options,
room_input_options=room_input_options,
room_output_options=room_output_options,
)
room_options = copy.copy(room_options) # shadow copy is enough

if self.input.audio is not None:
if room_input_options.audio_enabled:
if room_options.audio_input:
logger.warning(
"RoomIO audio input is enabled but input.audio is already set, ignoring.." # noqa: E501
)
room_input_options.audio_enabled = False
room_options.audio_input = False

if self.output.audio is not None:
if room_output_options.audio_enabled:
if room_options.audio_output:
logger.warning(
"RoomIO audio output is enabled but output.audio is already set, ignoring.." # noqa: E501
)
room_output_options.audio_enabled = False
room_options.audio_output = False

if self.output.transcription is not None:
if room_output_options.transcription_enabled:
if room_options.text_output:
logger.warning(
"RoomIO transcription output is enabled but output.transcription is already set, ignoring.." # noqa: E501
)
room_output_options.transcription_enabled = False
room_options.text_output = False

self._room_io = room_io.RoomIO(
room=room,
agent_session=self,
input_options=room_input_options,
output_options=room_output_options,
)
self._room_io = room_io.RoomIO(room=room, agent_session=self, options=room_options)
tasks.append(asyncio.create_task(self._room_io.start(), name="_room_io_start"))

# session can be restarted, register the callbacks only once
Expand Down
20 changes: 14 additions & 6 deletions livekit-agents/livekit/agents/voice/room_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@
_ParticipantStreamTranscriptionOutput,
_ParticipantTranscriptionOutput,
)
from .room_io import (
DEFAULT_ROOM_INPUT_OPTIONS,
DEFAULT_ROOM_OUTPUT_OPTIONS,
from .room_io import RoomIO
from .types import (
AudioInputOptions,
AudioOutputOptions,
RoomInputOptions,
RoomIO,
RoomOptions,
RoomOutputOptions,
TextInputEvent,
TextInputOptions,
TextOutputOptions,
VideoInputOptions,
)

__all__ = [
"RoomIO",
"DEFAULT_ROOM_INPUT_OPTIONS",
"DEFAULT_ROOM_OUTPUT_OPTIONS",
"RoomOptions",
"RoomInputOptions",
"RoomOutputOptions",
"ATTRIBUTE_PUBLISH_ON_BEHALF",
"TextInputEvent",
"TextInputOptions",
"AudioInputOptions",
"AudioOutputOptions",
"TextOutputOptions",
"VideoInputOptions",
"_ParticipantTranscriptionOutput",
"_ParticipantAudioOutput",
"_ParticipantStreamTranscriptionOutput",
Expand Down
Loading
Loading