JavaScript Speech-to-Text API

Transcribe audio from Node.js or the browser with fetch or the OpenAI Node SDK. Stream segments in real time with SSE.

  • OpenAI Node SDK compatible — change baseURL only
  • fetch or FormData for browser and Node transcription
  • Server-Sent Events streaming for real-time segments
  • Flat-rate pricing from $19 every 4 weeks

Install

npm install openai

OpenAI Node SDK

Set baseURL to Privocio for drop-in Whisper compatibility.

import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: process.env.PRIVOCIO_API_KEY!,
  baseURL: "https://api.privocio.com/v1",
});

const file = await fs.openAsBlob("recording.wav");
const transcript = await openai.audio.transcriptions.create({
  model: "whisper-1",
  file,
  language: "en",
});

console.log(transcript.text);

fetch batch transcription

const API_BASE = "https://api.privocio.com";
const API_KEY = process.env.PRIVOCIO_API_KEY!;

const form = new FormData();
form.append("file", audioBlob, "recording.wav");
form.append("model", "whisper-1");
form.append("language", "en");

const res = await fetch(`${API_BASE}/v1/transcriptions`, {
  method: "POST",
  headers: { Authorization: `Bearer ${API_KEY}` },
  body: form,
});

if (!res.ok) {
  const err = await res.json().catch(() => ({}));
  throw new Error(JSON.stringify(err));
}

const data = await res.json();
console.log(data.text);

Streaming (SSE)

Real-time segment delivery — see streaming docs.

const form = new FormData();
form.append("file", audioFile);
form.append("model", "whisper-1");

const res = await fetch("https://api.privocio.com/v1/transcriptions/stream", {
  method: "POST",
  headers: { Authorization: "Bearer YOUR_API_KEY" },
  body: form,
});

const reader = res.body!.getReader();
const decoder = new TextDecoder();
let buffer = "";

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  buffer += decoder.decode(value, { stream: true });

  while (buffer.includes("\n\n")) {
    const idx = buffer.indexOf("\n\n");
    const block = buffer.slice(0, idx);
    buffer = buffer.slice(idx + 2);

    const match = block.match(/^event: (.+)\ndata: (.+)$/s);
    if (!match) continue;

    const [, event, data] = match;
    const parsed = JSON.parse(data);

    if (event === "segment") {
      console.log(parsed.text);
    }
  }
}

Migrate from OpenAI Whisper

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.PRIVOCIO_API_KEY!,
  baseURL: "https://api.privocio.com/v1", // ← only change
});

const transcript = await client.audio.transcriptions.create({
  model: "whisper-1",
  file: await fs.openAsBlob("meeting.mp3"),
});

Step-by-step guide: migrate from OpenAI Whisper.