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).
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()){
"text": "مرحبا بك في نبرة",
"is_final": true
}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_keystring · requiredAPI key for authentication. The connection is closed if it is missing or invalid.
api_keyrecognition_modelstring · default: server-configured modelModel 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.
recognition_modelend_of_utterance_silence_msinteger · default: -1Trailing 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.
end_of_utterance_silence_mspriority_wordslist of strings · default: []Words or phrases to bias recognition toward.
priority_wordspriority_words_strengthnumber · default: 0.5How strongly to bias toward priority_words. 0.5 works well for a relatively small vocabulary; the recommended range for broader biasing is 20-100.
priority_words_strengthFixed and never caller-configurable: input language, sample rate (16 kHz), encoding (LINEAR_PCM), channel count (mono), and punctuation.
{
"api_key": "YOUR_API_KEY",
"recognition_model": "",
"end_of_utterance_silence_ms": 500,
"priority_words": [
"نبرة",
"ذكاء اصطناعي",
"خدمة العملاء"
],
"priority_words_strength": 0.5
}Socket upgraded. The server sends a ready signal, then transcript messages as audio streams in.
application/json