@agent-media/audio 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ import type { MediaResult } from '@agent-media/core';
2
+ /**
3
+ * Supported audio output formats for extraction
4
+ */
5
+ export type AudioOutputFormat = 'mp3' | 'wav';
6
+ export interface ExtractInput {
7
+ /** Input video file path or URL */
8
+ input: string;
9
+ /** Output audio format (mp3, wav) */
10
+ format?: AudioOutputFormat;
11
+ /** Output directory (overrides default) */
12
+ out?: string;
13
+ }
14
+ /**
15
+ * Extract audio track from a video file
16
+ * Uses ffmpeg-static - binary is bundled, no external installation required
17
+ */
18
+ export declare function extract(options: ExtractInput): Promise<MediaResult>;
19
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/actions/extract.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAUrD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,KAAK,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,2CAA2C;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAsCD;;;GAGG;AACH,wBAAsB,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAiEzE"}
@@ -0,0 +1,97 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { writeFile, stat, unlink } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import ffmpegPath from 'ffmpeg-static';
6
+ import { createSuccess, createError, ensureOutputDir, generateOutputFilename, getOutputPath, ErrorCodes, } from '@agent-media/core';
7
+ /**
8
+ * Run ffmpeg command and return a promise
9
+ */
10
+ function runFfmpeg(args) {
11
+ return new Promise((resolve, reject) => {
12
+ if (!ffmpegPath) {
13
+ reject(new Error('ffmpeg-static path not found'));
14
+ return;
15
+ }
16
+ const process = spawn(ffmpegPath, args);
17
+ let stdout = '';
18
+ let stderr = '';
19
+ process.stdout.on('data', (data) => {
20
+ stdout += data.toString();
21
+ });
22
+ process.stderr.on('data', (data) => {
23
+ stderr += data.toString();
24
+ });
25
+ process.on('close', (code) => {
26
+ if (code === 0) {
27
+ resolve({ stdout, stderr });
28
+ }
29
+ else {
30
+ reject(new Error(`ffmpeg exited with code ${code}: ${stderr}`));
31
+ }
32
+ });
33
+ process.on('error', (err) => {
34
+ reject(err);
35
+ });
36
+ });
37
+ }
38
+ /**
39
+ * Extract audio track from a video file
40
+ * Uses ffmpeg-static - binary is bundled, no external installation required
41
+ */
42
+ export async function extract(options) {
43
+ const { input: inputPath, format = 'mp3', out } = options;
44
+ const outputDir = out ?? process.cwd() + '/.agent-media';
45
+ try {
46
+ await ensureOutputDir(outputDir);
47
+ // Check if input is URL or local file
48
+ const isUrl = inputPath.startsWith('http://') || inputPath.startsWith('https://');
49
+ let actualInputPath = inputPath;
50
+ let tempFile = null;
51
+ // If URL, download to temp file first
52
+ if (isUrl) {
53
+ const response = await fetch(inputPath);
54
+ if (!response.ok) {
55
+ return createError(ErrorCodes.NETWORK_ERROR, `Failed to fetch URL: ${response.statusText}`);
56
+ }
57
+ const arrayBuffer = await response.arrayBuffer();
58
+ const buffer = Buffer.from(arrayBuffer);
59
+ // Create temp file
60
+ tempFile = join(tmpdir(), `agent-media-${Date.now()}.tmp`);
61
+ await writeFile(tempFile, buffer);
62
+ actualInputPath = tempFile;
63
+ }
64
+ // Generate output filename
65
+ const outputFilename = generateOutputFilename(format, 'extracted');
66
+ const outputPath = getOutputPath(outputDir, outputFilename);
67
+ // Build ffmpeg arguments
68
+ const args = [
69
+ '-i', actualInputPath,
70
+ '-vn', // No video
71
+ '-acodec', format === 'mp3' ? 'libmp3lame' : 'pcm_s16le',
72
+ '-y', // Overwrite output
73
+ outputPath,
74
+ ];
75
+ // Run ffmpeg
76
+ await runFfmpeg(args);
77
+ // Clean up temp file if created
78
+ if (tempFile) {
79
+ await unlink(tempFile).catch(() => { }); // Ignore errors
80
+ }
81
+ const stats = await stat(outputPath);
82
+ const mimeType = format === 'wav' ? 'audio/wav' : 'audio/mpeg';
83
+ return createSuccess({
84
+ mediaType: 'audio',
85
+ action: 'extract',
86
+ provider: 'local',
87
+ outputPath: outputPath,
88
+ mime: mimeType,
89
+ bytes: stats.size,
90
+ });
91
+ }
92
+ catch (error) {
93
+ const message = error instanceof Error ? error.message : String(error);
94
+ return createError(ErrorCodes.PROVIDER_ERROR, `Audio extraction failed: ${message}`);
95
+ }
96
+ }
97
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/actions/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,UAAU,MAAM,eAAe,CAAC;AAEvC,OAAO,EACL,aAAa,EACb,WAAW,EACX,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,UAAU,GACX,MAAM,mBAAmB,CAAC;AAgB3B;;GAEG;AACH,SAAS,SAAS,CAAC,IAAc;IAC/B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAC;YAClD,OAAO;QACT,CAAC;QAED,MAAM,OAAO,GAA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AAC;YACb,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,CAAC,gBAAgB;QAC1D,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC;QAErC,MAAM,QAAQ,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC;QAE/D,OAAO,aAAa,CAAC;YACnB,SAAS,EAAE,OAAO;YAClB,MAAM,EAAE,SAAS;YACjB,QAAQ,EAAE,OAAO;YACjB,UAAU,EAAE,UAAU;YACtB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,KAAK,CAAC,IAAI;SAClB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,WAAW,CAAC,UAAU,CAAC,cAAc,EAAE,4BAA4B,OAAO,EAAE,CAAC,CAAC;IACvF,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { extract, type ExtractInput, type AudioOutputFormat } from './extract.js';
2
+ export { transcribe, type TranscribeInput } from './transcribe.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { extract } from './extract.js';
2
+ export { transcribe } from './transcribe.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA6C,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { MediaResult } from '@agent-media/core';
2
+ export interface TranscribeInput {
3
+ /** Input audio file path or URL */
4
+ input: string;
5
+ /** Enable speaker identification */
6
+ diarize?: boolean;
7
+ /** Language code (auto-detected if not provided) */
8
+ language?: string;
9
+ /** Number of speakers hint */
10
+ numSpeakers?: number;
11
+ /** Output directory (overrides default) */
12
+ out?: string;
13
+ /** Provider to use (overrides auto-detection) */
14
+ provider?: string;
15
+ }
16
+ /**
17
+ * Transcribe audio to text with timestamps
18
+ */
19
+ export declare function transcribe(options: TranscribeInput): Promise<MediaResult>;
20
+ //# sourceMappingURL=transcribe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcribe.d.ts","sourceRoot":"","sources":["../../src/actions/transcribe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAA6B,MAAM,mBAAmB,CAAC;AAGhF,MAAM,WAAW,eAAe;IAC9B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2CAA2C;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,CA0B/E"}
@@ -0,0 +1,25 @@
1
+ import { executeAction, globalRegistry } from '@agent-media/core';
2
+ /**
3
+ * Transcribe audio to text with timestamps
4
+ */
5
+ export async function transcribe(options) {
6
+ const isUrl = options.input.startsWith('http://') || options.input.startsWith('https://');
7
+ const input = {
8
+ source: options.input,
9
+ isUrl,
10
+ };
11
+ const context = {
12
+ outputDir: options.out ?? process.cwd() + '/.agent-media',
13
+ provider: options.provider,
14
+ };
15
+ return executeAction(globalRegistry, {
16
+ action: 'transcribe',
17
+ options: {
18
+ input,
19
+ diarize: options.diarize,
20
+ language: options.language,
21
+ numSpeakers: options.numSpeakers,
22
+ },
23
+ }, context);
24
+ }
25
+ //# sourceMappingURL=transcribe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcribe.js","sourceRoot":"","sources":["../../src/actions/transcribe.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAiBlE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAwB;IACvD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAE1F,MAAM,KAAK,GAAe;QACxB,MAAM,EAAE,OAAO,CAAC,KAAK;QACrB,KAAK;KACN,CAAC;IAEF,MAAM,OAAO,GAAkB;QAC7B,SAAS,EAAE,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,eAAe;QACzD,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;IAEF,OAAO,aAAa,CAClB,cAAc,EACd;QACE,MAAM,EAAE,YAAY;QACpB,OAAO,EAAE;YACP,KAAK;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC;KACF,EACD,OAAO,CACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './actions/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './actions/index.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@agent-media/audio",
3
+ "version": "0.2.0",
4
+ "description": "Audio actions for agent-media toolkit",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/TimPietrusky/agent-media.git",
9
+ "directory": "packages/audio"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ },
19
+ "./actions": {
20
+ "types": "./dist/actions/index.d.ts",
21
+ "import": "./dist/actions/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "clean": "rm -rf dist",
30
+ "typecheck": "tsc --noEmit"
31
+ },
32
+ "dependencies": {
33
+ "@agent-media/core": "workspace:*",
34
+ "@agent-media/providers": "workspace:*",
35
+ "ffmpeg-static": "^5.3.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^22.0.0",
39
+ "typescript": "^5.7.0"
40
+ }
41
+ }