Primary Hook
useVoice
The main hook for voice interactions, providing comprehensive access to all voice functionality.
Returns
Establishes voice connection
Closes voice connection and cleans up resources
Current connection state:
'disconnected', 'connecting', 'connected', or 'error'Array of conversation messages (user and assistant)
Whether microphone is actively capturing audio
Whether text-to-speech audio is currently playing
Whether waiting for AI assistant response
Connection information including session ID, timestamps
Current error state, if any
Clears all conversation messages
Send text message to assistant (for testing/debugging)
Specialized Hooks
useVoiceStatus
Get detailed connection status information:
Current connection state
Current error, if any
Connection details and session information
Computed boolean:
readyState === 'connected'Computed boolean:
readyState === 'connecting'Computed boolean:
readyState === 'disconnected'Computed boolean:
error !== nulluseVoiceMessages
Manage conversation messages with enhanced utilities:
All conversation messages
Filtered array of user messages only
Filtered array of assistant messages only
Filtered array of system messages
Filtered array of error messages
Most recent message in conversation
Whether any messages are currently streaming
Total number of messages
Total character count of all messages
useVoiceAudio
Monitor audio activity and states:
Whether microphone is capturing audio
Whether TTS audio is playing
Whether any audio activity is happening (recording or playing)
useSimpleVoice
Simplified connection API for basic use cases:
Simplified connect method taking individual parameters
Disconnect from voice session
Connection state
Conversation messages
Advanced Hooks
useVoiceIdleTimeout
Monitor and configure idle timeout behavior:
Seconds remaining until idle timeout
Whether idle warning period is active
Reset the idle timeout counter
Configure timeout settings
useVoiceTurnDetection
Access turn detection and conversation flow data:
Whether it’s currently the user’s turn to speak
Whether it’s currently the assistant’s turn to speak
Duration of current turn in milliseconds
Duration of current silence in milliseconds
Timestamp of last turn change
useVoiceDebug
Development and debugging utilities:
Current debug information and internal state
WebSocket connection statistics and performance metrics
Audio processing statistics and quality metrics
Raw WebSocket message history for debugging
Export debug logs for analysis
Type Definitions
VoiceMessage
NextEVIConfig
AudioConfig
ConnectionMetadata
Best Practices
Hook Selection
Hook Selection
- Use
useVoicefor most applications - it provides everything you need - Use specialized hooks (
useVoiceStatus,useVoiceMessages, etc.) when you need specific functionality - Use
useSimpleVoicefor quick prototypes or simple integrations - Use
useVoiceDebugonly in development environments
Error Handling
Error Handling
- Always handle connection errors in your UI
- Monitor the
errorstate from hooks - Implement retry logic for network issues
- Validate configuration before connecting
Performance
Performance
- Use
React.memofor message components to prevent unnecessary re-renders - Implement virtual scrolling for long conversation histories
- Clean up connections when components unmount
- Use
useVoiceAudioto show loading states during audio activity
User Experience
User Experience
- Show clear connection status to users
- Provide visual feedback for audio activity (recording/playing)
- Handle microphone permissions gracefully
- Implement idle timeout warnings
