技能圖譜SKILLSGROVE
技能圖譜/影片製作/vocalstack/js-sdk/vocalstack

vocalstack

安裝

$npx skills add https://github.com/vocalstack/js-sdk --skill vocalstack
$git clone --depth 1 https://github.com/vocalstack/js-sdk.git /tmp/js-sdk && mkdir -p ~/.claude/skills && cp -r /tmp/js-sdk/. ~/.claude/skills/vocalstack
請幫我安裝這個 Agent Skill:https://github.com/vocalstack/js-sdk/tree/0461f970445a615cc6c6035ed69cc7d11910bb88/ ,先閱讀它的 SKILL.md 和指令碼,確認安全後再安裝到我的技能目錄。

簡介

原文描述 · MITUse when writing Node or TypeScript code that calls the VocalStack speech API with @vocalstack/js-sdk, for example to transcribe an audio or video URL or a local file, stream live audio for realtime transcription, fetch or export a transcript (JSON, SRT, XLSX, PDF), or search transcripts. Covers installing, API keys, base URLs, five copy-paste programs and error handling (401, 402, 403, 429).
以下 SKILL.md 內容轉載自 vocalstack/js-sdk(提交 0461f97),依據 MIT 許可證轉載正文(文字未改動;僅省略檔案頭後設資料、將圖片顯示為連結,超長內容會截斷);版權歸 2026 VocalStack 所有。許可證:LICENSE。僅展示說明檔案,附帶指令碼請在原倉庫檢視。

VocalStack TypeScript SDK

The VocalStack API transcribes speech (files, links, live audio), with speaker labels and translation. @vocalstack/js-sdk has one client, VocalStack, with one group per resource: vs.transcriptions, vs.broadcasts, vs.search, vs.realtime and a few more (listed at the end).

What is what

  • A transcription is a file, a link, a microphone or a stream, transcribed and stored. Create one with vs.transcriptions.create(...). Its id is all you need: vs.transcriptions.transcript(id) reads the transcript, however often a live one was paused and resumed.
  • A job is a file or link transcription's work: vs.transcriptions.waitForJob(id) polls it until it is done or failed ({ onProgress: (job) => … } sees each read: job.state, job.progress.pct).
  • A broadcast is a link listeners open to follow live transcriptions. Each vs.broadcasts.record(id) starts a new live transcription.
  • A realtime session (vs.realtime) is a socket you stream audio into and read the transcript from. Nothing is stored. "Session" means only this.

Install

npm init -y && npm pkg set type=module   # in a new folder: the programs below are ESM
npm i @vocalstack/js-sdk                    # Node 20 or newer

To run code newer than the npm release, install it from a clone of https://github.com/vocalstack/js-sdk. Build it first (npm run build also builds the bundled contract/ package):

git clone https://github.com/vocalstack/js-sdk && (cd js-sdk && npm install && npm run build)
npm i ./js-sdk

Use ESM ("type": "module" in package.json, or .mjs files).

Speaker numbers start at 0. A speaker of -1 means speaker labels were off for that transcription, so print the text without a speaker.

Auth and base URL

  • Read the key from VOCALSTACK_API_KEY and pass it as apiKey. It goes out as Authorization: Bearer <key>, also on sockets.
  • An API key starts with vs_key_. There is one kind of key: every call is real usage on the account's tier and quotas.
  • Keys are for servers. Never put a key in browser code or in a URL. The API refuses a key sent from a web page (Origin header) or in a query string.
  • Scopes: read (read transcripts, search, export), write and recordings:publish (create transcriptions, stream live audio), or *.
  • Base URL: https://api.vocalstack.com (the default). Override it with VOCALSTACK_BASE_URL (for example, a local or staging server).

Every program below starts like this:

import { VocalStack } from '@vocalstack/js-sdk';
const vs = new VocalStack({
  baseUrl: process.env.VOCALSTACK_BASE_URL, // absent: https://api.vocalstack.com
  apiKey: process.env.VOCALSTACK_API_KEY,
});

1. Transcribe a URL and wait for the result

The server fetches the link itself, so it must be a public http(s) address. Private, loopback and cloud-metadata addresses are refused.

import { VocalStack } from '@vocalstack/js-sdk';
const vs = new VocalStack({ baseUrl: process.env.VOCALSTACK_BASE_URL, apiKey: process.env.VOCALSTACK_API_KEY });

const tx = await vs.transcriptions.create({
  url: 'https://raw.githubusercontent.com/openai/whisper/main/tests/jfk.flac',
  name: 'JFK sample',
});

// queued -> fetching -> transcribing -> done | failed
const job = await vs.transcriptions.waitForJob(tx.id);
if (job.state !== 'done') throw new Error(`transcription ${job.state}: ${job.error}`);

const { sentences } = await vs.transcriptions.transcript(tx.id);
for (const s of sentences) console.log(s.speaker >= 0 ? `[speaker ${s.speaker}] ${s.text}` : s.text);
console.log('transcription', tx.id);

2. Transcribe a local file

import { VocalStack } from '@vocalstack/js-sdk';
const vs = new VocalStack({ baseUrl: process.env.VOCALSTACK_BASE_URL, apiKey: process.env.VOCALSTACK_API_KEY });

const tx = await vs.transcriptions.create({
  file: process.argv[2], // a path (mp3, wav, flac, ogg, m4a, mp4 ...), a Blob or bytes
  settings: { spokenLanguage: 'en', speakerLabels: 'on' }, // both optional; speakerLabels: 'auto' (default) | 'on' | 'off'
  // Off unless asked for: settings.summary, settings.title, settings.summaryTranslations,
  // settings.translationTts (text-to-speech of translations), and shareLink: true (a public share link).
});
const job = await vs.transcriptions.waitForJob(tx.id);
if (job.state !== 'done') throw new Error(`transcription ${job.state}: ${job.error}`);

const { sentences } = await vs.transcriptions.transcript(tx.id);
console.log(sentences.map((s) => s.text).join(' '));

3. Fetch a transcript or an export file

transcriptions.transcript returns segments (with word timings), sentences and speakers. transcriptions.export returns the file as a Response: formats json, srt, xlsx, pdf; add { lang: '<code>' } for a translated file.

import { writeFile } from 'node:fs/promises';
import { VocalStack } from '@vocalstack/js-sdk';
const vs = new VocalStack({ baseUrl: process.env.VOCALSTACK_BASE_URL, apiKey: process.env.VOCALSTACK_API_KEY });
const id = process.argv[2];

const snap = await vs.transcriptions.transcript(id);
console.log(`${snap.segments.length} segments, ${snap.sentences.length} sentences, state ${snap.state}`);

const res = await vs.transcriptions.export(id, 'srt');
await writeFile('transcript.srt', Buffer.from(await res.arrayBuffer()));

4. Live transcription from a microphone or a file

A live transcription takes raw PCM: 32-bit float little-endian, 16 kHz, mono. Create it, start it, and open the publisher socket the grant names. Here ffmpeg decodes a file at realtime speed (-re). For a microphone, swap the input: -f avfoundation -i :0 on macOS, -f pulse -i default on Linux. (@vocalstack/js-sdk/mic is for browsers, and browsers must not hold API keys.)

import { spawn } from 'node:child_process';
import { VocalStack } from '@vocalstack/js-sdk';
const vs = new VocalStack({ baseUrl: process.env.VOCALSTACK_BASE_URL, apiKey: process.env.VOCALSTACK_API_KEY });

const tx = await vs.transcriptions.createLive({ name: 'Live demo', settings: { spokenLanguage: 'en' } });
const grant = await vs.transcriptions.start(tx.id);
const stream = await vs.transcriptions.publish(grant, { readyDeadlineMs: 180_000 }); // a cold engine can take a while

const ff = spawn('ffmpeg', ['-loglevel', 'error', '-re', '-i', process.argv[2],
  '-f', 'f32le', '-ac', '1', '-ar', '16000', '-']);
ff.stdout.on('data', (chunk) => stream.sendAudio(new Uint8Array(chunk)));
ff.on('close', () => stream.eof()); // eof() ends the transcription

for await (const ev of stream) {
  if (ev.type === 'transcript.committed') console.log(`[speaker ${ev.segment.speaker}] ${ev.segment.text}`);
  // also: 'transcript.draft' (replaces the live tail), 'transcript.sentence', 'transcript.translated'
}

// vs.transcriptions.pause(tx.id) and resume(tx.id) keep it one transcript; stop(tx.id) ends it without eof().
const { sentences } = await vs.transcriptions.transcript(tx.id);
console.log('final:', sentences.map((s) => s.text).join(' '));

To transcribe without storing anything, use a realtime session instead: await vs.realtime.transcribeFile('talk.mp3') returns { text, segments }.

5. Search transcripts

import { VocalStack } from '@vocalstack/js-sdk';
const vs = new VocalStack({ baseUrl: process.env.VOCALSTACK_BASE_URL, apiKey: process.env.VOCALSTACK_API_KEY });

const { hits } = await vs.search.query(process.argv[2] ?? 'country', { limit: 5 }); // q: 2+ characters
for (const h of hits) {
  console.log(`${h.linkName} @ ${h.mediaStart.toFixed(1)}s [speaker ${h.speaker}]: ${h.text} (transcription ${h.transcriptionId})`);
}

By meaning, in any language, even with none of the words (vector search). Each hit's passage is its whole paragraph: give the passages to your own model as context to answer questions about what was said (RAG). Pay as you go counts 60 an hour (allowance); Premium and Enterprise have no limit.

const { hits: found } = await vs.search.vector('how much does housing cost');
for (const h of found) console.log(h.similarity.toFixed(2), h.passage.mediaStart, h.passage.text);

Errors

A failed call throws VocalStackError with code, message, status, retryable, details (the body's data.details), headers and retryAfter (seconds, from Retry-After). A 429, and a 503 unavailable on a call that is safe to repeat, is retried for you after its Retry-After, twice by default (maxRetries on the client).

Status code What to do
401 invalid_token, key_expired, key_revoked Check VOCALSTACK_API_KEY. Use the replacement key, or create a new one.
403 forbidden Usually a missing scope: the message names it, and err.headers.get('www-authenticate') lists the scopes the route needs. A suspended key or account gets suspended.
403 terms_acceptance_required The account has not accepted the current Terms of Service and Privacy Policy: someone signs in to the Dashboard and accepts them (an organisation's keys work once an owner or admin has). Not retryable until then.
402 insufficient_credit The account's credit is out, or does not cover the transcription: every transcription is billed at least the plan's minimum (rates.minimumSeconds, 5 minutes). details: balance, plan, topUpUrl, and required when the cost was known up front. Add credit; vs.billing.get() shows the balance.
409 payment_method_required Auto top-up (vs.billing.setAutoTopUp) and the portal (vs.billing.portal()) need a payment first (vs.billing.createCheckout({ kind: 'topup', amount, acceptTerms: true }) opens one; a signed-in person's token, never an API key).
402 quota_exceeded The plan's transcriptions-at-once limit is reached. details: metric (concurrent_transcriptions), limit, used, plan, topUpUrl.
429 rate_limited Retried automatically; if it still fails, wait err.retryAfter seconds. Every response carries RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset.
503 unavailable The service is waking (its database was asleep). Retried automatically after Retry-After (2 s) on calls that are safe to repeat: GET, HEAD, DELETE, or any call with { idempotencyKey }. A create without a key is not retried: retry it yourself, with an idempotencyKey so it cannot run twice. A realtime socket refused this way throws unavailable; a bare 503 there is capacity_exceeded.
import { VocalStack, VocalStackError } from '@vocalstack/js-sdk';
const vs = new VocalStack({ baseUrl: process.env.VOCALSTACK_BASE_URL, apiKey: process.env.VOCALSTACK_API_KEY });

try {
  await vs.search.query('country');
} catch (err) {
  if (!(err instanceof VocalStackError)) throw err;
  if (err.code === 'insufficient_credit' || err.code === 'quota_exceeded') console.error(err.message, err.details);
  else console.error(err.status, err.code, err.message);
}

More

  • The other groups: vs.transcriptions (list, get, update, archive, restore, purge, listShareLinks, createShareLink, listScripts, pause, resume, stop, job, summarize, summary, translation, corrections, audio, voice, history, subscribe for a live transcript feed), vs.corrections (revert), vs.shareLinks, vs.speakers (with invite, listInvites, renewInvite, cancelInvite), vs.speakerInvites (the invited person's link, no key), vs.voices, vs.broadcasts, vs.me (get, usage), vs.languages, vs.rtmp, vs.events, vs.meta. Each method is named after its operation in the OpenAPI document (transcriptions.create is POST /v1/transcriptions).
  • <base>/llms.txt lists every operation in a form written for agents. <base>/llms-full.txt adds parameters, auth mode, tier and scopes.
  • <base>/docs is the interactive reference. <base>/v1/openapi.json is the OpenAPI document; the SDK's types are generated from it.
檢視許可證全文(MIT)
MIT License

Copyright (c) 2026 VocalStack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.