# Stream speech to text

> WS wss://api.nabrah.ai/api/ext/stt/ws

Group: Speech to text. Page: https://www.nabrah.ai/en/docs/api-reference/speech-to-text/stream-speech-to-text

Stream audio over a WebSocket and receive live transcription. Open the socket, then send a single JSON configuration message as the very first frame — before any audio. The server replies with a ready signal, after which you stream raw 16 kHz mono LINEAR_PCM audio frames and receive transcript messages back. Authenticate with `api_key` inside the config message (not the `X-API-Key` header).

## Configuration message

Sent once, as the first frame after the socket opens. Any field that is missing or the wrong type silently falls back to its default.

- **api_key** (string · required): API key for authentication. The connection is closed if it is missing or invalid. Fields: `api_key`.
- **recognition_model** (string · default: server-configured model): Model variant for the session. The default model is more accurate. Use "eot_nabrah" to emit inline <eot> tokens for turn detection — the raw token appears verbatim in text and the client is responsible for stripping it. Fields: `recognition_model`.
- **end_of_utterance_silence_ms** (integer · default: -1): Trailing silence in milliseconds that marks an utterance as ended. -1 leaves the recognizer's own defaults in place; only a positive value overrides. Drives both the final result and the earlier preliminary transcript, so lowering it is the main latency knob. Fields: `end_of_utterance_silence_ms`.
- **priority_words** (list of strings · default: []): Words or phrases to bias recognition toward. Fields: `priority_words`.
- **priority_words_strength** (number · default: 0.5): How strongly to bias toward priority_words. 0.5 works well for a relatively small vocabulary; the recommended range for broader biasing is 20-100. Fields: `priority_words_strength`.

Fixed and never caller-configurable: input language, sample rate (16 kHz), encoding (LINEAR_PCM), channel count (mono), and punctuation.

## Body (application/json)

```json
{
  "api_key": "YOUR_API_KEY",
  "recognition_model": "",
  "end_of_utterance_silence_ms": 500,
  "priority_words": [
    "نبرة",
    "ذكاء اصطناعي",
    "خدمة العملاء"
  ],
  "priority_words_strength": 0.5
}
```

## Response

### 101 Socket upgraded. The server sends a ready signal, then transcript messages as audio streams in.

Content type: `application/json`

```json
{
  "text": "مرحبا بك في نبرة",
  "is_final": true
}
```

## Request examples

### Python

```python
import asyncio
import json

import websockets


async def main():
    async with websockets.connect("wss://api.nabrah.ai/api/ext/stt/ws") as ws:
        await ws.send(json.dumps({
            "api_key": "YOUR_API_KEY",
            "recognition_model": "",
            "end_of_utterance_silence_ms": 500,
            "priority_words": [
                "نبرة",
                "ذكاء اصطناعي",
                "خدمة العملاء"
            ],
            "priority_words_strength": 0.5
        }))
        print(await ws.recv())  # ready
        # Stream raw 16 kHz mono PCM: await ws.send(chunk)
        async for message in ws:
            print(json.loads(message))


asyncio.run(main())
```

### JavaScript

```javascript
const ws = new WebSocket("wss://api.nabrah.ai/api/ext/stt/ws");

ws.addEventListener("open", () => {
  ws.send(JSON.stringify({
    "api_key": "YOUR_API_KEY",
    "recognition_model": "",
    "end_of_utterance_silence_ms": 500,
    "priority_words": [
      "نبرة",
      "ذكاء اصطناعي",
      "خدمة العملاء"
    ],
    "priority_words_strength": 0.5
  }));
});

ws.addEventListener("message", (event) => {
  console.log(JSON.parse(event.data));
});

// After the ready message, stream raw 16 kHz mono PCM frames:
// ws.send(pcmChunk);
```
