kotoba-technologies/kotoba-sts/v1/realtime_voice
Loading API documentation
Kotoba STS translates speech into speech over a WebSocket connection. Stream audio in and receive the translated text and the translated speech on the same connection, with latency low enough for a live conversation. One session translates in one direction.
Endpoint
wss://fal.run/Kotoba-Technologies/kotoba-sts/v1/realtime_voiceThe Playground offers a one-shot demo (POST /v1/speech-to-speech) that translates one uploaded clip. It is bounded for demos. Production integrations use the WebSocket endpoint described below.
Every pair of the four languages is supported (●). Rows are the spoken language (language); columns are the translation (target_language).
| Input \ Output | Japanese (ja) | English (en) | Korean (ko) | Mandarin Chinese (zh) |
|---|---|---|---|---|
Japanese (ja) | — | ● | ● | ● |
English (en) | ● | — | ● | ● |
Korean (ko) | ● | ● | — | ● |
Mandarin Chinese (zh) | ● | ● | ● | — |
Send JSON messages over the WebSocket. Open the session with one voice_session.update message, then wait for voice_session.updated, which echoes the applied settings.
{
"type": "voice_session.update",
"session": {
"input_audio_format": "pcm16",
"input_audio_sample_rate": 24000,
"input_audio_transcription": {"language": "ja", "target_language": "en"}
}
}| Setting | Type and values | Default | Behavior |
|---|---|---|---|
session.input_audio_transcription.language | string: "ja", "en", "ko" or "zh" | required | Language spoken in the audio. |
session.input_audio_transcription.target_language | string: "ja", "en", "ko" or "zh" | required | Language to translate into. See the pairs above. |
session.input_audio_format | string: "pcm16", "float32" or "twilio" | "pcm16" | pcm16 and float32 are raw little-endian samples; twilio is 8 kHz mu-law. |
session.input_audio_sample_rate | integer | 24000 | Sample rate of the input. Other rates are resampled server-side; twilio is always 8000. |
session.input_audio_number_of_channels | integer | 1 | Interleaved multi-channel input is mixed down to mono. |
session.turn_detection | false | false | The session translates one continuous stream; there is no turn detection. |
Then send audio, base64-encoded:
{"type": "input_audio_buffer.append", "audio": "<base64 PCM16>"}Field values below are illustrative.
{"type": "voice_session.updated", "session": {"...": "..."}}
{"type": "conversation.item.input_audio_transcription.text.delta", "item_id": "...", "delta": "Good morning."}
{"type": "conversation.item.input_audio_transcription.audio.delta", "item_id": "...", "delta": "<base64 PCM16, 24 kHz, mono>"}
{"type": "input_audio_buffer.committed"}text.delta carries the translated text. Concatenate the deltas; an empty delta carries nothing.audio.delta carries the translated speech as 16-bit PCM at 24 kHz, mono. Play or append it in order.Send a commit after the last audio:
{"type": "input_audio_buffer.commit"}The commit ends the session. The server translates the remaining audio, sends input_audio_buffer.committed, and closes the connection with code 1000 a few seconds later.
The translated speech trails the speaker by a few seconds. To keep the end of the translation, keep sending silence after the speaker stops until the translated speech has finished, then commit.
{"type": "error", "error": "session_sts_quota_exceeded"}. Open a new session to continue.system_busy). Retry with backoff.{"error": {"type": "invalid_request_error", "code": "...", "message": "...", "param": "<field>"}}. An unsupported language (invalid_languages) closes the connection; for other invalid settings, send a corrected voice_session.update on the same connection.{"type": "error", "error": "<message>"}.GET https://fal.run/Kotoba-Technologies/kotoba-sts/model_and_cuda_availability (same Authorization: Key header) or allow for it in the first connection's timeout.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_S2ST_URL=wss://fal.run/Kotoba-Technologies/kotoba-sts/v1/realtime_voiceLive microphone: send audio and read results concurrently, so translated speech starts while the microphone is still open.
import asyncio
from kotoba import AsyncKotobaClient
async def main():
client = AsyncKotobaClient()
async with client.s2st.stream(src="ja", tgt="en") as session:
async def feed():
async for chunk in mic_chunks(): # PCM16 chunks at 24 kHz from the microphone
await session.send_audio(chunk)
await session.commit()
feeder = asyncio.create_task(feed())
async for event in session:
if event.type == "partial_transcript": # translated text
print(event.text, end="", flush=True)
elif event.type == "audio_chunk": # translated speech
await play(event.audio)
elif event.type == "done":
break
feeder.cancel()
asyncio.run(main())client.s2st.translate("meeting_ja.wav", src="ja", tgt="en") translates a file and returns a result with to_wav(). It commits right after the file ends, so add a few seconds of silence to the end of the file to keep the last words.
Billing is per second of input audio sent on the session, silence included. 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-sts/v1/realtime_voice", {
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.