@wirecat/wordpress-cli 0.0.0-stage → 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/CHANGELOG.md +27 -0
- package/LICENSE +204 -0
- package/README.md +248 -2
- package/contracts/wirecat.json +2535 -0
- package/dist/bin/wordpress.d.ts +3 -0
- package/dist/bin/wordpress.d.ts.map +1 -0
- package/dist/bin/wordpress.js +40 -0
- package/dist/bin/wordpress.js.map +1 -0
- package/dist/bundle/agent-LKBRYKNB.js +37 -0
- package/dist/bundle/all-profiles-OEV7VFQG.js +320 -0
- package/dist/bundle/anthropic-JKTZP2DW.js +91 -0
- package/dist/bundle/app-server-7LWLDDE2.js +249 -0
- package/dist/bundle/bun-2FLR4IV4.js +169 -0
- package/dist/bundle/bun-sqlite-GRSRX5P4.js +76 -0
- package/dist/bundle/chunk-2BI25SEE.js +259 -0
- package/dist/bundle/chunk-2UEGJ5AJ.js +52 -0
- package/dist/bundle/chunk-2XUV7HNE.js +58 -0
- package/dist/bundle/chunk-2Z7UOXFC.js +16 -0
- package/dist/bundle/chunk-3BM6KBWP.js +2788 -0
- package/dist/bundle/chunk-3BRAZVHR.js +1010 -0
- package/dist/bundle/chunk-3LMW7U7F.js +1233 -0
- package/dist/bundle/chunk-3LVTQFGB.js +2000 -0
- package/dist/bundle/chunk-3TKFFSFU.js +106 -0
- package/dist/bundle/chunk-3UX4VJWD.js +78 -0
- package/dist/bundle/chunk-4HEXAGKT.js +334 -0
- package/dist/bundle/chunk-4HP6KGBI.js +32 -0
- package/dist/bundle/chunk-4ZAQMDLD.js +1308 -0
- package/dist/bundle/chunk-4ZTB7LS3.js +87 -0
- package/dist/bundle/chunk-5XPHFV7H.js +2333 -0
- package/dist/bundle/chunk-5Z3P543G.js +80 -0
- package/dist/bundle/chunk-6UYDKCV6.js +794 -0
- package/dist/bundle/chunk-7GNB4LBX.js +50 -0
- package/dist/bundle/chunk-7HJFBOAT.js +161 -0
- package/dist/bundle/chunk-7JVKQ6NM.js +206 -0
- package/dist/bundle/chunk-7QH5BZUG.js +142 -0
- package/dist/bundle/chunk-A474OVIW.js +1392 -0
- package/dist/bundle/chunk-AENEMQL3.js +1068 -0
- package/dist/bundle/chunk-AL7I4DT4.js +65718 -0
- package/dist/bundle/chunk-ARGRGTPX.js +108 -0
- package/dist/bundle/chunk-AV2ZJ4WX.js +7 -0
- package/dist/bundle/chunk-BAXNAOOL.js +76 -0
- package/dist/bundle/chunk-BH63B66W.js +407 -0
- package/dist/bundle/chunk-CCOSG3F2.js +24616 -0
- package/dist/bundle/chunk-CFQQTDSA.js +46 -0
- package/dist/bundle/chunk-CGCUOT67.js +388 -0
- package/dist/bundle/chunk-CHPWBQUK.js +39 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DQSOYH6N.js +20 -0
- package/dist/bundle/chunk-ECYOTDJM.js +14 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-EHW45LLT.js +100 -0
- package/dist/bundle/chunk-F3AV5ZSL.js +338 -0
- package/dist/bundle/chunk-F4BX7TH2.js +15 -0
- package/dist/bundle/chunk-F5ZAN7OC.js +6848 -0
- package/dist/bundle/chunk-FMMYBVCH.js +38 -0
- package/dist/bundle/chunk-FNB4SWTY.js +66 -0
- package/dist/bundle/chunk-FQROWBKV.js +12660 -0
- package/dist/bundle/chunk-FV2HJOSC.js +771 -0
- package/dist/bundle/chunk-GCAJW4SR.js +53 -0
- package/dist/bundle/chunk-GPRJXJC7.js +102 -0
- package/dist/bundle/chunk-HCOZUOSN.js +54 -0
- package/dist/bundle/chunk-HM6AMYHR.js +72 -0
- package/dist/bundle/chunk-HVXOA4FO.js +23 -0
- package/dist/bundle/chunk-HWQ7572G.js +95 -0
- package/dist/bundle/chunk-IJVTN5L3.js +82 -0
- package/dist/bundle/chunk-IZDDBOHU.js +3610 -0
- package/dist/bundle/chunk-JAE5B4G7.js +388 -0
- package/dist/bundle/chunk-K2Y5K37O.js +218 -0
- package/dist/bundle/chunk-KCH224US.js +9581 -0
- package/dist/bundle/chunk-KZJQPJK5.js +230 -0
- package/dist/bundle/chunk-L7P3LUDQ.js +286 -0
- package/dist/bundle/chunk-LECMHK2F.js +18 -0
- package/dist/bundle/chunk-LWEMZJLG.js +1332 -0
- package/dist/bundle/chunk-LWTETL2O.js +185 -0
- package/dist/bundle/chunk-MEYYH47C.js +25 -0
- package/dist/bundle/chunk-MJ6LTG4L.js +170 -0
- package/dist/bundle/chunk-NMQRSEZM.js +37 -0
- package/dist/bundle/chunk-ODVGFCBE.js +557 -0
- package/dist/bundle/chunk-OEQNP56V.js +633 -0
- package/dist/bundle/chunk-OV6WQY3L.js +39 -0
- package/dist/bundle/chunk-PL5P7UKW.js +25216 -0
- package/dist/bundle/chunk-PPNTY7LD.js +733 -0
- package/dist/bundle/chunk-PRZYRA66.js +358 -0
- package/dist/bundle/chunk-PV5UYGRJ.js +41594 -0
- package/dist/bundle/chunk-QYTOLPNI.js +52 -0
- package/dist/bundle/chunk-R7Y3XU66.js +362 -0
- package/dist/bundle/chunk-S4UUN6LD.js +1410 -0
- package/dist/bundle/chunk-SD5CXGIG.js +188 -0
- package/dist/bundle/chunk-SXY5G62I.js +288 -0
- package/dist/bundle/chunk-T37TAXVL.js +29 -0
- package/dist/bundle/chunk-T5SOY3AE.js +1197 -0
- package/dist/bundle/chunk-TJ7OORSO.js +1876 -0
- package/dist/bundle/chunk-TRYYWV7J.js +291 -0
- package/dist/bundle/chunk-U6VLNYCO.js +73 -0
- package/dist/bundle/chunk-UC7JLE6J.js +58 -0
- package/dist/bundle/chunk-UUIOAZPH.js +156 -0
- package/dist/bundle/chunk-UXQ24OY6.js +4072 -0
- package/dist/bundle/chunk-VBRRMGON.js +1007 -0
- package/dist/bundle/chunk-VRIBES2C.js +319 -0
- package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
- package/dist/bundle/chunk-XT5XYQEZ.js +3414 -0
- package/dist/bundle/chunk-XTAS5Z3G.js +2231 -0
- package/dist/bundle/chunk-XYQVVW4R.js +24 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-YHWFF6DN.js +39 -0
- package/dist/bundle/chunk-YUDVRFXN.js +63 -0
- package/dist/bundle/chunk-Z3I2MCUT.js +131 -0
- package/dist/bundle/chunk-ZDI3WC7V.js +353 -0
- package/dist/bundle/chunk-ZVQ7KFMT.js +274 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-P7YE4EKS.js +37 -0
- package/dist/bundle/command-server-entry-XIMCBWMV.js +166 -0
- package/dist/bundle/decode-6XK55WYV.js +297 -0
- package/dist/bundle/definitions-GIQCGYPR.js +7986 -0
- package/dist/bundle/dispatch-JQBAZWCL.js +411 -0
- package/dist/bundle/dist-2TV3NVE5.js +7577 -0
- package/dist/bundle/dist-PAKDDIBT.js +191 -0
- package/dist/bundle/echarts-YRRVLEX3.js +42501 -0
- package/dist/bundle/embed-L3EEQSGX.js +38 -0
- package/dist/bundle/embedder-BIKLBV3J.js +111 -0
- package/dist/bundle/failure-I6AAF5R5.js +25 -0
- package/dist/bundle/first-run-W6G6TYZ2.js +29 -0
- package/dist/bundle/first-screen-ITIAJIBU.js +37 -0
- package/dist/bundle/hast-util-from-html-ZHU6HGIE.js +10531 -0
- package/dist/bundle/hast-util-to-html-IIFHILP5.js +998 -0
- package/dist/bundle/hast-util-to-mdast-D62XX3NR.js +2272 -0
- package/dist/bundle/instructions-AG7SRWTR.js +11 -0
- package/dist/bundle/mcp-YGOAUNC3.js +167 -0
- package/dist/bundle/mdast-util-from-markdown-WVUJDSUO.js +1900 -0
- package/dist/bundle/mdast-util-gfm-KN2D32QS.js +1040 -0
- package/dist/bundle/mdast-util-to-hast-AYJV7KAE.js +879 -0
- package/dist/bundle/mdast-util-to-markdown-UCAJNHJO.js +18 -0
- package/dist/bundle/meeting-combined-CQJ3JHHU.js +24 -0
- package/dist/bundle/meeting-model-MZ7VVBNK.js +25 -0
- package/dist/bundle/meeting-semantic-DADWRRHP.js +22 -0
- package/dist/bundle/micromark-extension-gfm-EEJRRJ36.js +1771 -0
- package/dist/bundle/node-GJQYN4FT.js +176 -0
- package/dist/bundle/node-JJ3WDCNJ.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-TPR62DT2.js +74 -0
- package/dist/bundle/oauth-WGY7JQVW.js +20 -0
- package/dist/bundle/open-DE7QZNAN.js +23 -0
- package/dist/bundle/openai-NHEFT3HS.js +238 -0
- package/dist/bundle/process-MEKCZMX3.js +91 -0
- package/dist/bundle/program-EP2S5BTM.js +38857 -0
- package/dist/bundle/prompt-PWY53BYH.js +17 -0
- package/dist/bundle/recognize-74TXHKMQ.js +26 -0
- package/dist/bundle/remote-F5TJZ5ER.js +31 -0
- package/dist/bundle/rerank-HWUO52UF.js +52 -0
- package/dist/bundle/schemas-4K6WWS5N.js +2157 -0
- package/dist/bundle/serve-I2USUY4X.js +199 -0
- package/dist/bundle/server-GDYDNO6K.js +79 -0
- package/dist/bundle/server-KYUW2AHB.js +212 -0
- package/dist/bundle/sqlite-runtime-N6VFGBJK.js +20 -0
- package/dist/bundle/state-L6JSCN77.js +36 -0
- package/dist/bundle/store-EPG2YPN3.js +291 -0
- package/dist/bundle/store-SQWQJE32.js +181 -0
- package/dist/bundle/store-maintenance-command-FTGSICVA.js +66 -0
- package/dist/bundle/surface-SNMHY6GP.js +65 -0
- package/dist/bundle/wordpress.js +183 -0
- package/dist/commands/api.d.ts +22 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +37 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/content.d.ts +4 -0
- package/dist/commands/content.d.ts.map +1 -0
- package/dist/commands/content.js +94 -0
- package/dist/commands/content.js.map +1 -0
- package/dist/commands/session.d.ts +8 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +28 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +69 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +37 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +31 -0
- package/dist/context.js.map +1 -0
- package/dist/generated/definitions.d.ts +3 -0
- package/dist/generated/definitions.d.ts.map +1 -0
- package/dist/generated/definitions.js +7982 -0
- package/dist/generated/definitions.js.map +1 -0
- package/dist/generated/manifest.d.ts +6 -0
- package/dist/generated/manifest.d.ts.map +1 -0
- package/dist/generated/manifest.js +8830 -0
- package/dist/generated/manifest.js.map +1 -0
- package/dist/generated/schemas.d.ts +229 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +2019 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/generated/types.d.ts +3365 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +5 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/generated/wirecat-config.d.ts +11 -0
- package/dist/generated/wirecat-config.d.ts.map +1 -0
- package/dist/generated/wirecat-config.js +337 -0
- package/dist/generated/wirecat-config.js.map +1 -0
- package/dist/identity.d.ts +28 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +29 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +53 -0
- package/dist/program.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/package.json +87 -4
- package/skills/wordpress-cli/SKILL.md +88 -0
- package/skills/wordpress-cli/references/api/api-block-directory.md +17 -0
- package/skills/wordpress-cli/references/api/api-block-patterns.md +13 -0
- package/skills/wordpress-cli/references/api/api-block-types.md +34 -0
- package/skills/wordpress-cli/references/api/api-blocks.md +159 -0
- package/skills/wordpress-cli/references/api/api-categories.md +69 -0
- package/skills/wordpress-cli/references/api/api-comments.md +79 -0
- package/skills/wordpress-cli/references/api/api-font-collections.md +16 -0
- package/skills/wordpress-cli/references/api/api-font-families.md +122 -0
- package/skills/wordpress-cli/references/api/api-global-styles.md +29 -0
- package/skills/wordpress-cli/references/api/api-media.md +106 -0
- package/skills/wordpress-cli/references/api/api-menu-items.md +115 -0
- package/skills/wordpress-cli/references/api/api-menu-locations.md +22 -0
- package/skills/wordpress-cli/references/api/api-menus.md +69 -0
- package/skills/wordpress-cli/references/api/api-navigation.md +155 -0
- package/skills/wordpress-cli/references/api/api-pages.md +161 -0
- package/skills/wordpress-cli/references/api/api-pattern-directory.md +23 -0
- package/skills/wordpress-cli/references/api/api-plugins.md +25 -0
- package/skills/wordpress-cli/references/api/api-posts.md +166 -0
- package/skills/wordpress-cli/references/api/api-search.md +21 -0
- package/skills/wordpress-cli/references/api/api-settings.md +19 -0
- package/skills/wordpress-cli/references/api/api-sidebars.md +34 -0
- package/skills/wordpress-cli/references/api/api-statuses.md +22 -0
- package/skills/wordpress-cli/references/api/api-tags.md +69 -0
- package/skills/wordpress-cli/references/api/api-taxonomies.md +23 -0
- package/skills/wordpress-cli/references/api/api-template-parts.md +38 -0
- package/skills/wordpress-cli/references/api/api-templates.md +38 -0
- package/skills/wordpress-cli/references/api/api-themes.md +12 -0
- package/skills/wordpress-cli/references/api/api-types.md +22 -0
- package/skills/wordpress-cli/references/api/api-users.md +149 -0
- package/skills/wordpress-cli/references/api/api-widget-types.md +46 -0
- package/skills/wordpress-cli/references/api/api-widgets.md +57 -0
- package/skills/wordpress-cli/references/api/api-wp-pattern-category.md +69 -0
- package/skills/wordpress-cli/references/api.md +44 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
SAMPLE_RATE,
|
|
5
|
+
decodeOgg
|
|
6
|
+
} from "./chunk-KZJQPJK5.js";
|
|
7
|
+
import "./chunk-3BM6KBWP.js";
|
|
8
|
+
import "./chunk-3LMW7U7F.js";
|
|
9
|
+
import "./chunk-S4UUN6LD.js";
|
|
10
|
+
import {
|
|
11
|
+
importFrom
|
|
12
|
+
} from "./chunk-Y5E2WNWB.js";
|
|
13
|
+
import {
|
|
14
|
+
CliError
|
|
15
|
+
} from "./chunk-HM6AMYHR.js";
|
|
16
|
+
import {
|
|
17
|
+
__name
|
|
18
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
19
|
+
|
|
20
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/speech/decode.js
|
|
21
|
+
import { spawn } from "node:child_process";
|
|
22
|
+
import { mkdtemp, open, readFile, rm, writeFile } from "node:fs/promises";
|
|
23
|
+
import { createRequire } from "node:module";
|
|
24
|
+
import { tmpdir } from "node:os";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import { pathToFileURL } from "node:url";
|
|
27
|
+
var LONGEST_AUDIO_SECONDS = 3600;
|
|
28
|
+
var FFMPEG_TIMEOUT_MS = 12e4;
|
|
29
|
+
var FFMPEG_FORMATS = "mov,mp4,m4a,3gp,3g2,mj2,aac,mp3,wav,amr,caf,aiff,flac,ogg,matroska,webm,asf";
|
|
30
|
+
var text = /* @__PURE__ */ __name((bytes, from, length) => String.fromCharCode(...bytes.subarray(from, from + length)), "text");
|
|
31
|
+
var contains = /* @__PURE__ */ __name((bytes, needle, within) => Buffer.from(bytes.buffer, bytes.byteOffset, Math.min(bytes.length, within)).includes(needle, 0, "latin1"), "contains");
|
|
32
|
+
var formatOf = /* @__PURE__ */ __name((bytes) => {
|
|
33
|
+
if (text(bytes, 0, 4) === "OggS") {
|
|
34
|
+
if (contains(bytes, "OpusHead", 128))
|
|
35
|
+
return "opus";
|
|
36
|
+
if (contains(bytes, "vorbis", 128))
|
|
37
|
+
return "vorbis";
|
|
38
|
+
return "other";
|
|
39
|
+
}
|
|
40
|
+
if (text(bytes, 0, 4) === "fLaC")
|
|
41
|
+
return "flac";
|
|
42
|
+
const frame = bytes[0] === 255 && ((bytes[1] ?? 0) & 224) === 224 && ((bytes[1] ?? 0) >> 1 & 3) !== 0;
|
|
43
|
+
if (text(bytes, 0, 3) === "ID3" || frame)
|
|
44
|
+
return "mp3";
|
|
45
|
+
return "other";
|
|
46
|
+
}, "formatOf");
|
|
47
|
+
var everyChannel = /* @__PURE__ */ __name((decoded) => {
|
|
48
|
+
if (!decoded.channelData[0] || decoded.samplesDecoded === 0)
|
|
49
|
+
throw new CliError("validation_error", "no audio in that file");
|
|
50
|
+
return decoded.channelData.map((samples) => ({ samples, rate: decoded.sampleRate }));
|
|
51
|
+
}, "everyChannel");
|
|
52
|
+
var load = /* @__PURE__ */ __name((name) => importFrom(new URL("speech/decode.js", import.meta.resolve("@wirecat/cli-core")).href, pathToFileURL(createRequire(new URL("speech/decode.js", import.meta.resolve("@wirecat/cli-core")).href).resolve(name)).href), "load");
|
|
53
|
+
var decodeVorbis = /* @__PURE__ */ __name(async (bytes) => {
|
|
54
|
+
const { OggVorbisDecoder } = await load("@wasm-audio-decoders/ogg-vorbis");
|
|
55
|
+
const decoder = new OggVorbisDecoder();
|
|
56
|
+
await decoder.ready;
|
|
57
|
+
try {
|
|
58
|
+
return everyChannel(await decoder.decodeFile(bytes));
|
|
59
|
+
} finally {
|
|
60
|
+
decoder.free();
|
|
61
|
+
}
|
|
62
|
+
}, "decodeVorbis");
|
|
63
|
+
var decodeFlac = /* @__PURE__ */ __name(async (bytes) => {
|
|
64
|
+
const { FLACDecoder } = await load("@wasm-audio-decoders/flac");
|
|
65
|
+
const decoder = new FLACDecoder();
|
|
66
|
+
await decoder.ready;
|
|
67
|
+
try {
|
|
68
|
+
return everyChannel(await decoder.decodeFile(bytes));
|
|
69
|
+
} finally {
|
|
70
|
+
decoder.free();
|
|
71
|
+
}
|
|
72
|
+
}, "decodeFlac");
|
|
73
|
+
var decodeMp3 = /* @__PURE__ */ __name(async (bytes) => {
|
|
74
|
+
const { MPEGDecoder } = await load("mpg123-decoder");
|
|
75
|
+
const decoder = new MPEGDecoder();
|
|
76
|
+
await decoder.ready;
|
|
77
|
+
try {
|
|
78
|
+
return everyChannel(decoder.decode(bytes));
|
|
79
|
+
} finally {
|
|
80
|
+
decoder.free();
|
|
81
|
+
}
|
|
82
|
+
}, "decodeMp3");
|
|
83
|
+
var tooLongError = /* @__PURE__ */ __name(() => new CliError("validation_error", `the audio is longer than ${LONGEST_AUDIO_SECONDS / 60} minutes`), "tooLongError");
|
|
84
|
+
var FLOAT = 3;
|
|
85
|
+
var LONGEST_HEADER = 64 * 1024;
|
|
86
|
+
var EXTENSIBLE = 65534;
|
|
87
|
+
var wavStream = /* @__PURE__ */ __name((most) => {
|
|
88
|
+
let head = Buffer.alloc(0);
|
|
89
|
+
let channels = 0;
|
|
90
|
+
let rate = 0;
|
|
91
|
+
let rest = Buffer.alloc(0);
|
|
92
|
+
let length = 0;
|
|
93
|
+
let parts = [];
|
|
94
|
+
const header = /* @__PURE__ */ __name(() => {
|
|
95
|
+
if (head.length < 12)
|
|
96
|
+
return false;
|
|
97
|
+
if (head.toString("latin1", 0, 4) !== "RIFF" || head.toString("latin1", 8, 12) !== "WAVE")
|
|
98
|
+
throw new CliError("validation_error", "ffmpeg did not answer with WAV audio");
|
|
99
|
+
for (let at = 12; at + 8 <= head.length; ) {
|
|
100
|
+
const id = head.toString("latin1", at, at + 4);
|
|
101
|
+
const size = head.readUInt32LE(at + 4);
|
|
102
|
+
if (id === "data") {
|
|
103
|
+
rest = head.subarray(at + 8);
|
|
104
|
+
head = Buffer.alloc(0);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
if (at + 8 + size > head.length)
|
|
108
|
+
return false;
|
|
109
|
+
if (id === "fmt ") {
|
|
110
|
+
const tag = head.readUInt16LE(at + 8);
|
|
111
|
+
channels = head.readUInt16LE(at + 10);
|
|
112
|
+
rate = head.readUInt32LE(at + 12);
|
|
113
|
+
if (tag !== FLOAT && tag !== EXTENSIBLE || head.readUInt16LE(at + 22) !== 32 || channels < 1)
|
|
114
|
+
throw new CliError("validation_error", "ffmpeg did not answer with 32-bit float samples");
|
|
115
|
+
parts = Array.from({ length: channels }, () => []);
|
|
116
|
+
}
|
|
117
|
+
at += 8 + size + size % 2;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}, "header");
|
|
121
|
+
return {
|
|
122
|
+
push: /* @__PURE__ */ __name((chunk) => {
|
|
123
|
+
if (channels === 0 || head.length > 0) {
|
|
124
|
+
head = Buffer.concat([head, chunk]);
|
|
125
|
+
if (head.length > LONGEST_HEADER)
|
|
126
|
+
throw new CliError("validation_error", "ffmpeg's WAV header never ended");
|
|
127
|
+
if (!header())
|
|
128
|
+
return true;
|
|
129
|
+
chunk = Buffer.alloc(0);
|
|
130
|
+
}
|
|
131
|
+
const bytes = rest.length ? Buffer.concat([rest, chunk]) : chunk;
|
|
132
|
+
const frame = channels * 4;
|
|
133
|
+
const frames = Math.floor(bytes.length / frame);
|
|
134
|
+
rest = Buffer.from(bytes.subarray(frames * frame));
|
|
135
|
+
if (frames === 0)
|
|
136
|
+
return length <= most;
|
|
137
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, frames * frame);
|
|
138
|
+
for (let channel = 0; channel < channels; channel++) {
|
|
139
|
+
const samples = new Float32Array(frames);
|
|
140
|
+
for (let index = 0; index < frames; index++)
|
|
141
|
+
samples[index] = view.getFloat32(index * frame + channel * 4, true);
|
|
142
|
+
parts[channel]?.push(samples);
|
|
143
|
+
}
|
|
144
|
+
length += frames;
|
|
145
|
+
return length <= most;
|
|
146
|
+
}, "push"),
|
|
147
|
+
end: /* @__PURE__ */ __name(() => {
|
|
148
|
+
if (channels === 0)
|
|
149
|
+
throw new CliError("validation_error", "no audio in that file");
|
|
150
|
+
return parts.map((pieces, channel) => {
|
|
151
|
+
const samples = new Float32Array(length);
|
|
152
|
+
let at = 0;
|
|
153
|
+
for (const piece of pieces) {
|
|
154
|
+
samples.set(piece, at);
|
|
155
|
+
at += piece.length;
|
|
156
|
+
}
|
|
157
|
+
parts[channel] = [];
|
|
158
|
+
return { samples, rate };
|
|
159
|
+
});
|
|
160
|
+
}, "end")
|
|
161
|
+
};
|
|
162
|
+
}, "wavStream");
|
|
163
|
+
var runFfmpegFile = /* @__PURE__ */ __name((path) => new Promise((resolve, reject) => {
|
|
164
|
+
const child = spawn("ffmpeg", [
|
|
165
|
+
"-nostdin",
|
|
166
|
+
"-hide_banner",
|
|
167
|
+
"-loglevel",
|
|
168
|
+
"error",
|
|
169
|
+
"-protocol_whitelist",
|
|
170
|
+
"file",
|
|
171
|
+
"-format_whitelist",
|
|
172
|
+
FFMPEG_FORMATS,
|
|
173
|
+
"-i",
|
|
174
|
+
path,
|
|
175
|
+
"-vn",
|
|
176
|
+
"-af",
|
|
177
|
+
"aformat=channel_layouts=mono|stereo",
|
|
178
|
+
"-ar",
|
|
179
|
+
String(SAMPLE_RATE),
|
|
180
|
+
"-c:a",
|
|
181
|
+
"pcm_f32le",
|
|
182
|
+
"-bitexact",
|
|
183
|
+
"-f",
|
|
184
|
+
"wav",
|
|
185
|
+
"pipe:1"
|
|
186
|
+
], { stdio: ["ignore", "pipe", "pipe"], timeout: FFMPEG_TIMEOUT_MS });
|
|
187
|
+
const wav = wavStream(LONGEST_AUDIO_SECONDS * SAMPLE_RATE);
|
|
188
|
+
let long = false;
|
|
189
|
+
let broken;
|
|
190
|
+
let errors = "";
|
|
191
|
+
child.stdout.on("data", (chunk) => {
|
|
192
|
+
if (long || broken)
|
|
193
|
+
return;
|
|
194
|
+
try {
|
|
195
|
+
long = !wav.push(chunk);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
broken = error;
|
|
198
|
+
}
|
|
199
|
+
if (long || broken)
|
|
200
|
+
child.kill();
|
|
201
|
+
});
|
|
202
|
+
child.stderr.on("data", (chunk) => {
|
|
203
|
+
errors = (errors + chunk.toString()).slice(-500);
|
|
204
|
+
});
|
|
205
|
+
child.on("error", (error) => reject(error.code === "ENOENT" ? new CliError("validation_error", "only ffmpeg reads this audio format, and ffmpeg is not installed") : error));
|
|
206
|
+
child.on("close", (code) => {
|
|
207
|
+
if (long)
|
|
208
|
+
return reject(tooLongError());
|
|
209
|
+
if (broken)
|
|
210
|
+
return reject(broken);
|
|
211
|
+
if (code !== 0)
|
|
212
|
+
return reject(new CliError("validation_error", `ffmpeg could not read the audio: ${errors.trim() || code}`));
|
|
213
|
+
try {
|
|
214
|
+
resolve(wav.end());
|
|
215
|
+
} catch (error) {
|
|
216
|
+
reject(error);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}), "runFfmpegFile");
|
|
220
|
+
var runFfmpeg = /* @__PURE__ */ __name(async (bytes) => {
|
|
221
|
+
const directory = await mkdtemp(join(tmpdir(), "wirecat-audio-"));
|
|
222
|
+
try {
|
|
223
|
+
const input = join(directory, "audio");
|
|
224
|
+
await writeFile(input, bytes, { mode: 384 });
|
|
225
|
+
return await runFfmpegFile(input);
|
|
226
|
+
} finally {
|
|
227
|
+
await rm(directory, { recursive: true, force: true });
|
|
228
|
+
}
|
|
229
|
+
}, "runFfmpeg");
|
|
230
|
+
var BUNDLED = {
|
|
231
|
+
opus: decodeOgg,
|
|
232
|
+
vorbis: decodeVorbis,
|
|
233
|
+
flac: decodeFlac,
|
|
234
|
+
mp3: decodeMp3
|
|
235
|
+
};
|
|
236
|
+
var tooLong = /* @__PURE__ */ __name((pcm) => pcm.samples.length / pcm.rate > LONGEST_AUDIO_SECONDS, "tooLong");
|
|
237
|
+
var fromFfmpeg = /* @__PURE__ */ __name((answer) => Array.isArray(answer) ? { channels: answer, mixed: false } : { channels: [answer], mixed: true }, "fromFfmpeg");
|
|
238
|
+
var decodeChannels = /* @__PURE__ */ __name(async (bytes, ffmpeg = runFfmpeg) => {
|
|
239
|
+
const format = formatOf(bytes);
|
|
240
|
+
const decoded = format === "other" ? fromFfmpeg(await ffmpeg(bytes)) : await BUNDLED[format](bytes).then((channels) => ({ channels, mixed: false }), (error) => ffmpeg(bytes).then(fromFfmpeg, () => {
|
|
241
|
+
throw error;
|
|
242
|
+
}));
|
|
243
|
+
if (decoded.channels.length === 0)
|
|
244
|
+
throw new CliError("validation_error", "no audio in that file");
|
|
245
|
+
if (decoded.channels.some(tooLong))
|
|
246
|
+
throw tooLongError();
|
|
247
|
+
return decoded;
|
|
248
|
+
}, "decodeChannels");
|
|
249
|
+
var decodeChannelsFile = /* @__PURE__ */ __name(async (path, { maxBytes = 64 * 1024 * 1024, ffmpegFile = runFfmpegFile } = {}) => {
|
|
250
|
+
const file = await open(path, "r");
|
|
251
|
+
let start;
|
|
252
|
+
let size;
|
|
253
|
+
try {
|
|
254
|
+
size = (await file.stat()).size;
|
|
255
|
+
const head = Buffer.alloc(Math.min(size, 128));
|
|
256
|
+
await file.read(head, 0, head.length, 0);
|
|
257
|
+
start = head;
|
|
258
|
+
} finally {
|
|
259
|
+
await file.close();
|
|
260
|
+
}
|
|
261
|
+
if (formatOf(start) === "other") {
|
|
262
|
+
const channels = await ffmpegFile(path);
|
|
263
|
+
if (channels.some(tooLong))
|
|
264
|
+
throw tooLongError();
|
|
265
|
+
return { channels, mixed: false };
|
|
266
|
+
}
|
|
267
|
+
if (size > maxBytes)
|
|
268
|
+
throw new CliError("validation_error", `the audio file is larger than ${Math.round(maxBytes / 1024 / 1024)} MB`, {
|
|
269
|
+
reason: "file.too-large"
|
|
270
|
+
});
|
|
271
|
+
return decodeChannels(new Uint8Array(await readFile(path)), () => ffmpegFile(path));
|
|
272
|
+
}, "decodeChannelsFile");
|
|
273
|
+
var mixDown = /* @__PURE__ */ __name((channels) => {
|
|
274
|
+
const [first] = channels;
|
|
275
|
+
if (!first)
|
|
276
|
+
throw new CliError("validation_error", "no audio in that file");
|
|
277
|
+
if (channels.length === 1)
|
|
278
|
+
return first;
|
|
279
|
+
const length = channels.reduce((longest, { samples: samples2 }) => Math.max(longest, samples2.length), 0);
|
|
280
|
+
const samples = new Float32Array(length);
|
|
281
|
+
for (const channel of channels)
|
|
282
|
+
for (let index = 0; index < channel.samples.length; index++)
|
|
283
|
+
samples[index] = (samples[index] ?? 0) + (channel.samples[index] ?? 0) / channels.length;
|
|
284
|
+
return { samples, rate: first.rate };
|
|
285
|
+
}, "mixDown");
|
|
286
|
+
var decodeAudio = /* @__PURE__ */ __name(async (bytes, ffmpeg = runFfmpeg) => mixDown((await decodeChannels(bytes, ffmpeg)).channels), "decodeAudio");
|
|
287
|
+
export {
|
|
288
|
+
LONGEST_AUDIO_SECONDS,
|
|
289
|
+
decodeAudio,
|
|
290
|
+
decodeChannels,
|
|
291
|
+
decodeChannelsFile,
|
|
292
|
+
formatOf,
|
|
293
|
+
mixDown,
|
|
294
|
+
runFfmpeg,
|
|
295
|
+
runFfmpegFile,
|
|
296
|
+
wavStream
|
|
297
|
+
};
|