Skip to content

Commit

Permalink
Adds code to have better control over the agent. Now, you can pause s…
Browse files Browse the repository at this point in the history
…o you won't get interrupted while talking to other channel members, resume functionality, and set the participant the agent should actively listen to.
  • Loading branch information
Chris Wilson committed Nov 21, 2024
1 parent 70b4e87 commit 3a9ac19
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions livekit-agents/livekit/agents/multimodal/multimodal_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,25 @@ def _on_playout_stopped(interrupted: bool) -> None:
for f in bstream.write(frame.data.tobytes()):
self._session.input_audio_buffer.append(f)

def set_source_participant(self, participant_identity: str) -> None:
"""Set the source participant for the agent."""
self._link_participant(participant_identity)

def pause_listening(self) -> None:
"""Pause listening to the audio stream."""
if self._read_micro_atask is not None:
self._read_micro_atask.cancel() # Stop the current task
self._read_micro_atask = None
logger.info("Paused listening to the audio stream.")

def resume_listening(self) -> None:
"""Resume listening to the audio stream."""
if self._subscribed_track is not None and self._read_micro_atask is None:
self._read_micro_atask = asyncio.create_task(
self._micro_task(self._subscribed_track) # Restart the task
)
logger.info("Resumed listening to the audio stream.")

def _on_participant_connected(self, participant: rtc.RemoteParticipant):
if self._linked_participant is None:
return
Expand Down

0 comments on commit 3a9ac19

Please sign in to comment.