Implementation:0xsline OpenChatCut ExtractAudioPlugin
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Audio_Processing, Transcription, HTTP |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete Vite plugin that exposes `POST /api/extract-audio` for extracting ASR-optimized audio from media files, with audio-track detection, caching, and error classification.
Description
The extractAudioPlugin function registers an HTTP endpoint at `/api/extract-audio`:
- Method validation: Rejects non-POST with 405.
- Path validation: Source must be `/media/uploads/<safe-name>`; resolves via `resolveUploadFile`.
- Audio detection: Probes with `probeHasAudio` before extraction; returns `422` with `{ ok: false, noAudio: true }` if no audio track.
- Caching: Checks for existing `.asr.ogg` or `.asr.mp3`; returns immediately if found and `force` is not set.
- Extraction: Delegates to extractAsrAudio for the actual encoding.
- Empty-file detection: Returns 422 if extracted audio is 0 bytes.
- Error classification: 503 for FFmpeg spawn errors, 422 for no-audio/empty/exit errors, 500 for other failures.
Usage
- Transcription pipeline: The editor UI calls this endpoint before transcribing.
- Agent transcription: MCP agents call this endpoint to prepare audio for ASR.
Code Reference
Source Location
- Repository: OpenChatCut
- File:*** server/plugins/extract-audio.ts
Signature
export function extractAudioPlugin(): Plugin;
Import
import { extractAudioPlugin } from '../server/plugins/extract-audio.ts';
I/O Contract
Inputs (HTTP POST body)
| Name | Type | Required | Description |
|---|---|---|---|
| src | string | Yes | `/media/uploads/<safe-name>` path |
| force | boolean | No | Bypass cache and re-extract |
Outputs (HTTP 200 JSON)
| Name | Type | Description |
|---|---|---|
| ok | true | Success flag |
| path | string | `/media/uploads/<stem>.asr.ogg` or `.asr.mp3` |
| bytes | number | Output file size |
| cached | boolean | Whether the result was from cache |
| source | string | Original source path |
Usage Examples
Extract Audio
# Extract audio (with caching)
curl -X POST http://localhost:5199/api/extract-audio \
-H 'Content-Type: application/json' \
-d '{"src":"/media/uploads/interview.mp4"}'
# Force re-extraction (bypass cache)
curl -X POST http://localhost:5199/api/extract-audio \
-H 'Content-Type: application/json' \
-d '{"src":"/media/uploads/interview.mp4","force":true}'
Register the Plugin
import { extractAudioPlugin } from '../server/plugins/extract-audio.ts';
const plugins = [
extractAudioPlugin(),
// ...other plugins
];
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment