From 2a0731abde0fca438d813337d76ea918ab34a954 Mon Sep 17 00:00:00 2001 From: Yini Shi Date: Mon, 18 Nov 2024 11:51:33 -0500 Subject: [PATCH 1/2] onAudioReceived callback --- packages/embed-react/package.json | 2 +- packages/embed/package.json | 2 +- packages/react/package.json | 2 +- packages/react/src/lib/VoiceProvider.tsx | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/embed-react/package.json b/packages/embed-react/package.json index 87dc1f4..6b33e54 100644 --- a/packages/embed-react/package.json +++ b/packages/embed-react/package.json @@ -1,6 +1,6 @@ { "name": "@humeai/voice-embed-react", - "version": "0.1.19-beta.1", + "version": "0.1.19-beta.2", "description": "", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/packages/embed/package.json b/packages/embed/package.json index 64f3a66..178b40d 100644 --- a/packages/embed/package.json +++ b/packages/embed/package.json @@ -1,6 +1,6 @@ { "name": "@humeai/voice-embed", - "version": "0.1.19-beta.1", + "version": "0.1.19-beta.2", "description": "", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/packages/react/package.json b/packages/react/package.json index c9cdca0..cdca86d 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@humeai/voice-react", - "version": "0.1.19-beta.1", + "version": "0.1.19-beta.2", "description": "", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/packages/react/src/lib/VoiceProvider.tsx b/packages/react/src/lib/VoiceProvider.tsx index dcb882b..e92962b 100644 --- a/packages/react/src/lib/VoiceProvider.tsx +++ b/packages/react/src/lib/VoiceProvider.tsx @@ -98,6 +98,7 @@ export type VoiceProviderProps = PropsWithChildren & { onOpen?: () => void; onClose?: Hume.empathicVoice.chat.ChatSocket.EventHandlers['close']; onToolCall?: ToolCallHandler; + onAudioReceived?: (audioOutputMessage: AudioOutputMessage) => void; onAudioStart?: (clipId: string) => void; onAudioEnd?: (clipId: string) => void; onInterruption?: ( @@ -159,6 +160,9 @@ export const VoiceProvider: FC = ({ const onMessage = useRef(props.onMessage ?? noop); onMessage.current = props.onMessage ?? noop; + const onAudioReceived = useRef(props.onAudioReceived ?? noop); + onAudioReceived.current = props.onAudioReceived ?? noop; + const onAudioStart = useRef(props.onAudioStart ?? noop); onAudioStart.current = props.onAudioStart ?? noop; @@ -212,6 +216,7 @@ export const VoiceProvider: FC = ({ const client = useVoiceClient({ onAudioMessage: (message: AudioOutputMessage) => { player.addToQueue(message); + onAudioReceived.current(message); }, onMessage: useCallback( (message: JSONMessage) => { From 9ba3a45882c5b6b8478f25c8255a4367a6d3ef99 Mon Sep 17 00:00:00 2001 From: Yini Shi Date: Mon, 18 Nov 2024 11:52:32 -0500 Subject: [PATCH 2/2] readme --- packages/react/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/react/README.md b/packages/react/README.md index 899fc4d..a328133 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -107,6 +107,10 @@ See a complete list of props accepted by `VoiceProvider` below: (_Optional_) Callback function to invoke upon receiving a ToolCallMessage through the web socket. It will send the string returned as a the content of a ToolResponseMessage. This is where you should add logic that handles your custom tool calls. +#### `onAudioReceived?`: (message: AudioOutputMessage) => void + +(_Optional_) Callback function to invoke when an audio output message is received from the websocket. + #### `onAudioStart?`: (clipId: string) => void (_Optional_) Callback function to invoke when an audio clip from the assistant starts playing.