### Install Dependencies with pnpm Source: https://github.com/humeai/hume-react-sdk/blob/main/README.md Run these commands to install all necessary dependencies for local development using pnpm. This command installs packages for the SDK and example applications. ```bash pnpm install ``` ```bash pnpm dev ``` -------------------------------- ### Install @humeai/voice-embed-react Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/embed-react/README.md Add the voice-embed-react package to your project using npm. ```bash npm install @humeai/voice-embed-react ``` -------------------------------- ### Run Development Server Source: https://github.com/humeai/hume-react-sdk/blob/main/examples/next-app/README.md Use these commands to start the Next.js development server. Open http://localhost:3000 to view the result. ```bash npm run dev # or yarn dev # or pnpm dev # or bun dev ``` -------------------------------- ### Install @humeai/voice-embed Package Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/embed/README.md Add the @humeai/voice-embed package to your project using npm. This makes it available for import in your application. ```bash npm install @humeai/voice-embed ``` -------------------------------- ### Install @humeai/voice-react Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Add the @humeai/voice-react package to your project using npm. This command downloads and includes the package, making it available for import in your React components. ```bash npm install @humeai/voice-react ``` -------------------------------- ### Start a Call with VoiceProvider Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Use the `useVoice` hook within a component child of `VoiceProvider` to access the `connect` method. Ensure `connect` is called in response to a user gesture, like a button click, due to AudioContext API autoplay policies. ```tsx 'use client'; import { useVoice } from '@humeai/voice-react'; export function StartCall({ accessToken }: { accessToken: string }) { const { connect } = useVoice(); return ( <> ); } ``` -------------------------------- ### Wrap Components with VoiceProvider Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Use the VoiceProvider component to wrap your application's components. This enables them to access the voice methods provided by the SDK. This is a basic setup for integrating the SDK. ```tsx import { VoiceProvider } from '@humeai/voice-react'; function Page() { return {/* ... */}; } ``` -------------------------------- ### Connecting to EVI Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md This snippet demonstrates how to initiate a connection to the EVI using the `connect` method from the `useVoice` hook. It highlights the importance of user gestures for initializing the AudioContext API. ```APIDOC ## POST /connect ### Description Opens a socket connection to the voice API and initializes the microphone. This method must be called in response to a user gesture due to AudioContext API autoplay policies. ### Method POST ### Endpoint /connect ### Parameters #### Request Body - **auth** (object) - Required - Authentication details. - **type** (string) - Required - Type of authentication ('accessToken'). - **value** (string) - Required - The access token. - **configId** (string) - Required - The configuration ID for the EVI. - **options** (object) - Optional - Additional connection options. ### Request Example ```json { "auth": { "type": "accessToken", "value": "YOUR_ACCESS_TOKEN" }, "configId": "YOUR_CONFIG_ID" } ``` ### Response #### Success Response (200) - **message** (string) - Indicates a successful connection. #### Response Example ```json { "message": "Connected successfully" } ``` ``` -------------------------------- ### Migrate useVoice() to Granular Hooks Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/MIGRATION.md Before migration: uses useVoice() to access fft, micFft, and callDurationTimestamp. After migration: uses dedicated hooks usePlayerFft(), useMicFft(), and useCallDurationTimestamp() for granular updates and performance. ```tsx import { useVoice } from '@humeai/voice-react'; function Waveform() { const { fft, micFft, callDurationTimestamp } = useVoice(); return ( <> {callDurationTimestamp ?? '0:00'} ); } ``` ```tsx import { useVoice, usePlayerFft, useMicFft, useCallDurationTimestamp, } from '@humeai/voice-react'; function Waveform() { const fft = usePlayerFft(); const micFft = useMicFft(); const callDurationTimestamp = useCallDurationTimestamp(); return ( <> {callDurationTimestamp ?? '0:00'} ); } ``` -------------------------------- ### Use Player FFT Hook Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Returns live FFT values for assistant audio output. Use this hook to render visualizations based on audio data. ```tsx import { usePlayerFft } from '@humeai/voice-react'; function Waveform() { const fft = usePlayerFft(); // render visualization using fft values } ``` -------------------------------- ### Voice SDK Methods Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Reference for the available methods to control the voice connection and interaction. ```APIDOC ## Voice SDK Methods ### `disconnect` #### Description Disconnects from the voice API and microphone. #### Method POST #### Endpoint /disconnect ### `clearMessages` #### Description Clears transcript messages from history. #### Method POST #### Endpoint /clearMessages ### `mute` #### Description Mutes the microphone. #### Method POST #### Endpoint /mute ### `unmute` #### Description Unmutes the microphone. #### Method POST #### Endpoint /unmute ### `muteAudio` #### Description Mutes the assistant audio output. #### Method POST #### Endpoint /muteAudio ### `unmuteAudio` #### Description Unmutes the assistant audio output. #### Method POST #### Endpoint /unmuteAudio ### `setVolume` #### Description Sets the playback volume for the assistant's audio. Values are clamped between 0.0 (silent) and 1.0 (full volume). #### Method POST #### Endpoint /setVolume #### Parameters ##### Request Body - **level** (number) - Required - The desired volume level (0.0 to 1.0). ### `sendSessionSettings` #### Description Sends new session settings to the assistant, overriding `VoiceProvider` props. #### Method POST #### Endpoint /sendSessionSettings #### Parameters ##### Request Body - **message** (SessionSettings) - Required - The session settings object. ### `sendUserInput` #### Description Sends a user input text message to the assistant. #### Method POST #### Endpoint /sendUserInput #### Parameters ##### Request Body - **text** (string) - Required - The user's input text. ### `sendAssistantInput` #### Description Sends a text string for the assistant to read aloud. #### Method POST #### Endpoint /sendAssistantInput #### Parameters ##### Request Body - **text** (string) - Required - The text for the assistant to speak. ### `sendToolMessage` #### Description Sends a tool response or tool error message to the EVI backend. #### Method POST #### Endpoint /sendToolMessage #### Parameters ##### Request Body - **toolMessage** (ToolResponse | ToolError) - Required - The tool message or error object. ### `pauseAssistant` #### Description Pauses responses from EVI. Chat history is still saved and sent after resuming. #### Method POST #### Endpoint /pauseAssistant ### `resumeAssistant` #### Description Resumes responses from EVI. Chat history sent while paused will now be sent. #### Method POST #### Endpoint /resumeAssistant ``` -------------------------------- ### Import VoiceProvider Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Import the VoiceProvider component from the @humeai/voice-react package. This is the first step to integrating the SDK into your application. ```tsx import { VoiceProvider } from '@humeai/voice-react'; ``` -------------------------------- ### Verify Node.js Version Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/embed-react/README.md Check your current Node.js version to ensure it meets the minimum requirement of v18.0.0. ```bash node --version ``` -------------------------------- ### Granular Hooks Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md These hooks subscribe directly to high-frequency data via `useSyncExternalStore`, bypassing the main `VoiceContext`. Use them instead of the deprecated `useVoice()` properties for FFT and call duration data. ```APIDOC ## Granular Hooks ### Description These hooks subscribe directly to high-frequency data via `useSyncExternalStore`, bypassing the main `VoiceContext`. Use them instead of the deprecated `useVoice()` properties for FFT and call duration data. ### `usePlayerFft()` #### Returns - `readonly number[]`: Live FFT values for the assistant audio output, updated at display refresh rate (~60Hz). #### Example ```tsx import { usePlayerFft } from '@humeai/voice-react'; function Waveform() { const fft = usePlayerFft(); // render visualization using fft values } ``` ### `useMicFft()` #### Returns - `readonly number[]`: Live FFT values for microphone input, updated at display refresh rate (~60Hz). #### Example ```tsx import { useMicFft } from '@humeai/voice-react'; function MicWaveform() { const micFft = useMicFft(); // render visualization using micFft values } ``` ### `useCallDurationTimestamp()` #### Returns - `string | null`: The formatted call duration timestamp, updated ~1Hz during an active call. #### Example ```tsx import { useCallDurationTimestamp } from '@humeai/voice-react'; function CallTimer() { const timestamp = useCallDurationTimestamp(); return {timestamp ?? '0:00'}; } ``` ``` -------------------------------- ### ConnectOptions Type Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Defines the configuration options for establishing a WebSocket connection to the Hume Voice API. Authentication is mandatory. ```APIDOC ## `ConnectOptions` Type Definition ### Description This type defines the configuration options required to establish a WebSocket connection with Hume's Voice API. It includes settings for authentication, API host, configuration IDs, transcription verbosity, resumed chat groups, audio constraints, session settings, and device selection. ### Fields - **auth** (AuthStrategy) - Required - Authentication strategy and corresponding value. Authentication is required to establish the web socket connection with Hume's Voice API. See our [documentation](https://dev.hume.ai/docs/quick-start#getting-your-api-key) on obtaining your `API key` or `access token`. - **hostname** (string) - Optional - Hostname of the Hume API. If not provided this value will default to `"api.hume.ai"`. - **configId** (string) - Optional - If you have a configuration ID with voice presets, pass the config ID here. - **configVersion** (string) - Optional - If you wish to use a specific version of your config, pass in the version ID here. - **verboseTranscription** (boolean) - Optional - A flag to enable verbose transcription. When `true`, unfinalized user transcripts are sent to the client as interim UserMessage messages, which makes the assistant more sensitive to interruptions. Defaults to `true`. - **resumedChatGroupId** (string) - Optional - Include a chat group ID, which enables the chat to continue from a previous chat group. - **audioConstraints** (AudioConstraints) - Optional - Custom audio constraints passed to navigator.getUserMedia to get the microphone stream. - **sessionSettings** (Hume.empathicVoice.SessionSettings) - Optional - Session settings to be sent immediately once the connection to EVI is established. See documentation for details: https://dev.hume.ai/docs/empathic-voice-interface-evi/configuration/session-settings - **devices** (DeviceOptions) - Optional - Device IDs for microphone and speaker selection. ``` -------------------------------- ### Use Mic FFT Hook Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Returns live FFT values for microphone input. This hook is useful for creating real-time visualizations of microphone activity. ```tsx import { useMicFft } from '@humeai/voice-react'; function MicWaveform() { const micFft = useMicFft(); // render visualization using micFft values } ``` -------------------------------- ### DeviceOptions Type Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Specifies the device IDs for microphone and speaker selection. ```APIDOC ## `DeviceOptions` Type Definition ### Description This type allows for the explicit selection of audio input (microphone) and audio output (speaker) devices by their respective IDs. If not specified, the system's default devices will be used. ### Fields - **microphoneDeviceId** (string) - Optional - Device ID of the microphone/audio input to use. Uses the default microphone if not specified. - **speakerDeviceId** (string) - Optional - Device ID of the speaker/audio output to use for playback. Uses the default audio output if not specified. ``` -------------------------------- ### Voice SDK Properties Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Reference for the properties that provide the current state of the voice connection. ```APIDOC ## Voice SDK Properties ### `isMuted` #### Description Boolean that indicates whether the microphone is currently muted. #### Type boolean ### `isAudioMuted` #### Description Boolean that indicates whether the assistant's audio output is currently muted. #### Type boolean ### `volume` #### Description The current playback volume level for the assistant's voice, ranging from 0.0 (silent) to 1.0 (full volume). Defaults to 1.0. #### Type number ### `isPlaying` #### Description Boolean that indicates whether the assistant's audio is currently playing. #### Type boolean ### `isPaused` #### Description Boolean that indicates whether the assistant is currently paused. When paused, the assistant still listens but does not send responses until resumed. #### Type boolean ``` -------------------------------- ### VoiceProvider Configuration Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md The VoiceProvider component enables access to voice methods and can be configured with various optional props to customize its behavior. ```APIDOC ## VoiceProvider Configuration ### Description The `VoiceProvider` component is essential for integrating Hume's Empathic Voice Interface into your React application. It manages the WebSocket connection, microphone input, audio playback, and message history. You can customize its behavior using the following optional props. ### Props #### `enableAudioWorklet` (boolean) - Optional - A flag to toggle the audio player implementation between AudioWorklet and AudioBuffer. AudioWorklet is recommended for best audio quality results on most browsers, but has degraded performance on Safari 17. Defaults to `true`. #### `onMessage` ((message: JsonMessage & { receivedAt: Date;}) => void) - Optional - Callback function to invoke upon receiving a message through the web socket. #### `onToolCall` (ToolCallHandler) - 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. #### `onAudioEnd` ((clipId: string) => void) - Optional - Callback function to invoke when an audio clip from the assistant stops playing. #### `onInterruption` ((clipId: string) => void) - Optional - Callback function to invoke when the assistant is interrupted. #### `onClose` ((event: CloseEvent) => void) - Optional - Callback function to invoke upon the web socket connection being closed. #### `clearMessagesOnDisconnect` (boolean) - Optional - Boolean which indicates whether you want to clear message history when the call ends. #### `messageHistoryLimit` (number) - Optional - Set the number of messages that you wish to keep over the course of the conversation. The default value is 100. ### Usage Example ```tsx import { VoiceProvider } from '@humeai/voice-react'; function App() { return ( console.log('Message received:', message)} onToolCall={(toolCall) => console.log('Tool call received:', toolCall)} onAudioReceived={(audio) => console.log('Audio received:', audio)} onAudioStart={(clipId) => console.log('Audio started:', clipId)} onAudioEnd={(clipId) => console.log('Audio ended:', clipId)} onInterruption={(clipId) => console.log('Interruption:', clipId)} onClose={(event) => console.log('Connection closed:', event)} clearMessagesOnDisconnect={false} messageHistoryLimit={50} > {/* Your application components */} ); } export default App; ``` ``` -------------------------------- ### Create EmbeddedVoice Instance Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/embed/README.md Instantiate the EmbeddedVoice component with configuration options. For server components in Next.js, ensure this is done within a client component. ```tsx import { type CloseHandler, EmbeddedVoice as EA, type EmbeddedVoiceConfig, type TranscriptMessageHandler, } from '@humeai/voice-embed'; const embeddedVoice = EA.create({ // Configuration options }); ``` -------------------------------- ### Configure ESLint for Type Aware Lint Rules Source: https://github.com/humeai/hume-react-sdk/blob/main/examples/vite-app-embed/README.md Update the ESLint configuration to enable type-aware lint rules for production applications. Ensure `tsconfig.json` and `tsconfig.node.json` are included in `parserOptions.project`. ```javascript export default { // other rules... parserOptions: { ecmaVersion: 'latest', sourceType: 'module', project: ['./tsconfig.json', './tsconfig.node.json'], tsconfigRootDir: __dirname, }, }; ``` -------------------------------- ### Embedded Voice Widget Configuration Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/embed/README.md Configuration options for the embedded voice widget, including props accepted by VoiceProvider and widget-specific settings. ```APIDOC ## Embedded Voice Widget Configuration ### Description Configuration options for the embedded voice widget. This includes all props accepted by the `VoiceProvider` from the `@humeai/voice-react` package, plus additional widget-specific configurations. ### Parameters #### Widget Specific Options - **`isEmbedOpen`** (boolean) - Required - Determines the initial visibility of the widget. `true` renders the widget open on initial load, `false` starts with the widget closed. Enables external control over the widget's visibility. - **`rendererUrl`** (string) - Optional - URL where the widget itself is hosted. Defaults to `https://voice-widget.hume.ai` if blank. - **`onMessage`** (function) - Optional - Callback function invoked upon receiving a message through the web socket. - **`onClose`** (function) - Optional - Callback function invoked upon the web socket connection being closed. - **`openOnMount`** (boolean) - Optional - Indicates whether the widget should be initialized in an open or closed state. Defaults to `false`. ``` -------------------------------- ### Voice Provider State and Data Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md These properties provide access to the current state and data of the voice connection, including message history, last messages, connection status, and error information. ```APIDOC ## Voice Provider State and Data ### Description Provides access to the current state and data of the voice connection, including message history, last messages, connection status, and error information. ### Properties - **`messages`**: (Array) Message history of the current conversation. By default, `messages` does not include interim user messages when `verboseTranscription` is set to true on the `VoiceProvider` (`verboseTranscription` is true by default). To access interim messages, you can define a custom `onMessage` callback on your `VoiceProvider`. - **`lastVoiceMessage`**: ([AssistantTranscriptMessage](https://github.com/HumeAI/hume-typescript-sdk/blob/ac89e41e45a925f9861eb6d5a1335ab51d5a1c94/src/api/resources/empathicVoice/types/AssistantMessage.ts) | null) The last transcript message received from the assistant. - **`lastUserMessage`**: ([UserTranscriptMessage](https://github.com/HumeAI/hume-typescript-sdk/blob/ac89e41e45a925f9861eb6d5a1335ab51d5a1c94/src/api/resources/empathicVoice/types/UserMessage.ts) | null) The last transcript message received from the user. - **`readyState`**: ([VoiceReadyState](https://github.com/HumeAI/empathic-voice-api-js/blob/8a4f9b87870c68650cde73a818edd093716c59fd/packages/react/src/lib/useVoiceClient.ts#L21)) The current readyState of the websocket connection. - **`status`**: ([VoiceStatus](https://github.com/HumeAI/empathic-voice-api-js/blob/8a4f9b87870c68650cde73a818edd093716c59fd/packages/react/src/lib/VoiceProvider.tsx#L41)) The current status of the voice connection. Informs you of whether the voice is connected, disconnected, connecting, or error. If the voice is in an error state, it will automatically disconnect from the websocket and microphone. - **`error`**: ([VoiceError](https://github.com/HumeAI/empathic-voice-api-js/blob/8a4f9b87870c68650cde73a818edd093716c59fd/packages/react/src/lib/VoiceProvider.tsx#L36)) Provides more detailed error information if the voice is in an error state. - **`isError`**: (boolean) If true, the voice is in an error state. - **`isAudioError`**: (boolean) If true, an audio playback error has occurred. - **`isMicrophoneError`**: (boolean) If true, a microphone error has occurred. - **`isSocketError`**: (boolean) If true, there was an error connecting to the websocket. - **`toolStatusStore`**: (Record) A map of tool call IDs to their associated tool messages. - **`chatMetadata`**: ([ChatMetadataMessage](https://github.com/HumeAI/hume-typescript-sdk/blob/ac89e41e45a925f9861eb6d5a1335ab51d5a1c94/src/api/resources/empathicVoice/types/ChatMetadata.ts) | null) Metadata about the current chat, including chat ID, chat group ID, and request ID. - **`playerQueueLength`**: (number) The number of assistant audio clips that are queued up, including the clip that is currently playing. ``` -------------------------------- ### Import EmbeddedVoice Component Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/embed/README.md Import the EmbeddedVoice component from the @humeai/voice-embed package into your React application. ```tsx import { EmbeddedVoice } from '@humeai/voice-embed'; ``` -------------------------------- ### Import EmbeddedVoice Component Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/embed-react/README.md Import the EmbeddedVoice component from the @humeai/voice-embed-react package into your React application. ```tsx import { EmbeddedVoice } from '@humeai/voice-embed-react'; ``` -------------------------------- ### Basic EmbeddedVoice Usage Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/embed-react/README.md Integrate the EmbeddedVoice component into your React app. Configure authentication with an API key and handle messages and close events. For server components, instantiate EmbeddedVoice within a client component. ```tsx import React, { useState } from 'react'; import { EmbeddedVoice } from '@humeai/voice-embed-react'; function App() { const apiKey = process.env.HUME_API_KEY || ''; const [isEmbedOpen, setIsEmbedOpen] = useState(false); return (
console.log('Message received: ', msg)} onClose={() => setIsEmbedOpen(false)} isEmbedOpen={isEmbedOpen} />
); } ``` -------------------------------- ### AudioConstraints Type Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Defines constraints for audio input, such as echo cancellation and noise suppression. ```APIDOC ## `AudioConstraints` Type Definition ### Description This type defines constraints that can be applied to the audio input stream obtained via `navigator.getUserMedia`. These settings help optimize audio quality by managing echo, noise, and gain. ### Fields - **echoCancellation** (boolean) - Optional - Reduce echo from the input (if supported). Defaults to `true`. - **noiseSuppression** (boolean) - Optional - Suppress background noise (if supported). Defaults to `true`. - **autoGainControl** (boolean) - Optional - Automatically adjust microphone gain (if supported). Defaults to `true`. ``` -------------------------------- ### Use Call Duration Timestamp Hook Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/react/README.md Returns the formatted call duration timestamp, updated approximately once per second during an active call. Displays the current call length. ```tsx import { useCallDurationTimestamp } from '@humeai/voice-react'; function CallTimer() { const timestamp = useCallDurationTimestamp(); return {timestamp ?? '0:00'}; } ``` -------------------------------- ### EmbeddedVoice Component Props Source: https://github.com/humeai/hume-react-sdk/blob/main/packages/embed-react/README.md The EmbeddedVoice component accepts props from VoiceProvider and additional props for widget configuration. ```APIDOC ## EmbeddedVoice Component Props ### Description The `EmbeddedVoice` component in the Hume React SDK allows for the integration of a voice widget. It accepts all props compatible with the `VoiceProvider` from the [@humeai/voice-react package](https://github.com/HumeAI/empathic-voice-api-js/blob/main/packages/react), along with specific props for customizing the widget's behavior and appearance. ### Props #### Inherited Props `EmbeddedVoice` accepts all props that are accepted by the `VoiceProvider` in the [@humeai/voice-react package](https://github.com/HumeAI/empathic-voice-api-js/blob/main/packages/react). #### Component-Specific Props - **`isEmbedOpen`** (boolean) - Required - Determines the initial visibility of the widget. `true` renders the widget open on initial load, `false` starts with the widget closed. This prop also enables external control over the widget's visibility state. - **`rendererUrl`** (string) - Optional - URL where the widget itself is hosted. Defaults to `https://voice-widget.hume.ai`. - **`onMessage`** (function) - Optional - Callback function invoked upon receiving a message through the web socket. - **`onClose`** (function) - Optional - Callback function invoked upon the web socket connection being closed. - **`openOnMount`** (boolean) - Optional - Indicates whether the widget should be initialized in an open or closed state. Defaults to `false`. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.