Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xsline OpenChatCut TranscribeCloudAudio

From Leeroopedia
Knowledge Sources
Domains Transcription, Speech_Recognition, Cloud_Integration
Last Updated 2026-10-22 14:00 GMT

Overview

Concrete function that transcribes audio using cloud AI providers via the Vercel AI SDK, normalizing diverse provider outputs into a uniform `NormalizedTranscriptResult` with word-level timestamps and speaker utterances.

Description

The transcribeCloudAudio function:

  • Dispatches to `runProvider` which calls the Vercel AI SDK `transcribe()` function with provider-specific configuration.
  • Extracts raw words from the provider response body — each provider has a different JSON shape:
    • OpenAI/Groq/Mistral: `words[]` or `segments[]`.
    • Deepgram: `results.channels[0].alternatives[0].words[]`.
    • ElevenLabs/Cartesia: `words[]` (filtering by `type: 'word'`).
  • Falls back to standard AI SDK segment-based words if the raw response has no word array.
  • Normalizes timestamps from seconds to milliseconds (rounded).
  • Joins text with proper punctuation spacing (e.g., no space before commas).
  • Groups utterances by speaker — consecutive words with the same speaker ID form an utterance.

The function handles:

  • Language: ISO code or `'auto'` (omits language param for auto-detection).
  • Diarization: Speaker diarization for Deepgram and ElevenLabs.
  • Timestamp granularities: `['word', 'segment']` for OpenAI.

Usage

  • Transcription plugin: Called by `transcriptionPlugin`'s HTTP handler.
  • Agent transcription: Called when MCP agents request transcription.

Code Reference

Source Location

  • Repository: OpenChatCut
  • File:*** server/plugins/transcription-providers.ts

Signature

export interface NormalizedTranscriptWord {
  text: string;
  start: number;  // milliseconds
  end: number;    // milliseconds
  speaker: string | null;
}

export interface NormalizedTranscriptUtterance {
  speaker: string;
  text: string;
  start: number;
  end: number;
  words: NormalizedTranscriptWord[];
}

export interface NormalizedTranscriptResult {
  text: string;
  words: NormalizedTranscriptWord[];
  utterances: NormalizedTranscriptUtterance[];
}

export async function transcribeCloudAudio(
  options: TranscriptionOptions,
  request: CloudTranscriptionRequest,
): Promise<NormalizedTranscriptResult>;

Import

import {
  transcribeCloudAudio,
  type NormalizedTranscriptResult,
} from '../server/plugins/transcription-providers.ts';

I/O Contract

Inputs

Name Type Required Description
options TranscriptionOptions Yes Provider API keys, models, defaults
request.provider string Yes Provider: openai, deepgram, groq, elevenlabs, cartesia, mistral
request.language string Yes ISO code or 'auto'
request.diarize boolean Yes Enable speaker diarization
request.audio Buffer Yes Raw audio bytes (max 100 MiB)

Outputs

Name Type Description
text string Full transcript text
words NormalizedTranscriptWord[] Word-level timestamps (ms)
utterances NormalizedTranscriptUtterance[] Speaker-grouped utterances

Usage Examples

Transcribe with OpenAI

import { transcribeCloudAudio } from '../server/plugins/transcription-providers.ts';

const result = await transcribeCloudAudio(
  {
    openaiApiKey: process.env.OPENAI_API_KEY,
    openaiModel: 'whisper-1',
  },
  {
    provider: 'openai',
    language: 'en',
    diarize: false,
    audio: audioBuffer,
  },
);

console.log(`Transcript: ${result.text}`);
console.log(`Words: ${result.words.length}`);
console.log(`Utterances: ${result.utterances.length}`);

With Deepgram Diarization

const result = await transcribeCloudAudio(
  { deepgramApiKey: process.env.DEEPGRAM_API_KEY, deepgramModel: 'nova-2' },
  { provider: 'deepgram', language: 'auto', diarize: true, audio: audioBuffer },
);

for (const utt of result.utterances) {
  console.log(`[${utt.speaker}] ${utt.start}ms-${utt.end}ms: ${utt.text}`);
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment