kotoba-technologies/kotoba-streaming-stt/v1/realtime
Loading API documentation
Kotoba Streaming STT turns speech into text over a WebSocket connection, in Japanese, English, Mandarin Chinese, Korean, Cantonese, Spanish and Vietnamese. Transcript updates arrive while the audio is still streaming. Speaker diarization is optional: turn it on and every finalized turn carries a speaker label.
Endpoint
wss://fal.run/Kotoba-Technologies/kotoba-streaming-stt/v1/realtimeThe Playground offers a one-shot demo (POST /v1/speech-to-text, JSON body with audio_url) that runs one clip through the same streaming session and returns text, words, language_code and audio_duration_secs. It is bounded for demos. Production integrations use the WebSocket endpoint described below.
start_ms / end_ms) relative to the input audio.Send JSON messages over the WebSocket. Audio chunks are base64-encoded in input_audio_buffer.append events.
Mono PCM16 at 24 kHz is the typical input. The server also accepts float32 PCM, PCM at other sample rates (resampled server-side), 8 kHz mu-law (mulaw or twilio), and self-contained Ogg/Opus chunks (opus).
Open the session with one transcription_session.update message, then wait for transcription_session.updated, which echoes the applied settings.
| Setting | Type and values | Default | Behavior |
|---|---|---|---|
session.input_audio_transcription.target_language | string, see Supported languages below | required | Language spoken in the audio. |
session.diarization | boolean | false | true returns speaker-attributed transcription. Where two speakers talk at the same time, the overlapping words go to one of them. |
session.turn_detection | object (semantic_vad or server_vad) or false | semantic_vad, medium | See Turn detection below. |
session.input_audio_transcription.timestamps | boolean | false | true adds start_ms / end_ms to deltas and completed turns. |
session.input_audio_transcription.keywords | array of strings | none | Up to 1,000 terms, 64 characters each. The decoder is biased toward these spellings. |
session.input_audio_transcription.style_preference.human_name | string: "default" or "kana" | "default" | "kana" writes personal names in katakana (Japanese audio); "default" writes them as usual. |
session.input_audio_transcription.style_preference.verbatim | boolean | true | false removes fillers and restarts from the transcript. Japanese only: with another target_language it returns invalid_parameters (param session.input_audio_transcription). |
Timestamps are milliseconds from the first audio accepted on the connection, not wall-clock time. A new connection starts at zero.
Pass the code in target_language exactly as written (lowercase). Any other value returns an invalid_parameters error with param session.input_audio_transcription.target_language.
| Language | target_language |
|---|---|
| Japanese | ja |
| English | en |
| Mandarin Chinese (Simplified output) | zh |
| Mandarin Chinese (Taiwan Traditional output) | zh-tw |
| Korean | ko |
| Cantonese (Traditional output) | yue |
| Spanish | es |
| Vietnamese | vi |
When turn_detection is omitted, this deployment applies semantic turn detection:
{"type": "semantic_vad", "eagerness": "medium"}Semantic turn detection completes a turn shortly after the model finishes a sentence and waits longer in the middle of one. eagerness is low, medium or high (auto equals medium). It reads the model's text output, not audio energy.
{"type": "server_vad", "silence_duration_ms": 800} completes a turn after a fixed run of empty model output. silence_duration_ms is a non-negative integer; omitted or null means 800. It counts consecutive empty model outputs, not wall-clock silence.
"turn_detection": false gives a continuous transcript through delta events with no completed-turn events. It is only available with diarization off: a diarized session needs turns, because the settled speaker arrives on the completed event. Sending diarization: true with turn_detection: false returns an invalid_parameters error with param session.turn_detection. The values true and null are rejected as well; use false or one of the two objects above.
{
"type": "transcription_session.update",
"session": {
"input_audio_format": "pcm16",
"input_audio_sample_rate": 24000,
"input_audio_number_of_channels": 1,
"input_audio_transcription": {
"target_language": "ja",
"timestamps": true
},
"diarization": true
}
}Wait for transcription_session.updated, then send audio:
{"type": "input_audio_buffer.append", "audio": "<base64 PCM16>"}For ordinary transcription, omit diarization or set it to false. Audio and commit work the same way.
Field values below are illustrative.
A provisional update:
{
"type": "conversation.item.input_audio_transcription.delta",
"item_id": "turn-1",
"speaker_id": "speaker_1",
"delta": "おはよう",
"start_ms": 120,
"end_ms": 640
}A finalized speaker turn:
{
"type": "conversation.item.input_audio_transcription.completed",
"item_id": "turn-1",
"speaker_id": "speaker_1",
"transcript": "おはようございます。",
"start_ms": 120,
"end_ms": 1200
}With diarization off, deltas are append-only: concatenate the non-empty deltas of a turn to get its text. With turn detection on, each completed event carries the full text of its turn under the same item_id as its deltas.
With diarization on, deltas are provisional, in text and in speaker. The completed event for an item_id is the settled result and replaces the deltas of that item. Handle it like this:
item_id.completed, replace the item's provisional text and speaker with transcript and speaker_id. Do not append the completed transcript to its deltas.transcript retires the item: remove it.speaker_id and a null item_id; they belong to the previous item.Speaker labels are speaker_1 through speaker_8, in order of first appearance, and are stable for the whole connection. They do not identify the same person across connections. Speakers with very similar voices can share a label.
Send a commit after the last audio chunk:
{"type": "input_audio_buffer.commit"}Keep reading until the server returns:
{"type": "input_audio_buffer.committed"}The server flushes the remaining audio and sends the pending completed turns before committed. Stopping the audio does not flush the session. An error event or a disconnect is not a successful commit. The server then closes the connection with code 1000.
{"type": "error", "error": "session_quota_exceeded: ..."}. Open a new session to continue. Audio volume and silence do not count toward this limit.transcription_session.update within 60 seconds of connecting.system_busy). Retry with backoff.{"type": "error", "error": {"code": "invalid_parameters", "param": "<field>"}}. The connection stays open, and a corrected transcription_session.update on the same connection is accepted. param points at the setting, for example session.turn_detection or session.input_audio_transcription.keywords.GET https://fal.run/Kotoba-Technologies/kotoba-streaming-stt/model_and_cuda_availability (same Authorization: Key header) or allow for it in the first connection's timeout. The Kotoba Python SDK waits 15 seconds for the session to open, so with the SDK warm the app first or retry.Authenticate the WebSocket upgrade with Authorization: Key <FAL_KEY>. Keep the fal key on your server; do not ship it to browsers or mobile clients.
kotoba-sdk 0.3.2 or newer on PyPI talks to this endpoint and selects the Key scheme for fal.run hosts.
pip install "kotoba-sdk>=0.3.2"
export KOTOBA_API_KEY=<fal key>
export KOTOBA_ASR_URL=wss://fal.run/Kotoba-Technologies/kotoba-streaming-stt/v1/realtimeOrdinary transcription yields text deltas:
from kotoba import KotobaClient
client = KotobaClient()
for delta in client.asr.transcribe_stream(pcm16_chunks(), language="ja"):
print(delta, end="", flush=True)With diarization=True the stream yields StreamEvent objects instead of strings. Each final_transcript is one speaker's settled turn and replaces the partials of its item_id:
items = {} # item_id -> (speaker_id, text)
for event in client.asr.transcribe_stream(pcm16_chunks(), language="ja", diarization=True, timestamps=True):
item_id = event.metadata["item_id"]
if event.type == "partial_transcript":
if item_id is not None:
speaker, text = items.get(item_id, (event.speaker_id, ""))
items[item_id] = (event.speaker_id, text + event.text)
elif event.text: # final_transcript: the settled turn
items[item_id] = (event.speaker_id, event.text)
print(event.speaker_id, event.metadata.get("start_ms"), event.metadata.get("end_ms"), event.text)
else: # an empty final retires a provisional item
items.pop(item_id, None)turn_detection, keywords, timestamps and style_preference are keyword arguments of transcribe_stream(). Leave turn_detection unset to use the deployment default above. style_preference={"verbatim": False} needs kotoba-sdk 0.3.3 or newer.
Billing is per second of input audio. See the model page for the current rate.
Any WebSocket client works with this endpoint. The examples use ws for Node.js and websockets for Python.
npm install wsSet FAL_KEY as an environment variable in your runtime.
export FAL_KEY="YOUR_API_KEY"This endpoint speaks its own message protocol over a WebSocket. Open the connection with any WebSocket client and authenticate the upgrade with the Authorization: Key header. Browsers must not hold the API key: connect through your own server, which adds the header. The message protocol itself is documented in the model's About section.
import WebSocket from "ws";
// Keep the API key on your server; a browser connects through your
// own backend, which adds the header. Use the "ws" package: Node's
// global WebSocket ignores the headers option and the upgrade gets 401.
const ws = new WebSocket("wss://fal.run/kotoba-technologies/kotoba-streaming-stt/v1/realtime", {
headers: { Authorization: "Key " + process.env.FAL_KEY },
});
ws.on("open", () => {
// Send the app's first message here.
});
ws.on("message", (data, isBinary) => {
if (isBinary) return; // binary frame, e.g. audio
console.log(data.toString()); // the app's messages, shown as text
});
ws.on("error", console.error);The API uses an API Key for authentication. Read it from the FAL_KEY environment variable on your server and send it as the Authorization: Key <FAL_KEY> header on the WebSocket upgrade, as the real-time snippet above does.
Some attributes in the API accept file URLs as input. Whenever that's the case you can pass your own URL or a Base64 data URI.
You can pass a Base64 data URI as a file input. The API will handle the file decoding for you. Keep in mind that for large files, this alternative although convenient can impact the request performance.
You can also pass your own URLs as long as they are publicly accessible. Be aware that some hosts might block cross-site requests, rate-limit, or consider the request as a bot.
We provide a convenient file storage that allows you to upload files and use them in your requests. You can upload files using the client API and use the returned URL in your requests.
import { fal } from "@fal-ai/client";
const file = new File(["Hello, World!"], "hello.txt", { type: "text/plain" });
const url = await fal.storage.upload(file);Read more about file handling in our file upload guide.