SDKs
The official SDKs for JavaScript and Python: install, a first request, and what they handle for you
Voice213 has official SDKs for JavaScript and TypeScript, and for Python. They cover the whole developer API: voice-overs, KhasbhaSTT transcription, KhasbhaSTT LIVE sessions, the catalogue of voices, tones and models, and your account. Both have the same methods, named the way each language names things, so an example in one reads like the other.
| JavaScript & TypeScript | Python | |
|---|---|---|
| Package | @voice213/sdk on npm | voice213 on PyPI |
| Runs on | Node.js 18+, Bun, Deno and edge runtimes, with ES modules or CommonJS. Live sessions in the browser too | Python 3.9+, with a synchronous client and an asynchronous one |
| Client | new Voice213() | Voice213(), or AsyncVoice213() for asyncio |
| Guide | JavaScript & TypeScript | Python |
Install
pip install voice213npm install @voice213/sdkThen set your API key in the VOICE213_API_KEY environment variable on your server: see Get Your API Key.
A first request
The same voice-over and transcription in both languages:
from voice213 import Voice213
client = Voice213() # reads VOICE213_API_KEY
speech = client.text_to_speech.create("مرحبا بيكم في Voice213", voice="kenza", model="voice213-pro-2")
speech.save("welcome.mp3")
print(f"{speech.cost} {speech.currency}, {speech.remaining_credit} left")
transcript = client.speech_to_text.transcribe("call.mp3", language="ar", dialect="algerian")
print(transcript.text)import Voice213 from "@voice213/sdk";
const voice213 = new Voice213(); // reads VOICE213_API_KEY
const speech = await voice213.textToSpeech.create({ text: "مرحبا بيكم في Voice213", voice: "kenza", model: "voice213-pro-2" });
await speech.save("welcome.mp3");
console.log(`${speech.cost} ${speech.currency}, ${speech.remainingCredit} left`);
const transcript = await voice213.speechToText.transcribe({ file: "call.mp3", language: "ar", dialect: "algerian" });
console.log(transcript.text);What they handle for you
- Your key. The client reads it from
VOICE213_API_KEY, or takes the one you pass, and sends it with every request. A missing key fails before anything is sent, with the codeMISSING_API_KEY. - Both voice-over formats. A voice-over comes back as a link to an MP3 or, with
inline, as a WAV inside the answer. Either way you get oneSpeech, with its cost and your remaining credit, andsave()writes the audio to a file. - Files.
transcribe()uploads a recording from a path or its bytes, with its name and type, or sends the link to one that's already online. - Long requests. The client waits up to 10 minutes for an answer, enough for a long script on a Pro model or a recording near the 30-minute limit. In Node.js, the JavaScript SDK isn't cut off after 5 minutes, as the built-in
fetchis. - Safe retries. Rate limits, maintenance and failures that cost nothing are retried twice, after the API's
Retry-Afteror with exponential backoff. A voice-over or a transcription that may have reached Voice213, but whose answer never came, isn't sent again, so you're never charged twice. See Handle errors and retry safely. - Clear errors. Every error has a class for its status and a
codeto branch on, such asINSUFFICIENT_CREDITorRATE_LIMIT_DAY, with an English message even when the API's own is in Arabic. - Live sessions.
connect()creates the single-use token and opens the socket. A session streams a WAV file at real-time pace, or your own audio, and keeps the transcript, final sentences and the one being spoken. In the browser, the JavaScript SDK captures the microphone at 16 kHz for you. - Types. TypeScript types in the JavaScript SDK, typed results in the Python one, with the docs in your editor.
The answers follow the API Reference, without success. The voices and tones come out of the data the API wraps them in, and your account is flattened to credit, currency and key. In Python, every name is in snake_case: remainingCredit is remaining_credit.
Keep the key on your server
The SDKs run on your server, where your API key is safe. The JavaScript client refuses to run in a web page, with the code BROWSER_NOT_ALLOWED: a key there would be readable by every visitor. For live transcription in a browser, your server creates a token with the key, and the page opens the session with LiveSession, which never needs the key. See Live transcription in a browser.
Other languages
From any other language, call the API over HTTP: every endpoint page has a cURL example of the request, and Live Transcription Socket describes the protocol of a live session, message by message.
Next steps
Was this page helpful?