Skip to main content

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:
Option 2: Header Use 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

  1. Connect: Establish WebSocket connection with authentication
  2. Initialize: Send initialization message with configuration
  3. Ready: Receive ready confirmation from server
  4. Exchange: Send/receive data messages
  5. Close: Gracefully close connection when done

Text-to-Speech WebSocket

Message Types

Client Messages

Initialization (init)
Text (text)

Server Messages

Ready (ready)
Audio (audio)
Error (error)

Complete Example

Speech-to-Text WebSocket

Message Types

Client Messages

Initialization (init)
Audio (audio)
Command (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 (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 Transform (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 (flush_done)
Error (error)

Complete Example

Best Practices

Connection Management

Reconnection Logic
Heartbeat/Ping

Error Handling

Audio Processing

Chunk Size Optimization
  • Send audio chunks of 100-200ms for optimal latency
  • Too small: Increased overhead
  • Too large: Increased latency
Buffer Management

Performance Optimization

Batch Text Messages
Throttle Audio Sending

Common 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
Problem: Connection drops frequently
  • 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
Problem: Recognition not working (STT)
  • 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)
Problem: High memory usage
  • Solution: Process and discard audio chunks after sending
  • Solution: Limit buffer sizes for audio data
  • Solution: Close unused connections promptly