Overview
The VoxNexus WebSocket API provides real-time bidirectional communication for voice services. It’s ideal for applications requiring low-latency, interactive voice processing such as:- Real-time voice assistants
- Live transcription services
- Interactive voice response (IVR) systems
- Voice-controlled applications
- Real-time captioning
Connection
Endpoints
- Text-to-Speech:
wss://api.voxnexus.ai/v1/tts/realtime - Speech-to-Text:
wss://api.voxnexus.ai/v1/stt/realtime
Authentication
VoxNexus WebSocket API supports two authentication methods: Option 1: Query Parameter (Recommended) Append your API key as a query parameter. This method is recommended as it works with all WebSocket clients:X-Api-Key header (may not work with all clients):
Query parameter authentication is recommended for browser-based applications as the standard WebSocket API doesn’t support custom headers.
Connection Lifecycle
- Connect: Establish WebSocket connection with authentication
- Initialize: Send initialization message with configuration
- Ready: Receive ready confirmation from server
- Exchange: Send/receive data messages
- Close: Gracefully close connection when done
Text-to-Speech WebSocket
Message Types
Client Messages
Initialization (init)
text)
Server Messages
Ready (ready)
audio)
error)
Complete Example
Speech-to-Text WebSocket
Message Types
Client Messages
Initialization (init)
audio)
command)
The
flush command tells the server that no more audio will be sent. The server will respond with a flush_done message after completing recognition. Subsequent audio will start a new recognition session.Server Messages
Ready (ready)
transcript)
The
is_final field distinguishes between partial results (false) and complete sentences (true). Confidence scores and word-level information are only valid when is_final is true. segment_id is only present when is_final=true and LLM transform is enabled.llm)
Sent only when
enable_llm_transform=true. Each final transcript segment triggers a sequence of llm messages streaming the LLM output incrementally. Concatenate all delta values until is_final=true. segment_id links the output to its corresponding transcript message (absent for a full-text post-flush pass).flush_done)
error)
Complete Example
Best Practices
Connection Management
Reconnection LogicError Handling
Audio Processing
Chunk Size Optimization- Send audio chunks of 100-200ms for optimal latency
- Too small: Increased overhead
- Too large: Increased latency
Performance Optimization
Batch Text MessagesCommon Patterns
Bidirectional Voice Conversation
Real-time Captioning
Troubleshooting
Connection Issues
Problem: Connection fails immediately- Solution: Verify API key is correct and has proper permissions
- Solution: Check network connectivity and firewall settings
- Solution: Implement reconnection logic with exponential backoff
- Solution: Check for network instability or proxy issues
Audio Issues
Problem: No audio received (TTS)- Solution: Verify initialization message was sent and ready message received
- Solution: Check that text messages are being sent correctly
- Solution: Verify audio format and sample rate match initialization
- Solution: Check that audio chunks are being sent continuously
- Solution: Ensure audio quality is sufficient (no excessive noise)
Performance Issues
Problem: High latency- Solution: Reduce audio chunk size for faster processing
- Solution: Use appropriate sample rates (16kHz is usually sufficient)
- Solution: Optimize network connection (use closer server if available)
- Solution: Process and discard audio chunks after sending
- Solution: Limit buffer sizes for audio data
- Solution: Close unused connections promptly

