Skip to content
speechinfraConsole

OpenAI · Realtime ASR

Whisper Realtime

Streaming multilingual speech recognition powered by the Whisper model family.

whisper-realtime
$0.005 / audio minuteTry in Console

Current model-specific price from our catalog. Requests require your project API key and sufficient balance. Availability is checked at execution time.

Input and capabilities

Connect over WebSocket. After session.updated, send mono PCM16 little-endian audio at 16 kHz. The direct streaming session supports up to 30 seconds of audio.

  • transcription
  • realtime input
  • streaming output
  • word timestamps
  • segment timestamps
  • partial transcripts
  • endpointing

Automatic language detection: supported.

Supported language codes: en, zh, de, es, ru, ko, fr, ja, pt, tr, pl, ca, nl, ar, sv, it, id, hi, fi, vi, he, uk, el, ms, cs, ro, da, hu, ta, no, th, ur, hr, bg, lt, la, mi, ml, cy, sk, te, fa, lv, bn, sr, az, sl, kn, et, mk, br, eu, is, hy, ne, mn, bs, kk, sq, sw, gl, mr, pa, si, km, sn, yo, so, af, oc, ka, be, tg, sd, gu, am, yi, lo, uz, fo, ht, ps, tk, nn, mt, sa, lb, my, bo, tl, mg, as, tt, haw, ln, ha, ba, jv, su, yue.

API endpoint

WEBSOCKET wss://api.speechinfra.com/v1/inference/whisper-realtime/realtime

Authenticate with your Speechinfra project key. Read the quickstart and billing guide.

Python
# pip install websockets
# audio.pcm: mono, 16 kHz, signed PCM16 little-endian; <= 30 seconds.
import asyncio, json, os
from pathlib import Path
from websockets.asyncio.client import connect

async def main():
    headers = {"Authorization": "Bearer " + os.environ["SPEECH_API_KEY"]}
    async with connect("wss://api.speechinfra.com/v1/inference/whisper-realtime/realtime", additional_headers=headers) as socket:
        await socket.send("{\"turn_detection\":\"server_vad\",\"threshold\":0.3,\"min_silence_duration_ms\":500,\"min_speech_duration_ms\":250,\"max_speech_duration_s\":5,\"speech_pad_ms\":250,\"type\":\"session.configure\"}")
        while True:
            event = json.loads(await socket.recv())
            if event["type"] == "error":
                raise RuntimeError(event)
            if event["type"] == "session.updated":
                break
        async def send():
            audio = Path("audio.pcm").read_bytes()
            assert 0 < len(audio) <= 960000 and len(audio) % 2 == 0
            for i in range(0, len(audio), 3200):
                await socket.send(audio[i:i+3200])
                await asyncio.sleep(0.1)
            await socket.send('{"type":"session.close"}')
        sender = asyncio.create_task(send())
        try:
            async with asyncio.timeout(90):
                async for message in socket:
                    print(message)
        finally:
            sender.cancel()

asyncio.run(main())
JavaScript / browser
// Use from the console origin with a Speech Cloud project key.
// apiKey is a Speech Cloud project key, never a provider key.
const socket = new WebSocket("wss://api.speechinfra.com/v1/inference/whisper-realtime/realtime", ['speech', apiKey]);
socket.onopen = () => socket.send("{\"turn_detection\":\"server_vad\",\"threshold\":0.3,\"min_silence_duration_ms\":500,\"min_speech_duration_ms\":250,\"max_speech_duration_s\":5,\"speech_pad_ms\":250,\"type\":\"session.configure\"}");
socket.onmessage = ({data}) => {
  const event = JSON.parse(data);
  console.log(event);
  if (event.type === 'session.updated') {
    // Send mono PCM16 / 16 kHz binary frames, <= 30 s in total.
    // After the final frame: socket.send(JSON.stringify({type:'session.close'}));
  }
};
// For a complete file-streaming example: scripts/test_models.py

Request parameters

Generated from the API schema for this deployment. Conditional parameters apply only when their controlling setting is enabled.

ParameterTypeDetails
turn_detectionstring

enum: server_vad, manual · default: "server_vad"

All accepted values
[
  "server_vad",
  "manual"
]
thresholdnumber

default: 0.3 · min: 0 · max: 1

Applies when: {"turn_detection":"server_vad"}

min_silence_duration_msinteger

default: 500 · min: 0 · max: 10000

Applies when: {"turn_detection":"server_vad"}

min_speech_duration_msinteger

default: 250 · min: 0 · max: 10000

Applies when: {"turn_detection":"server_vad"}

max_speech_duration_snumber

default: 5 · min: 0.1 · max: 300

Applies when: {"turn_detection":"server_vad"}

speech_pad_msinteger

default: 250 · min: 0 · max: 5000

Applies when: {"turn_detection":"server_vad"}

typestring

enum: session.configure · default: "session.configure"

All accepted values
[
  "session.configure"
]
Complete request schema
{
  "type": "object",
  "additionalProperties": false,
  "required": [],
  "properties": {
    "turn_detection": {
      "type": "string",
      "enum": [
        "server_vad",
        "manual"
      ],
      "default": "server_vad"
    },
    "threshold": {
      "type": "number",
      "minimum": 0,
      "maximum": 1,
      "default": 0.3,
      "visibleWhen": {
        "turn_detection": "server_vad"
      }
    },
    "min_silence_duration_ms": {
      "type": "integer",
      "minimum": 0,
      "maximum": 10000,
      "default": 500,
      "visibleWhen": {
        "turn_detection": "server_vad"
      }
    },
    "min_speech_duration_ms": {
      "type": "integer",
      "minimum": 0,
      "maximum": 10000,
      "default": 250,
      "visibleWhen": {
        "turn_detection": "server_vad"
      }
    },
    "max_speech_duration_s": {
      "type": "number",
      "minimum": 0.1,
      "maximum": 300,
      "default": 5,
      "visibleWhen": {
        "turn_detection": "server_vad"
      }
    },
    "speech_pad_ms": {
      "type": "integer",
      "minimum": 0,
      "maximum": 5000,
      "default": 250,
      "visibleWhen": {
        "turn_detection": "server_vad"
      }
    },
    "type": {
      "type": "string",
      "enum": [
        "session.configure"
      ],
      "default": "session.configure"
    }
  }
}

Response schema

Returns JSON events over the WebSocket connection.

View complete response schema
{
  "type": "object",
  "description": "JSON server events. Send binary mono PCM16 at 16 kHz after session.updated; session.close drains and returns session.closed.",
  "properties": {
    "type": {
      "enum": [
        "session.created",
        "session.updated",
        "session.routed",
        "transcript.partial",
        "transcript.final",
        "error",
        "session.closed"
      ]
    }
  }
}