Skip to main content

Basic Voice Chat Component

Here’s a complete example of a React component that creates a voice conversation using the useConversation hook:
Want to use a different voice? See all available voices you can choose from.

Connection Management

onDisconnect Callback

Use onDisconnect to handle cleanup when the conversation ends:
Important: Use onDisconnect for cleanup logic, not onError. The onError callback is called for runtime errors as well, so it’s not ideal for cleanup tasks.

onError Callback

Use onError specifically for handling errors:

Advanced Features

Event Handling

You can listen to various events during the conversation:

Text Input

You can also send text messages programmatically:

Mute Control

Control the microphone state by passing micMuted prop to useConversation:

Volume Control

Control the AI’s voice volume by passing volume prop to useConversation (value between 0 and 1):

Complete Example with Error Handling

Here’s a more complete example showing proper error and disconnect handling:

Next Steps