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
For compatible voices, the optionalintervention_group_id in init selects one pronunciation group owned by your account. Omission selects default; the session uses only that group and system rules. The selected group is fixed for the session: send a new init on a new connection to use another group, not a group field on text messages. Explicit selection on an unsupported provider, including default, is rejected with INTERVENTION_NOT_SUPPORTED. IDs outside your account cannot select another user’s rules.
The initialization language follows the same BCP 47 locale rules as HTTP synthesis. Omit it to use the available primary locale of the selected model and voice, or its sole supported locale. A broad tag such as en uses a matching primary locale or sole match. If several matches remain without a default, select a locale explicitly. An explicit region such as en-GB must be supported and does not fall back to en-US. Use model-filtered voice capabilities to populate locale choices.
For a compatible model and voice, initialize a session with a group returned by the group API:
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

