-
Notifications
You must be signed in to change notification settings - Fork 114
Pull audio track from avatar worker in useVoiceAssistant #1130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
246b8c0
b6b466e
bfbffbf
19916dd
4f8fbac
10c2380
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@livekit/components-react": patch | ||
--- | ||
|
||
Pull audio track from avatar worker in useVoiceAssistant |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,29 @@ export type AgentState = | |
* @beta | ||
*/ | ||
export interface VoiceAssistant { | ||
/** | ||
* The agent participant. | ||
*/ | ||
agent: RemoteParticipant | undefined; | ||
/** | ||
* The current state of the agent. | ||
*/ | ||
state: AgentState; | ||
/** | ||
* The microphone track published by the agent or associated avatar worker (if any). | ||
*/ | ||
audioTrack: TrackReference | undefined; | ||
/** | ||
* The camera track published by the agent or associated avatar worker (if any). | ||
*/ | ||
videoTrack: TrackReference | undefined; | ||
/** | ||
* The transcriptions of the agent's microphone track (if any). | ||
*/ | ||
agentTranscriptions: ReceivedTranscriptionSegment[]; | ||
/** | ||
* The agent's participant attributes. | ||
*/ | ||
agentAttributes: RemoteParticipant['attributes'] | undefined; | ||
} | ||
|
||
|
@@ -42,8 +61,28 @@ const state_attribute = 'lk.agent.state'; | |
* @beta | ||
*/ | ||
export function useVoiceAssistant(): VoiceAssistant { | ||
const agent = useRemoteParticipants().find((p) => p.kind === ParticipantKind.AGENT); | ||
const audioTrack = useParticipantTracks([Track.Source.Microphone], agent?.identity)[0]; | ||
const remoteParticipants = useRemoteParticipants(); | ||
const agent = remoteParticipants.find( | ||
(p) => p.kind === ParticipantKind.AGENT && !('lk.publish_on_behalf' in p.attributes), | ||
); | ||
const worker = remoteParticipants.find( | ||
(p) => | ||
p.kind === ParticipantKind.AGENT && p.attributes['lk.publish_on_behalf'] === agent?.identity, | ||
); | ||
const agentTracks = useParticipantTracks( | ||
[Track.Source.Microphone, Track.Source.Camera], | ||
agent?.identity, | ||
); | ||
const workerTracks = useParticipantTracks( | ||
[Track.Source.Microphone, Track.Source.Camera], | ||
worker?.identity, | ||
); | ||
const audioTrack = | ||
agentTracks.find((t) => t.source === Track.Source.Microphone) ?? | ||
workerTracks.find((t) => t.source === Track.Source.Microphone); | ||
const videoTrack = | ||
agentTracks.find((t) => t.source === Track.Source.Camera) ?? | ||
workerTracks.find((t) => t.source === Track.Source.Camera); | ||
const { segments: agentTranscriptions } = useTrackTranscription(audioTrack); | ||
const connectionState = useConnectionState(); | ||
const { attributes } = useParticipantAttributes({ participant: agent }); | ||
|
@@ -66,6 +105,7 @@ export function useVoiceAssistant(): VoiceAssistant { | |
agent, | ||
state, | ||
audioTrack, | ||
videoTrack, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't we simply want to return all tracks that the agent publishes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah i don't have a strong opinion really. this seemed least disruptive and i think if you really want all the tracks you can get them from |
||
agentTranscriptions, | ||
agentAttributes: attributes, | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where are we documenting these attributes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably need a full reference of special attributes but for now this is going into the avatar integration docs https://github.com/livekit/web/pull/1165/files#diff-42c10a5d6ec7f1e0d9ade709732ba1d4c3697b6d411523ecdc5a2ac75a9457efR46