- An SLNG key
- Basic familiarity with WebSockets (open, send, receive, close)
Protocol overview
This page documents the WebSocket protocol used by SLNG-hosted models and bridges. Third-party providers (Deepgram, KugelAudio, Sarvam) may expose their own native WebSocket formats. Check the per-model API reference in the sidebar for provider-specific details.Supported encodings, sample rates, and optional fields vary by model. For model-specific parameters, see the Text-to-Speech and Speech-to-Text tabs in the sidebar.
TTS WebSocket Protocol
For the full per-model parameter list and response schema, see the model’s page in the Text-to-Speech sidebar.Connection
slng/ prefix for
SLNG-hosted models:
Message Flow
Browse all available TTS models and endpoints on the Text-to-Speech models page.Client → Server Messages
Initialize Session
Initialize a session with model and voice configuration before sending text.config.pronunciation to set a default pronunciation dictionary for the session.
Parameters:
Send Text for Synthesis
Send text to synthesize into audio. Setflush: true to finalize the current segment immediately instead of waiting for more text.
pronunciation on a text message to override the active dictionary for that turn. Later turns reuse the most recent active dictionary.
Flush Buffer
Force any buffered text/audio to be finalized and delivered.Clear Buffer
Clear any queued text/audio from the current session.Close Session
Close the current session and stop any further audio generation.Server → Client Messages
Session Ready
Indicates the session is ready to receive messages.Audio Chunk
Chunk of base64-encoded audio data.Segment Start
Signals the start of a synthesized segment.Segment End
Signals the end of a synthesized segment.Flushed
Acknowledges that buffered output was flushed.Cleared
Acknowledges that queued output was cleared.Audio End
Signals the end of audio generation.Error
Indicates an error occurred during synthesis.
Common Error Codes:
auth_error: Invalid or missing SLNG keyconfig_error: Invalid configurationrate_limit: Too many requestsprovider_error: Upstream provider error
STT WebSocket Protocol
For the full per-model parameter list and response schema, see the model’s page in the Speech-to-Text sidebar.Connection
slng/ prefix for
SLNG-hosted models:
Message Flow
Browse all available STT models and endpoints on the Speech-to-Text models page.Client → Server Messages
Initialize Session
Initialize a session with recognition configuration before streaming audio.Send Audio Data
Stream an audio frame to be transcribed. After initialization, send audio in one of two formats: Binary frames: send raw PCM audio samples directly as binary WebSocket frames:Finalize Transcription
Force the server to finalize any buffered audio and return results. The connection stays open so you can continue streaming.Close Stream
Signal that no more audio will be sent. The server processes any remaining audio, sends final results, then closes the connection.Keep-Alive
Send periodically during silence to prevent idle disconnection.Server → Client Messages
Session Ready
Indicates the session is ready to receive audio.Partial Transcript
Interim transcription result.Final Transcript
Final transcription result with optional metadata.Error
Indicates an error occurred during recognition.Next Steps
Integration guide
Best practices and troubleshooting
TTS examples
JavaScript and Python code for real-time TTS
STT examples
JavaScript and Python code for real-time STT
Protocol comparison
HTTP vs. WebSocket: when to use each