> ## Documentation Index
> Fetch the complete documentation index at: https://60db.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# WebSocket Introduction

> Overview of 60db WebSocket API for real-time STT and TTS

# 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

| Endpoint     | Description              |
| ------------ | ------------------------ |
| `/ws/stt`    | Speech-to-Text streaming |
| `/ws/tts`    | Text-to-Speech streaming |
| `/ws/health` | Health 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

```javascript theme={null}
const ws = new WebSocket('ws://api.60db.ai/ws/stt?apiKey=sk_live_your_key');
```

### 2. Handle Connection Events

```javascript theme={null}
ws.onopen = () => {
  console.log('Connected!');
};

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

### 3. Send Messages

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

### 4. Send Binary Data

```javascript theme={null}
// 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:

```json theme={null}
{
  "type": "message_type",
  "data": "message_data"
}
```

Binary audio data is sent as raw bytes without JSON encoding.

## Next Steps

* [STT WebSocket Guide](/api-reference/websocket/stt) - Learn Speech-to-Text
* [TTS WebSocket Guide](/api-reference/websocket/tts) - Learn Text-to-Speech
* [Complete WebSocket Reference](/websocket-api) - Full API documentation
