惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
A
About on SuperTechFans
Vercel News
Vercel News
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
V
Visual Studio Blog
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
美团技术团队

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(qqbot): remove native ffmpeg subprocess fallback · op...
vincentkoc · 2026-05-03 · via Recent Commits to openclaw:main

@@ -3,18 +3,16 @@

33

* 音频格式转换工具。

44

*

55

* Handles SILK ↔ PCM ↔ WAV ↔ MP3 conversions for QQ Bot voice messaging.

6-

* Prefers ffmpeg when available; falls back to WASM decoders (silk-wasm,

7-

* mpg123-decoder) for environments without native tooling.

6+

* Uses WASM decoders (silk-wasm, mpg123-decoder) and direct QQ-native uploads

7+

* without launching native subprocesses.

88

*

99

* Self-contained within engine/ — no framework SDK dependency.

1010

*/

111112-

import { execFile } from "node:child_process";

1312

import * as fs from "node:fs";

1413

import * as path from "node:path";

1514

import { formatErrorMessage } from "./format.js";

1615

import { debugLog, debugError, debugWarn } from "./log.js";

17-

import { detectFfmpeg, isWindows } from "./platform.js";

1816

import { normalizeLowercaseStringOrEmpty as normalizeLowercase } from "./string-normalize.js";

19172018

type SilkWasm = typeof import("silk-wasm");

@@ -184,7 +182,7 @@ function normalizeFormats(formats: string[]): string[] {

184182

/**

185183

* Convert a local audio file to Base64-encoded SILK for QQ API upload.

186184

*

187-

* Attempts conversion via ffmpeg → WASM decoders → null fallback chain.

185+

* Attempts conversion via direct QQ-native upload → WASM decoders → null fallback chain.

188186

*/

189187

export async function audioFileToSilkBase64(

190188

filePath: string,

@@ -234,25 +232,6 @@ export async function audioFileToSilkBase64(

234232235233

const targetRate = 24000;

236234237-

const ffmpegCmd = await detectFfmpeg();

238-

if (ffmpegCmd) {

239-

try {

240-

debugLog(

241-

`[audio-convert] ffmpeg (${ffmpegCmd}): converting ${ext} (${buf.length} bytes) → PCM s16le ${targetRate}Hz`,

242-

);

243-

const pcmBuf = await ffmpegToPCM(ffmpegCmd, filePath, targetRate);

244-

if (pcmBuf.length === 0) {

245-

debugError(`[audio-convert] ffmpeg produced empty PCM output`);

246-

return null;

247-

}

248-

const { silkBuffer } = await pcmToSilk(pcmBuf, targetRate);

249-

debugLog(`[audio-convert] ffmpeg: ${ext} → SILK done (${silkBuffer.length} bytes)`);

250-

return silkBuffer.toString("base64");

251-

} catch (err) {

252-

debugError(`[audio-convert] ffmpeg conversion failed: ${formatErrorMessage(err)}`);

253-

}

254-

}

255-256235

debugLog(`[audio-convert] fallback: trying WASM decoders for ${ext}`);

257236258237

if (ext === ".pcm") {

@@ -278,12 +257,9 @@ export async function audioFileToSilkBase64(

278257

}

279258

}

280259281-

const installHint = isWindows()

282-

? "Install ffmpeg with choco install ffmpeg, scoop install ffmpeg, or from https://ffmpeg.org"

283-

: process.platform === "darwin"

284-

? "Install ffmpeg with brew install ffmpeg"

285-

: "Install ffmpeg with sudo apt install ffmpeg or sudo yum install ffmpeg";

286-

debugError(`[audio-convert] unsupported format: ${ext} (no ffmpeg available). ${installHint}`);

260+

debugError(

261+

`[audio-convert] unsupported format without native subprocess conversion: ${ext}. Use QQ-native voice formats or WAV/MP3/PCM inputs.`,

262+

);

287263

return null;

288264

}

289265

@@ -386,48 +362,7 @@ async function pcmToSilk(

386362

};

387363

}

388364389-

/** Use ffmpeg to convert any audio to mono 24 kHz PCM s16le. */

390-

function ffmpegToPCM(

391-

ffmpegCmd: string,

392-

inputPath: string,

393-

sampleRate: number = 24000,

394-

): Promise<Buffer> {

395-

return new Promise((resolve, reject) => {

396-

const args = [

397-

"-i",

398-

inputPath,

399-

"-f",

400-

"s16le",

401-

"-ar",

402-

String(sampleRate),

403-

"-ac",

404-

"1",

405-

"-acodec",

406-

"pcm_s16le",

407-

"-v",

408-

"error",

409-

"pipe:1",

410-

];

411-

execFile(

412-

ffmpegCmd,

413-

args,

414-

{

415-

maxBuffer: 50 * 1024 * 1024,

416-

encoding: "buffer",

417-

...(isWindows() ? { windowsHide: true } : {}),

418-

},

419-

(err, stdout) => {

420-

if (err) {

421-

reject(new Error(`ffmpeg failed: ${err.message}`));

422-

return;

423-

}

424-

resolve(stdout as unknown as Buffer);

425-

},

426-

);

427-

});

428-

}

429-430-

/** Decode MP3 to PCM via mpg123-decoder WASM (fallback when ffmpeg is unavailable). */

365+

/** Decode MP3 to PCM via mpg123-decoder WASM. */

431366

async function wasmDecodeMp3ToPCM(buf: Buffer, targetRate: number): Promise<Buffer | null> {

432367

try {

433368

const { MPEGDecoder } = await import("mpg123-decoder");

@@ -502,7 +437,7 @@ async function wasmDecodeMp3ToPCM(buf: Buffer, targetRate: number): Promise<Buff

502437

}

503438

}

504439505-

/** Parse a standard PCM WAV and extract mono 24 kHz PCM data (fallback without ffmpeg). */

440+

/** Parse a standard PCM WAV and extract mono 24 kHz PCM data. */

506441

export function parseWavFallback(buf: Buffer): Buffer | null {

507442

if (buf.length < 44) {

508443

return null;