@mdgate/audio 0.1.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.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @mdgate/audio
2
+
3
+ Convert MP3, WAV, M4A, AAC, Ogg, FLAC, and WebM audio to Markdown. Outputs GitHub-Flavored
4
+ Markdown. Works in Node, Edge, and browsers. No native addons.
5
+
6
+ Needs an `(input) => markdown` transcription function — `@mdgate/ai` or your own. `all()` does not
7
+ register `audio()`.
8
+
9
+ ```ts
10
+ import { create } from '@mdgate/core';
11
+ import { audio } from '@mdgate/audio';
12
+ import { ai } from '@mdgate/ai';
13
+
14
+ const convert = create([
15
+ audio(ai({ baseURL, apiKey, model }).convertAudio),
16
+ ]);
17
+ ```
@@ -0,0 +1,3 @@
1
+ import type { Converter } from '@mdgate/core';
2
+ import type { ConvertAudio } from './types.js';
3
+ export declare function audio(transcribe?: ConvertAudio): Converter;
@@ -0,0 +1,3 @@
1
+ export { audio } from './audio.js';
2
+ export { toMarkdown } from './to-markdown.js';
3
+ export type { AudioInput, AudioMime, ConvertAudio } from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import{ConvertError as c}from"@mdgate/core";import{ConvertError as t}from"@mdgate/core";var g={mp3:"audio/mpeg",wav:"audio/wav",wave:"audio/x-wav",m4a:"audio/m4a",aac:"audio/aac",ogg:"audio/ogg",flac:"audio/flac",weba:"audio/webm"},A=[208,207,17,224,161,177,26,225];function f(n){if(h(n))return"audio/mpeg";if(v(n))return"audio/wav";let r=w(n);if(r!==void 0)return r;if(U(n))return"audio/ogg";if(M(n))return"audio/flac";return}function a(n){let r=n.split(/[/\\]/).pop()??"",o=r.lastIndexOf(".");if(o<=0||o===r.length-1)return;return g[r.slice(o+1).toLowerCase()]}function p(n,r){return f(n)??(r?.path!==void 0?a(r.path):void 0)}function l(n){if(C(n))throw t.unsupported("pdf");if(B(n,A))throw t.unsupported("ole");if(n.length>=4&&n[0]===80&&n[1]===75&&n[2]===3&&n[3]===4)throw t.unsupported("zip")}function h(n){if(n.length>=3&&n[0]===73&&n[1]===68&&n[2]===51)return!0;return n.length>=2&&n[0]===255&&(n[1]&240)===240}function v(n){return n.length>=12&&n[0]===82&&n[1]===73&&n[2]===70&&n[3]===70&&n[8]===87&&n[9]===65&&n[10]===86&&n[11]===69}function w(n){if(n.length<12)return;if(n[4]!==102||n[5]!==116||n[6]!==121||n[7]!==112)return;let r=(n[0]<<24|n[1]<<16|n[2]<<8|n[3])>>>0,o=Math.min(n.length,r>=16?r:n.length,256),i=!1,e=!1;if(x(n,8))i=!0;if(m(n,8))e=!0;for(let u=16;u+4<=o;u+=4){if(x(n,u))i=!0;if(m(n,u))e=!0}if(i)return"audio/m4a";if(e)return"audio/mp4";return}function x(n,r){return n[r]===77&&n[r+1]===52&&(n[r+2]===65||n[r+2]===66||n[r+2]===80)&&n[r+3]===32}function m(n,r){return n[r]===109&&n[r+1]===112&&n[r+2]===52}function U(n){return n.length>=4&&n[0]===79&&n[1]===103&&n[2]===103&&n[3]===83}function M(n){return n.length>=4&&n[0]===102&&n[1]===76&&n[2]===97&&n[3]===67}function C(n){let r=F(n);return H(n,"%PDF-",r)}function F(n){let r=0;if(n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191)r=3;while(r<n.length){let o=n[r];if(o!==9&&o!==10&&o!==13&&o!==32)break;r+=1}return r}function B(n,r){if(n.length<r.length)return!1;for(let o=0;o<r.length;o+=1)if(n[o]!==r[o])return!1;return!0}function H(n,r,o){if(o+r.length>n.length)return!1;for(let i=0;i<r.length;i+=1)if(n[o+i]!==r.charCodeAt(i))return!1;return!0}function d(n){return{id:"audio",sniff(r,o){if(f(r)!==void 0)return 2;if(o?.path!==void 0&&a(o.path)!==void 0)return 1;return 0},async convert(r,o){l(r);let i=p(r,o);if(i===void 0)throw c.unsupported(o?.path===void 0?"unrecognized file content: name the format explicitly":`unrecognized file content and extension: ${o.path}`);if(n===void 0)throw c.unsupported("audio transcription");let e=await n({bytes:r,mime:i});return{markdown:e.endsWith(`
2
+ `)?e:`${e}
3
+ `}}}}import{create as W}from"@mdgate/core";var z=W([d()]);function E(n,r){return z(n,r)}export{E as toMarkdown,d as audio};
@@ -0,0 +1,6 @@
1
+ import { type ConvertHint } from '@mdgate/core';
2
+ /**
3
+ * Convert a single file's bytes to Markdown with the audio converter.
4
+ * `hint.path` is only a sniff hint; it is never read from disk.
5
+ */
6
+ export declare function toMarkdown(bytes: Uint8Array, hint?: ConvertHint): Promise<string>;
@@ -0,0 +1,6 @@
1
+ export type AudioMime = 'audio/mpeg' | 'audio/wav' | 'audio/x-wav' | 'audio/mp4' | 'audio/m4a' | 'audio/aac' | 'audio/ogg' | 'audio/webm' | 'audio/flac';
2
+ export type AudioInput = {
3
+ bytes: Uint8Array;
4
+ mime: AudioMime;
5
+ };
6
+ export type ConvertAudio = (input: AudioInput) => Promise<string>;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@mdgate/audio",
3
+ "version": "0.1.0",
4
+ "description": "mdgate audio converter",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist/**/*.js",
18
+ "dist/**/*.d.ts"
19
+ ],
20
+ "scripts": {
21
+ "build": "bun ../../scripts/build-package.ts",
22
+ "prepublishOnly": "bun run build"
23
+ },
24
+ "dependencies": {
25
+ "@mdgate/core": "0.1.3"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "engines": {
31
+ "node": ">=20"
32
+ },
33
+ "keywords": [
34
+ "mdgate",
35
+ "markdown",
36
+ "audio"
37
+ ]
38
+ }