Developer Reference
Audio
Turn speech into text, and text into speech.
Updated November 2026
Speech to text
For voice input, dictation and meeting notes, Chabi serves OpenAI's transcription API at https://chabi.dev/v1/audio/transcriptions with gpt-transcribe. Same SDK, base URL and user token as REQUESTS.
Send a WAV file
With @chabi/js
import OpenAI from "openai";import fs from "node:fs";const client = new OpenAI(chabi.openai()); // chabi from @chabi/js/nodeconst { text } = await client.audio.transcriptions.create({file: fs.createReadStream("meeting.wav"),model: "gpt-transcribe",language: "en", // optional: the spoken language, if you know it});
Without the SDK: the user's token as the API key
import OpenAI from "openai";import fs from "node:fs";const client = new OpenAI({ baseURL: "https://chabi.dev/v1", apiKey: userToken });const { text } = await client.audio.transcriptions.create({file: fs.createReadStream("meeting.wav"),model: "gpt-transcribe",language: "en", // optional: the spoken language, if you know it});
curl https://chabi.dev/v1/audio/transcriptions \-H "Authorization: Bearer $USER_TOKEN" \-F model=gpt-transcribe \-F file=@meeting.wav
Record in the browser
Chabi charges by the length of the audio, which it reads from the WAV header, so it only accepts uncompressed WAV. Browsers record webm or mp4, so convert the recording before sending it:
With @chabi/js
import OpenAI from "openai";const client = new OpenAI({ ...chabi.openai(), dangerouslyAllowBrowser: true });// A recording (Blob) from MediaRecorder → 16 kHz mono 16-bit WAV.async function toWav(blob) {const ctx = new AudioContext({ sampleRate: 16000 });const audio = await ctx.decodeAudioData(await blob.arrayBuffer());ctx.close();const pcm = audio.getChannelData(0);const v = new DataView(new ArrayBuffer(44 + pcm.length * 2));const str = (at, s) => [...s].forEach((c, i) => v.setUint8(at + i, c.charCodeAt(0)));str(0, "RIFF"); v.setUint32(4, 36 + pcm.length * 2, true);str(8, "WAVE"); str(12, "fmt "); v.setUint32(16, 16, true);v.setUint16(20, 1, true); // PCMv.setUint16(22, 1, true); // monov.setUint32(24, 16000, true); // samples per secondv.setUint32(28, 32000, true); // bytes per secondv.setUint16(32, 2, true); // bytes per samplev.setUint16(34, 16, true); // bits per samplestr(36, "data"); v.setUint32(40, pcm.length * 2, true);pcm.forEach((s, i) => v.setInt16(44 + i * 2, Math.max(-1, Math.min(1, s)) * 0x7fff, true));return new File([v], "speech.wav", { type: "audio/wav" });}const mic = await navigator.mediaDevices.getUserMedia({ audio: true });const recorder = new MediaRecorder(mic);const parts = [];recorder.ondataavailable = (e) => parts.push(e.data);recorder.onstop = async () => {const { text } = await client.audio.transcriptions.create({file: await toWav(new Blob(parts)),model: "gpt-transcribe",});};recorder.start(); // call recorder.stop() when the user is done
Without the SDK: the user's token as the API key
import OpenAI from "openai";const client = new OpenAI({ baseURL: "https://chabi.dev/v1", apiKey: userToken, dangerouslyAllowBrowser: true });// A recording (Blob) from MediaRecorder → 16 kHz mono 16-bit WAV.async function toWav(blob) {const ctx = new AudioContext({ sampleRate: 16000 });const audio = await ctx.decodeAudioData(await blob.arrayBuffer());ctx.close();const pcm = audio.getChannelData(0);const v = new DataView(new ArrayBuffer(44 + pcm.length * 2));const str = (at, s) => [...s].forEach((c, i) => v.setUint8(at + i, c.charCodeAt(0)));str(0, "RIFF"); v.setUint32(4, 36 + pcm.length * 2, true);str(8, "WAVE"); str(12, "fmt "); v.setUint32(16, 16, true);v.setUint16(20, 1, true); // PCMv.setUint16(22, 1, true); // monov.setUint32(24, 16000, true); // samples per secondv.setUint32(28, 32000, true); // bytes per secondv.setUint16(32, 2, true); // bytes per samplev.setUint16(34, 16, true); // bits per samplestr(36, "data"); v.setUint32(40, pcm.length * 2, true);pcm.forEach((s, i) => v.setInt16(44 + i * 2, Math.max(-1, Math.min(1, s)) * 0x7fff, true));return new File([v], "speech.wav", { type: "audio/wav" });}const mic = await navigator.mediaDevices.getUserMedia({ audio: true });const recorder = new MediaRecorder(mic);const parts = [];recorder.ondataavailable = (e) => parts.push(e.data);recorder.onstop = async () => {const { text } = await client.audio.transcriptions.create({file: await toWav(new Blob(parts)),model: "gpt-transcribe",});};recorder.start(); // call recorder.stop() when the user is done
- Up to 25 MB per file: about 13 minutes of 16 kHz mono 16-bit audio, which is all speech needs. For anything longer, record in chunks (say 30 seconds each) and send them as you go, so text appears while the user talks.
- It costs 0.675 credits per minute of audio, rounded up to the second (see MODEL NOTES). Chabi knows the cost before it calls the provider, so it holds exactly that. Silence costs the same as speech: skip chunks with nothing in them.
- Optional fields:
language(an ISO code such asen),prompt(names and terms to spell right) andresponse_format:json(default,{ text }),text,srtorvtt. Streaming isn't supported. - Compressed audio (webm, mp4, mp3, ogg…) gets 400
unsupported_audio_format. In Node or Electron, record PCM yourself or convert files with ffmpeg:ffmpeg -i in.m4a -ac 1 -ar 16000 out.wav.
Text to speech
To read text aloud, Chabi serves OpenAI's speech API at https://chabi.dev/v1/audio/speech, with OpenAI's voices: gpt-realtime-2.1-mini, gpt-realtime-2.1. Same SDK, base URL and user token as REQUESTS. Behind it, an OpenAI Realtime model reads your text word for word.
With @chabi/js
import OpenAI from "openai";const client = new OpenAI(chabi.openai()); // chabi from @chabi/js/nodeconst speech = await client.audio.speech.create({model: "gpt-realtime-2.1-mini",voice: "marin",input: "Your order is ready for pickup.",instructions: "Warm and friendly.", // optional: how it sounds, never what it says});const mp3 = Buffer.from(await speech.arrayBuffer());
Without the SDK: the user's token as the API key
import OpenAI from "openai";const client = new OpenAI({ baseURL: "https://chabi.dev/v1", apiKey: userToken });const speech = await client.audio.speech.create({model: "gpt-realtime-2.1-mini",voice: "marin",input: "Your order is ready for pickup.",instructions: "Warm and friendly.", // optional: how it sounds, never what it says});const mp3 = Buffer.from(await speech.arrayBuffer());
from openai import OpenAIclient = OpenAI(base_url="https://chabi.dev/v1", api_key=user_token)with client.audio.speech.with_streaming_response.create(model="gpt-realtime-2.1-mini", voice="marin", input="Your order is ready for pickup.",) as speech:speech.stream_to_file("speech.mp3")
curl https://chabi.dev/v1/audio/speech \-H "Authorization: Bearer $USER_TOKEN" \-H "Content-Type: application/json" \-d '{"model": "gpt-realtime-2.1-mini", "voice": "marin", "input": "Hello!", "response_format": "wav"}' \-o hello.wav
- Models:
gpt-realtime-2.1-mini, orgpt-realtime-2.1for higher quality at about three times the price. OpenAI's owntts-1,tts-1-hdandgpt-4o-mini-ttsaren't served (OpenAI shuts them down on 2027-01-06): usegpt-realtime-2.1-mini. - Voices:
alloy,ash,ballad,coral,echo,sage,shimmer,verse,marin,cedar.marinandcedarsound best. Custom voices aren't supported. inputup to 4,096 characters (about four minutes of speech). Send plain text: markdown and code symbols aren't read well, and long strings of digits (tracking numbers, long numbers) can be misread, so spell them out or group them.response_format:mp3,opus,aac,flac,wav,pcm(mp3by default).wavandpcmstart fastest;pcmis raw 24 kHz 16-bit mono little-endian with no header. Audio streams as it's generated, so playback can start in about a second.- Optional:
instructions(a style such as "calm narrator": it changes how it sounds, never what it says) andspeed(0.25 to 1.5).stream_format: "sse"isn't supported. - It costs credits by what each request actually used, about 3.77 credits a minute of speech on
gpt-realtime-2.1-mini(see MODEL NOTES). Chabi holds the most a text could cost first, so a long text needs more credits free than it ends up using.