Skip to main content

Primary Hook

useVoice

The main hook for voice interactions, providing comprehensive access to all voice functionality.

Returns

function
Establishes voice connection
function
Closes voice connection and cleans up resources
string
Current connection state: 'disconnected', 'connecting', 'connected', or 'error'
VoiceMessage[]
Array of conversation messages (user and assistant)
boolean
Whether microphone is actively capturing audio
boolean
Whether text-to-speech audio is currently playing
boolean
Whether waiting for AI assistant response
ConnectionMetadata
Connection information including session ID, timestamps
NextEVIError | null
Current error state, if any
function
Clears all conversation messages
function
Send text message to assistant (for testing/debugging)

Specialized Hooks

useVoiceStatus

Get detailed connection status information:
string
Current connection state
NextEVIError | null
Current error, if any
ConnectionMetadata
Connection details and session information
boolean
Computed boolean: readyState === 'connected'
boolean
Computed boolean: readyState === 'connecting'
boolean
Computed boolean: readyState === 'disconnected'
boolean
Computed boolean: error !== null

useVoiceMessages

Manage conversation messages with enhanced utilities:
VoiceMessage[]
All conversation messages
VoiceMessage[]
Filtered array of user messages only
VoiceMessage[]
Filtered array of assistant messages only
VoiceMessage[]
Filtered array of system messages
VoiceMessage[]
Filtered array of error messages
VoiceMessage | null
Most recent message in conversation
boolean
Whether any messages are currently streaming
number
Total number of messages
number
Total character count of all messages

useVoiceAudio

Monitor audio activity and states:
boolean
Whether microphone is capturing audio
boolean
Whether TTS audio is playing
boolean
Whether any audio activity is happening (recording or playing)

useSimpleVoice

Simplified connection API for basic use cases:
function
Simplified connect method taking individual parameters
function
Disconnect from voice session
string
Connection state
VoiceMessage[]
Conversation messages

Advanced Hooks

useVoiceIdleTimeout

Monitor and configure idle timeout behavior:
number
Seconds remaining until idle timeout
boolean
Whether idle warning period is active
function
Reset the idle timeout counter
function
Configure timeout settings

useVoiceTurnDetection

Access turn detection and conversation flow data:
boolean
Whether it’s currently the user’s turn to speak
boolean
Whether it’s currently the assistant’s turn to speak
number
Duration of current turn in milliseconds
number
Duration of current silence in milliseconds
number
Timestamp of last turn change

useVoiceDebug

Development and debugging utilities:
object
Current debug information and internal state
object
WebSocket connection statistics and performance metrics
object
Audio processing statistics and quality metrics
object[]
Raw WebSocket message history for debugging
function
Export debug logs for analysis

Type Definitions

VoiceMessage

NextEVIConfig

AudioConfig

ConnectionMetadata

Best Practices

  • Use useVoice for most applications - it provides everything you need
  • Use specialized hooks (useVoiceStatus, useVoiceMessages, etc.) when you need specific functionality
  • Use useSimpleVoice for quick prototypes or simple integrations
  • Use useVoiceDebug only in development environments
  • Always handle connection errors in your UI
  • Monitor the error state from hooks
  • Implement retry logic for network issues
  • Validate configuration before connecting
  • Use React.memo for message components to prevent unnecessary re-renders
  • Implement virtual scrolling for long conversation histories
  • Clean up connections when components unmount
  • Use useVoiceAudio to show loading states during audio activity
  • Show clear connection status to users
  • Provide visual feedback for audio activity (recording/playing)
  • Handle microphone permissions gracefully
  • Implement idle timeout warnings

Examples

Basic Voice Chat

Status Monitor