Skip to content

Commit 3305128

Browse files
authored
add player queue length to react sdk (#260)
1 parent 472d308 commit 3305128

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

packages/react/src/lib/VoiceProvider.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export type VoiceContextType = {
8080
callDurationTimestamp: string | null;
8181
toolStatusStore: ReturnType<typeof useToolStatus>['store'];
8282
chatMetadata: Hume.empathicVoice.ChatMetadata | null;
83+
playerQueueLength: number;
8384
};
8485

8586
const VoiceContext = createContext<VoiceContextType | null>(null);
@@ -396,6 +397,7 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
396397
callDurationTimestamp,
397398
toolStatusStore: toolStatus.store,
398399
chatMetadata: messageStore.chatMetadata,
400+
playerQueueLength: player.queueLength,
399401
}) satisfies VoiceContextType,
400402
[
401403
connect,
@@ -405,6 +407,7 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
405407
player.isAudioMuted,
406408
player.muteAudio,
407409
player.unmuteAudio,
410+
player.queueLength,
408411
mic.fft,
409412
mic.isMuted,
410413
mic.mute,

packages/react/src/lib/useSoundPlayer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export const useSoundPlayer = (props: {
2323
buffer: AudioBuffer;
2424
}>
2525
>([]);
26+
const [queueLength, setQueueLength] = useState(0);
27+
2628
const isProcessing = useRef(false);
2729
const currentlyPlayingAudioBuffer = useRef<AudioBufferSourceNode | null>(
2830
null,
@@ -36,6 +38,8 @@ export const useSoundPlayer = (props: {
3638
onError.current = props.onError;
3739

3840
const playNextClip = useCallback(() => {
41+
setQueueLength(clipQueue.current.length);
42+
3943
if (analyserNode.current === null || audioContext.current === null) {
4044
onError.current('Audio environment is not initialized');
4145
return;
@@ -227,5 +231,6 @@ export const useSoundPlayer = (props: {
227231
unmuteAudio,
228232
stopAll,
229233
clearQueue,
234+
queueLength,
230235
};
231236
};

0 commit comments

Comments
 (0)