Skip to main content
Every TTS and STT model is reachable over both HTTP and WebSocket. The URL stays the same; only the protocol changes. The snippets on this page use SLNG_API_KEY as a placeholder. Replace it with an SLNG key from app.slng.ai/api-keys before running the code.

At a Glance

How Each Protocol Works

You send a request and get back the full result once processing finishes.Use HTTP when you:
  • Generate audio files for download or storage
  • Transcribe pre-recorded audio files
  • Want the simplest possible integration
  • Don’t need real-time streaming
See complete examples: TTS over HTTP · STT over HTTP

WebSocket Best Practices

WebSocket connections are stateful. You need to handle the lifecycle:
  • Reconnect with backoff. If the connection drops, retry with exponential delay (1s, 2s, 4s… up to 30s).
  • Handle binary and text frames. Audio arrives as binary ArrayBuffer; control messages come as JSON text.
  • Send a close frame when you’re done so the server releases resources.

Which Protocol for Which Use Case?

Next Steps

TTS over HTTP

Generate audio files from text with simple HTTP requests.

TTS over WebSocket

Stream audio in real-time with interruption support.

STT over HTTP

Transcribe pre-recorded audio files.

STT over WebSocket

Transcribe live audio from a microphone.