Add PTT (voice) upload support with FFmpeg addon
Introduce NT SILK-based voice (PTT) upload pipeline and native FFmpeg addon wrapper. - Add ffmpeg-addon wrapper (packages/core/src/bridge/highway/ffmpeg-addon.ts) to load platform/arch .node binaries, detect SILK files, and convert inputs to NT SILK via the native addon. Provides encodeSilk, isSilkFile and default temp dir helpers. - Implement ptt-upload pipeline (packages/core/src/bridge/highway/ptt-upload.ts) to: resolve/fetch audio bytes, convert to NT SILK if needed, send OIDB upload request, perform highway HTTP upload when required, and produce Encodable MsgInfo bytes for commonElem. - Wire record element support into element-builder: uploadPttMsgInfo is used to build a commonElem for 'record' sends; when SendContext is absent, record sends are skipped with a warning (graceful no-bridge path). - Update message parsing to accept record segments from data.file, data.url or data.path and drop empty sources. - Enable canSendRecord in OneBot instance context. - Add tests covering record parsing and the graceful send path (packages/core/tests/message-parser.test.ts). - Include prebuilt native ffmpeg addon binaries under packages/runtime/native/ffmpeg and update vite config to validate & copy the ffmpeg addon into the dist layout. These changes enable sending voice messages by converting/encoding sources to the expected NT SILK format and uploading them through the existing highway/NTV2 flows.
This commit is contained in:
1 parent
2af273b9e2
commit
c39b3f5c4e
11 files changed
+525
-5
No files matched your search
@@ -26,7 +26,7 @@ const nativeSrc = toPosix(nativeDir);
|
||||
// Target selection: `SNOWLUMA_TARGET=<platform>-<arch>` overrides the host
|
||||
// detection, enabling cross-target packaging on CI.
|
||||
const targetTriple = process.env.SNOWLUMA_TARGET ?? `${process.platform}-${process.arch}`;
|
||||
const targetPlatform = targetTriple.split('-')[0];
|
||||
const [targetPlatform, targetArch] = targetTriple.split('-');
|
||||
|
||||
// Runtime scaffolding files copied into dist/. The NTQQ hook is Windows-only,
|
||||
// so its launcher/shell script differ per target.
|
||||
@@ -47,12 +47,22 @@ const nativeFiles = [
|
||||
: []),
|
||||
];
|
||||
|
||||
// FFmpeg native addon ported from NapCat. Uses NapCat's
|
||||
// `<platform>.<arch>` naming so the prebuilt binaries can be vendored
|
||||
// as-is without renaming. Lives under `native/ffmpeg/` to keep it
|
||||
// separate from the SnowLuma flat-naming addons above.
|
||||
const ffmpegAddonFile = `ffmpegAddon.${targetPlatform}.${targetArch}.node`;
|
||||
const ffmpegSrcDir = path.resolve(nativeDir, 'ffmpeg');
|
||||
|
||||
// Fail fast if any expected native binary is missing from packages/runtime/native/.
|
||||
// vite-plugin-cp only emits a warning on missing source files; we want a hard
|
||||
// error so CI can't accidentally ship an incomplete archive.
|
||||
const missingNatives = nativeFiles.filter(
|
||||
(f) => !fs.existsSync(path.join(nativeDir, f)),
|
||||
);
|
||||
if (!fs.existsSync(path.join(ffmpegSrcDir, ffmpegAddonFile))) {
|
||||
missingNatives.push(`ffmpeg/${ffmpegAddonFile}`);
|
||||
}
|
||||
if (missingNatives.length > 0) {
|
||||
throw new Error(
|
||||
`Missing native binaries for target ${targetTriple}:\n` +
|
||||
@@ -73,6 +83,11 @@ const BaseConfigPlugin: PluginOption[] = [
|
||||
dest: path.join(distDir, 'native'),
|
||||
flatten: true,
|
||||
})),
|
||||
{
|
||||
src: `${toPosix(ffmpegSrcDir)}/${ffmpegAddonFile}`,
|
||||
dest: path.join(distDir, 'native', 'ffmpeg'),
|
||||
flatten: true,
|
||||
},
|
||||
]
|
||||
})
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user