Live transcription

Live transcription converts a real-time audio stream into text via WebSocket. Instead of uploading a file, the client opens a persistent WebSocket connection and streams raw PCM audio frames; the service replies with incremental transcript.partial and transcript.final events.

The two-step flow:

  • (1) call POST /v1/live-transcription/sessions to obtain a short-lived signed token and a WebSocket URL;
  • (2) connect to that URL and stream audio.

Each session creation deducts 1 credit from the workspace's live_transcription monthly allowance.

WebSocket protocol

After connecting, send the raw binary frames containing PCM 16-bit mono audio. The required sample rate is returned in the session response as sampleRate:

  • 24 000 Hz
  • 16 000 Hz

The service buffers audio internally and emits transcript events as text accumulates. The client receives JSON text frames:

{ "type": "transcript.partial", "text": "Hello" }
{ "type": "transcript.final", "text": "Hello world." }
{ "type": "error", "text": "engine failed to connect" }

Close the WebSocket when the session ends. The service flushes any buffered audio before the connection is torn down.

SDK packages

Official SDKs handle session creation, WebSocket management, and audio framing for you. Install the package for your platform:

  • JavaScript / TypeScript — npm install perchat-media. Use perchat-media/browser for the VideoStreamer helper that captures audio from a <video> element.
  • Python — pip install perchat-media. Async context manager and async iterator pattern.
// npm install perchat-media

// ─── Node.js ────────────────────────────────────────────────────────
import { PerchatMediaClient, EventType } from "perchat-media";

const client = new PerchatMediaClient({
  apiKey: process.env.PERCHAT_MEDIA_API_KEY,
  baseUrl: process.env.PERCHAT_MEDIA_URL,
});

// Create a session, then connect with a language hint
const session = await client.liveTranscription.createSession();
const conn = await client.liveTranscription.connect(session, {
  language: "en", // ISO 639-1 code, or omit for auto-detect
});

// Send PCM16 mono audio (Uint8Array)
conn.sendAudio(pcmBytes);

// Iterate over transcript events
for await (const event of conn) {
  if (event.type === EventType.FINAL) {
    console.log("Transcript:", event.text);
  }
}

conn.close();

// ─── Browser (video element) ────────────────────────────────────────
import { PerchatMediaClient } from "perchat-media/browser";
import { VideoStreamer } from "perchat-media/browser";

const browserClient = new PerchatMediaClient({
  apiKey: "sk_prj_...",
  baseUrl: "https://api.example.com",
});

// Create the session upfront so we can reuse it for reconnects
const session = await browserClient.liveTranscription.createSession();

const streamer = new VideoStreamer("my-video", browserClient, {
  passthrough: true, // keep audio playing through speakers
});

streamer.onTranscript((event) => {
  if (event.type === "final") {
    console.log("Final:", event.text);
  }
});

streamer.onClose(() => console.log("Stream ended"));

// Pass the session to start — VideoStreamer uses it directly
await streamer.start(session);

// Switch language mid-stream (reuses session token, swaps WebSocket only)
await streamer.reconnect({
  ...session,
  wsUrl: session.wsUrl + "&language=fr",
});

// Stop transcription (video keeps playing)
await streamer.stop();

Create a session

POST/v1/live-transcription/sessions

Creates a short-lived session token for a live transcription WebSocket connection. The response includes a ready-to-use wsUrl (token already embedded) and the sampleRate expected by the configured engine.

The workspace must have live_transcription enabled — otherwise the call returns HTTP 403 forbidden with not_enabled. Check GET /v1/services. Calling this endpoint deducts 1 credit from the live_transcription monthly allowance. A 403 quotaExceeded error is returned when the workspace has no remaining credits.

Requires permission

live-transcription:create

Returns

Returns a session object with token, wsUrl, expiresAt, and sampleRate.

Connect & stream audio

WS/ws/transcribe

Opens a persistent WebSocket connection on the transcription service (the URL is returned as wsUrl from the session endpoint).

Once connected the client drives the session with a binary-in / text-out protocol:

  • Send raw PCM 16-bit mono audio as binary WebSocket frames. Use the sampleRate from the session response (24 000 Hz, 16 000 Hz).
  • Receive JSON text frames for every transcript update. See the event schema below.

Close the WebSocket normally when the session ends. Any buffered audio is flushed before the connection tears down.

Parameters

<binary frame>bytes
Raw PCM 16-bit mono audio at sampleRate Hz. Send as binary WebSocket frames continuously while recording.

Query parameters

tokenstring
Required. The signed session token returned by POST /v1/live-transcription/sessions. Already embedded in wsUrl.
languagestring
Optional language paramter for the transcription, autoIf not passed.

Returns

The server emits JSON text frames. Each frame has two fields:

  • type — "transcript.partial" while words are still arriving, "transcript.final" when a sentence is committed, or "error" on engine failure.
  • text — the transcript text (or error message when type is "error").