Skip to main content

Overview

The Speech-to-Text (STT) API converts audio files into text transcriptions. VoxNexus supports both REST API and WebSocket API for STT operations, with features like timestamps and speaker diarization.

REST API

The REST API endpoint /v1/stt processes complete audio files and returns full transcription results.

Basic Usage

Query Parameters

string
required
Model identifier. Specifies which model to use for STT. Use the /v1/models endpoint to browse available models.
string
Language or locale code. Supports both ISO 639-1 language codes (e.g., en, zh) and BCP 47 locale codes (e.g., en-US, zh-CN). When a language code is provided, the system will automatically resolve it to the most common locale (e.g., enen-US). Default: en-US. Optional but recommended for better recognition accuracy.
integer
required
Sample rate in Hz. Required parameter. Common values: 16000 for telephony, 44100 for high-quality audio.
boolean
Whether to return word-level timestamps. Default: false.
boolean
Whether to enable speaker diarization (identify different speakers). Default: false.
boolean
Whether to enable LLM post-processing on the STT transcript. Default: false. When enabled, the recognized transcript is passed to the LLM with the specified llm_prompt, and the transformed result is returned in the text field. If LLM transform fails, text falls back to the raw transcript.
string
LLM transform instruction. Required when enable_llm_transform=true. Describes what the LLM should do with the transcript, e.g. "correct punctuation", "translate to English", "summarize key points".
string
LLM model ID to use for transform. Optional — falls back to the server-configured default when not specified. Routing is prefix-based: claude-* models route to Anthropic; all other model IDs route to OpenAI. Examples: claude-haiku-4-5-20251001 (Anthropic), gpt-4.1 (OpenAI).
integer
Maximum output tokens for LLM transform. Optional. Range: 1 - 4096.

Request Body

The request body should contain the audio file in one of the supported formats:
  • audio/wav
  • audio/mpeg (MP3)
  • audio/pcm
  • application/octet-stream

Response

string
Unique identifier for this request.
string
Detected or specified language code (e.g., en, en-US, zh). May not be present if language detection is not enabled.
string
Raw STT recognition output (original ASR text before any LLM processing). Always present; identical to text when LLM transform is not enabled.
string
Final output text. When LLM transform is enabled and succeeds, this contains the LLM-transformed result; otherwise it equals transcript.
integer
Audio duration in milliseconds.
array
Word-level information array. Only present if enable_timestamps is true. Each item contains:
  • word: The recognized word
  • offset: Start time in milliseconds
  • duration: Duration in milliseconds
  • confidence: Confidence score (0.0-1.0)
array
Speaker information array. Only present if enable_speaker_diarization is true. Each item contains:
  • speaker_id: Unique speaker identifier
  • text: Text spoken by this speaker
  • offset: Start time in milliseconds
  • duration: Duration in milliseconds
string
Timestamp when the transcription was created (ISO 8601 format).

Response Headers

  • X-Request-ID: Request identifier
  • X-Language: Detected language code
  • X-Duration-Ms: Audio duration in milliseconds

WebSocket API

The WebSocket API provides real-time speech recognition, ideal for live transcription scenarios.

Connection

Connect to wss://api.voxnexus.ai/v1/stt/realtime with authentication:

Message Flow

  1. Initialize: Send an init message with recognition parameters
  2. Send Audio: Continuously send audio messages with Base64-encoded audio chunks
  3. Receive Results: Receive transcript messages (is_final: false for interim, is_final: true for complete sentences)
  4. Handle Errors: Monitor for error messages

Initialization Message

string
required
Message type. Must be init.
string
required
Model identifier. Specifies which model to use for STT. Use the /v1/models endpoint to browse available models.
string
Language or locale code. Supports both ISO 639-1 language codes (e.g., en, zh) and BCP 47 locale codes (e.g., en-US, zh-CN). When a language code is provided, the system will automatically resolve it to the most common locale (e.g., enen-US). Optional but recommended for better accuracy.
string
required
Audio format. Only pcm is supported.
integer
required
Sample rate in Hz. Only 16000 is supported.
boolean
Whether to return word-level timestamps. Default: false.
boolean
Whether to enable LLM post-processing on each final transcript. Default: false. When enabled, the server sends llm messages alongside transcript messages.
string
LLM transform instruction. Required when enable_llm_transform=true. E.g. "correct punctuation", "translate to English", "rewrite humorously".
string
LLM model ID. Optional — falls back to server default when not specified. Routing is prefix-based: claude-* models route to Anthropic; all other model IDs route to OpenAI. Examples: claude-haiku-4-5-20251001 (Anthropic), gpt-4.1 (OpenAI).
integer
Maximum output tokens for LLM transform. Optional. Range: 1 - 4096.
string
LLM processing mode. Default: per_segment.
  • per_segment: LLM runs on each final sentence as it arrives (low latency, real-time).
  • post_flush: LLM runs once on the full accumulated text after flush (full context).
boolean
When llm_mode=per_segment, also run a full-text LLM pass after flush. Default: false. Produces both per-sentence llm messages (with segment_id) and a final full-text llm message (without segment_id) after flush completes.
string
Separate prompt for the post-flush full-text pass. Falls back to llm_prompt when not specified.

Audio Message

Command Message

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 Message
Transcript Message
The is_final field distinguishes between partial results (false) and complete sentences (true). The confidence score 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 — it links subsequent llm messages to this segment.
LLM Transform Message
Each final transcript triggers a sequence of llm messages streaming the LLM output incrementally. Concatenate all delta values until is_final=true to get the full transformed text. The segment_id links this output to its corresponding transcript message. For a full-text post-flush pass, segment_id is absent.
Flush Done Message
Error Message

Complete Example

Best Practices

Audio Format Selection

  • PCM: Best for real-time WebSocket streaming, requires exact sample rate specification
  • WAV: Good for REST API, includes format headers
  • MP3: Compressed format, good for file uploads, requires decoding

Sample Rate Guidelines

  • 8kHz: Telephony quality, sufficient for phone recordings
  • 16kHz: Standard quality, good balance of quality and file size
  • 22.05kHz: Radio quality
  • 44.1kHz/48kHz: High-quality audio, use for professional recordings

Language Specification

Always specify the language when known:

Timestamps

Enable timestamps for word-level timing information:

Speaker Diarization

Use speaker diarization for multi-speaker scenarios:

Error Handling

Implement robust error handling:

Common Use Cases

Meeting Transcription

Transcribe meeting recordings with speaker identification:

Live Captioning

Use WebSocket API for real-time captioning:

Voice Commands

Process voice commands with real-time recognition:

Audio Content Indexing

Index audio content for search:

Rate Limits and Quotas

  • Implement retry logic with exponential backoff for 429 responses
  • Consider WebSocket API for continuous streaming scenarios
  • Batch process large audio files during off-peak hours