Skip to content

Commit

Permalink
add onAudioReceived callback to VoiceProvider (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
yinishi authored Nov 18, 2024
1 parent f9ae462 commit 083121f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/embed-react/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/embed/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/lib/VoiceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export type VoiceProviderProps = PropsWithChildren<SocketConfig> & {
onOpen?: () => void;
onClose?: Hume.empathicVoice.chat.ChatSocket.EventHandlers['close'];
onToolCall?: ToolCallHandler;
onAudioReceived?: (audioOutputMessage: AudioOutputMessage) => void;
onAudioStart?: (clipId: string) => void;
onAudioEnd?: (clipId: string) => void;
onInterruption?: (
Expand Down Expand Up @@ -159,6 +160,9 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
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;

Expand Down Expand Up @@ -212,6 +216,7 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
const client = useVoiceClient({
onAudioMessage: (message: AudioOutputMessage) => {
player.addToQueue(message);
onAudioReceived.current(message);
},
onMessage: useCallback(
(message: JSONMessage) => {
Expand Down

0 comments on commit 083121f

Please sign in to comment.