Implementation:0xsline OpenChatCut ExtractAsrAudio
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Audio_Processing, Transcription, Media_Processing |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete function that extracts audio from a video or large audio file into a speech-recognition-optimized format (16 kHz mono Opus, with MP3 fallback), returning the absolute path of the written ASR audio.
Description
The extractAsrAudio function encodes audio from a source media file for ASR:
- Primary format: Opus (libopus) at 64 kbps, 16 kHz, mono — `.asr.ogg`.
- Fallback format: MP3 (libmp3lame) at 64 kbps, 16 kHz, mono — `.asr.mp3`.
- Try-catch fallback: If Opus encoding fails, the `.asr.ogg` temp file is cleaned up and MP3 is attempted. If MP3 also fails, the original Opus error is re-thrown.
- Temp-file safety: Uses `.part` temp files that are cleaned up on failure.
The companion extractAudioPlugin function wraps this as an HTTP endpoint at `/api/extract-audio` with:
- Path validation: Source must be `/media/uploads/<safe-name>`.
- Audio track detection: Probes for audio track before extraction; fast-fails with `noAudio: true`.
- Caching: Returns cached `.asr.ogg` or `.asr.mp3` if it exists and `force` is not set.
- 30-minute timeout: For long video sources.
Usage
- Transcription pipeline: Called as the first stage before cloud or local ASR.
- HTTP API: `POST /api/extract-audio` with `{ src, force? }`.
Code Reference
Source Location
- Repository: OpenChatCut
- File:*** server/plugins/extract-audio.ts
Signature
export async function extractAsrAudio(
inputPath: string,
dir: string,
stem: string,
): Promise<{ file: string; bytes: number }>;
export function extractAudioPlugin(): Plugin;
Import
import { extractAsrAudio, extractAudioPlugin } from '../server/plugins/extract-audio.ts';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| inputPath | string | Yes | Source media file path |
| dir | string | Yes | Output directory (upload dir) |
| stem | string | Yes | Output filename stem (from source name) |
Outputs
| Name | Type | Description |
|---|---|---|
| file | string | Absolute path to written ASR audio |
| bytes | number | Size of the output file in bytes |
Usage Examples
Extract Audio for ASR
import { extractAsrAudio } from '../server/plugins/extract-audio.ts';
const result = await extractAsrAudio(
'/media/uploads/source-video.mp4',
'/data/uploads',
'source-video',
);
console.log(`ASR audio: ${result.file} (${result.bytes} bytes)`);
// Output: /data/uploads/source-video.asr.ogg
Via HTTP API
curl -X POST http://localhost:5199/api/extract-audio \
-H 'Content-Type: application/json' \
-d '{"src":"/media/uploads/source-video.mp4"}'
# Response: { ok: true, path: "/media/uploads/source-video.asr.ogg", bytes: 12345 }
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment