Skip to content
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

add onAudioReceived callback to VoiceProvider #287

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading