Hi everyone, I’m working on a LiveKit application...
# agents
p
Hi everyone, I’m working on a LiveKit application with an Electron frontend that publishes two audio tracks: the user’s microphone and the system audio. Up until now I only had the microphone track, and I was processing input audio in the
on_user_turn_completed
callback using the STT node wrapper—everything worked perfectly. Now I want to handle both tracks in the same callback, but differentiate them so I can prefix each user turn with an identifier (e.g. “MICROPHONE” or “SYSTEM_AUDIO”). On the subscriber side, I’m listening for the
track_subscribed
event and I can ensure that both tracks are received:
Copy code
def on_track_subscribed(
    track: rtc.RemoteTrack,
    publication: rtc.RemoteTrackPublication,
    participant: rtc.RemoteParticipant
):
    if track.kind != rtc.TrackKind.KIND_AUDIO:
        return

    print(f"DEBUG: Track: {track}, Publication: {publication}, Participant: {participant}")

    if publication.source == rtc.TrackSource.SOURCE_MICROPHONE:
        speaker = "MICROPHONE"
    elif publication.source == rtc.TrackSource.SOURCE_SCREENSHARE:
        speaker = "SYSTEM_AUDIO"
    else:
        speaker = participant.identity

    print(f"DEBUG: Speaker: {speaker}, Source: {publication.source}")
My question: what’s the most straightforward way to identify each track’s source inside the
on_user_turn_completed
callback? Any pointers or examples would be hugely appreciated! Thanks in advance!
@jolly-air-155 could you help please?
j
one agent session can only listen to one track, you will need to create multiple RoomIO and agent sessions to process different tracks. here is a related example https://github.com/livekit/agents/blob/livekit-agents@1.2.3/examples/other/transcription/multi-user-transcriber.py also, right now the RoomIO doesn’t support audio track from screen sharing, here is a related pr https://github.com/livekit/agents/pull/3098 to enable it