Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.voiceos.com/llms.txt

Use this file to discover all available pages before exploring further.

This example uses the built-in fetch, FormData, and Blob APIs available in modern Node.js and Bun.
import { readFile } from "node:fs/promises";

const audio = await readFile("sample.mp3");

const messages = [
  {
    role: "system",
    content: "You are helping inside a TypeScript codebase."
  },
  {
    role: "user",
    content:
      "The user may say SessionStreamService.ts, promptableTranscription.ts, or VOICEOS_TEAM_API_KEY."
  }
];

const form = new FormData();
form.append("file", new Blob([audio], { type: "audio/mpeg" }), "sample.mp3");
form.append("messages", JSON.stringify(messages));
form.append("languages", JSON.stringify("en"));
form.append("dictionary", JSON.stringify(["VoiceOS", "providerFallback"]));
form.append("response_format", "json");

const response = await fetch("https://beta.api.voiceos.com/v1/audio/transcriptions", {
  method: "POST",
  body: form
});

if (!response.ok) {
  throw new Error(`VoiceOS API failed: ${response.status} ${await response.text()}`);
}

const result = await response.json();
console.log(result.text);

Production-ready wrapper

export async function transcribePromptable({ audioPath, messages = [], languages = "auto", dictionary = [] }) {
  const audio = await readFile(audioPath);
  const form = new FormData();

  form.append("file", new Blob([audio], { type: "audio/mpeg" }), audioPath);
  if (messages.length > 0) {
    form.append("messages", JSON.stringify(messages));
  }
  form.append("languages", JSON.stringify(languages));
  if (dictionary.length > 0) {
    form.append("dictionary", JSON.stringify(dictionary));
  }
  form.append("response_format", "json");

  const response = await fetch("https://beta.api.voiceos.com/v1/audio/transcriptions", {
    method: "POST",
    body: form
  });

  const body = await response.json();

  if (!response.ok) {
    const message = body?.error?.message || "Transcription failed";
    throw new Error(message);
  }

  return body;
}