Skip to content
VelosyllOpen studio

Transcribe and translate a file with Node.js

Queue an English recording, export its WebVTT captions, and turn a transcript excerpt into Spanish text and audio.

Before you start

  • Node.js 22.17 or newer, npm and an empty project directory.
  • A running Velosyll service with its local models, project credits, and a project API key issued by a workspace owner.

1. Connect to the local service

Run these shell commands in an empty folder. At the read command, paste your project key and press Enter. The SDK archive and English reading are downloaded from your Velosyll installation. The Node client uses built-in modules.

Configure your shell and install the SDK · bash
export VELOSYLL_URL=http://127.0.0.1:8464
read -rs VELOSYLL_API_KEY
export VELOSYLL_API_KEY
printf '\n'
npm init -y
curl -fSLo "velosyll-node-0.1.0.tgz" "$VELOSYLL_URL/sdk/downloads/velosyll-node-0.1.0.tgz"
npm install --offline --no-audit --no-fund "./velosyll-node-0.1.0.tgz"
curl -fSLo reading.wav "$VELOSYLL_URL/assets/studio-session.wav"

2. Save the transcription program

Save this file alongside package.json. submit returns a job ID. wait polls once per second, stops on completed or failed, and aborts after ten minutes. The raw response option returns the caption export as bytes.

File transcription and WebVTT export · javascriptDownload transcribe-file.mjs
import { mkdir, writeFile } from "node:fs/promises";
import { VelosyllClient } from "@velosyll/node";

async function main() {
  const api = new VelosyllClient();
  const input = process.argv[2];
  if (!input || (input === "--job" && !process.argv[3])) {
    throw new Error("Pass an English audio file, or --job JOB_ID.");
  }
  const id = input === "--job"
    ? process.argv[3]
    : (await api.submit(input, { language: "en" })).id;
  console.log("Job ID:", id);
  const job = await api.wait(id, { timeoutMs: 600_000, intervalMs: 1_000 });
  const path = "/v1/transcriptions/" + encodeURIComponent(id) + "/export?format=vtt";
  const captions = await api.request(path, { audio: true });
  await mkdir("velosyll-output", { recursive: true });
  await writeFile("velosyll-output/transcript.txt", job.result.text, "utf8");
  await writeFile("velosyll-output/captions.vtt", captions);
  console.log(job.result.text);
}

main().catch(error => {
  console.error(error.message);
  process.exitCode = 1;
});

3. Run it and verify the transcript

The program prints the job ID and transcript, then writes transcript.txt and captions.vtt in velosyll-output. A WebVTT export starts with WEBVTT. To poll an existing job, use the second command with its printed ID.

Transcribe the included English recording · bash
node transcribe-file.mjs reading.wav
head -n 3 velosyll-output/captions.vtt
Resume an existing job · bash
node transcribe-file.mjs --job JOB_ID

4. Add translation, key points and stock speech

This second program takes the first 240 Unicode characters of the transcript. It translates that excerpt, extracts source-linked English key points and synthesizes the Spanish translation using the default stock voice.

Work with the transcript excerpt · javascriptDownload transcript-tools.mjs
import { readFile, writeFile } from "node:fs/promises";
import { VelosyllClient } from "@velosyll/node";

async function main() {
  const api = new VelosyllClient();
  const input = await readFile("velosyll-output/transcript.txt", "utf8");
  const excerpt = Array.from(input.trim()).slice(0, 240).join("");
  if (!excerpt) throw new Error("The transcript contains no speech.");
  const translated = await api.translate(excerpt, "en", "es");
  const notes = await api.request("/v1/notes", {
    method: "POST", json: { text: excerpt, language: "en", task: "key_points" },
  });
  const speech = await api.speak(translated.text, "es", { format: "wav" });
  await writeFile("velosyll-output/spanish.txt", translated.text, "utf8");
  await writeFile("velosyll-output/key-points.json", JSON.stringify(notes, null, 2));
  await writeFile("velosyll-output/spanish.wav", speech);
  console.log(translated.text);
  console.log(notes.result);
}

main().catch(error => {
  console.error(error.message);
  process.exitCode = 1;
});

5. Verify the language outputs

Run the program once, open spanish.txt, inspect result and evidence in key-points.json, and play spanish.wav. Each run makes one translation, one Scribe and one speech request against the project's local credits.

Run the language tools · bash
node transcript-tools.mjs
ls -lh velosyll-output

Expected result

A completed file job, timed captions, an excerpt translated to Spanish, source-linked notes and playable WAV audio.

Troubleshooting

The upload returned HTTP 401.
Use the project API key shown in the studio console for this installation. A revoked or expired key needs replacing.
The polling deadline passed.
Copy the job ID printed before polling began and use the --job command. Jobs can finish after the client exits.
The job entered the failed state.
Read the failure detail printed by the script. A failed job is terminal. After correcting the media or configuration, submit a new job.
A request returned 402, 422, 429 or 503.
Check project credits for 402. Check the input and language code for 422. Check the project quota or service capacity for 429. Check the local worker and installed model files for 503.

Explore further