Skip to main content
SLNG exposes every TTS and STT model over both HTTP and WebSocket. The URL stays the same; only the protocol changes.

At a Glance

HTTPWebSocket
FlowRequest → wait → complete responseOpen connection → stream both ways
Latency200–500 msSub-100 ms
Best forBatch jobs, file conversionVoice agents, live transcription
ComplexityOne curl callConnection lifecycle to manage

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
curl https://api.slng.ai/v1/tts/slng/deepgram/aura:2 \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "text": "Hello from HTTP!" }' \
  --output hello.wav
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?

Use caseProtocolWhy
Convert a script to an audio fileHTTPOne request, one file — simple
Transcribe a batch of recordingsHTTPUpload each file, get results
Voice agent (phone or web)WebSocketReal-time STT→LLM→TTS loop
Live captioning / transcriptionWebSocketStream mic audio, get text back
Generate a voiceover for a videoHTTPNo real-time requirement

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.