Skip to main content

WebSocket API Introduction

The 60db WebSocket API provides real-time, bidirectional streaming for Speech-to-Text (STT) and Text-to-Speech (TTS) services.

Base URL

ws://api.60db.ai/ws

Available Endpoints

EndpointDescription
/ws/sttSpeech-to-Text streaming
/ws/ttsText-to-Speech streaming
/ws/healthHealth check endpoint

Why WebSocket?

WebSocket provides several advantages over REST API for audio processing:
  • Real-time streaming: Low-latency bidirectional communication
  • Continuous audio: Stream audio chunks as they’re recorded
  • Live transcription: Get partial results while speaking
  • Efficient: No need to send complete audio files
  • Interactive: Natural conversation experience

Quick Start

1. Connect with API Key

const ws = new WebSocket('ws://api.60db.ai/ws/stt?apiKey=sk_live_your_key');

2. Handle Connection Events

ws.onopen = () => {
  console.log('Connected!');
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('Received:', data);
};

3. Send Messages

// Start STT session
ws.send(JSON.stringify({
  type: 'start',
  languages: ['en'],
  config: {
    encoding: 'mulaw',
    sample_rate: 8000
  }
}));

4. Send Binary Data

// Send audio bytes
ws.send(audioBuffer);

Connection Flow

Client                          Server
  |                               |
  |----- WebSocket Connect ------->|
  |                               |
  |<-- Authentication Message ----|
  |                               |
  |----- Start Session Message --->|
  |                               |
  |----- Binary Audio Data ------->|
  |----- Binary Audio Data ------->|
  |----- Binary Audio Data ------->|
  |                               |
  |<--- Transcription Results ----|
  |<--- Transcription Results ----|
  |                               |
  |----- Stop Session Message ---->|
  |                               |
  |<-- Billing Summary -----------|

Authentication

WebSocket connections authenticate via query parameter:
ws://api.60db.ai/ws/stt?apiKey=sk_live_your_api_key
Or with JWT token:
ws://api.60db.ai/ws/stt?token=your_jwt_token

Message Format

All control messages are JSON formatted:
{
  "type": "message_type",
  "data": "message_data"
}
Binary audio data is sent as raw bytes without JSON encoding.

Next Steps