diff --git a/packages/protocol/tests/native/audio-transcode.test.ts b/packages/protocol/tests/native/audio-transcode.test.ts index 0a54ce3e..29c7ac15 100644 --- a/packages/protocol/tests/native/audio-transcode.test.ts +++ b/packages/protocol/tests/native/audio-transcode.test.ts @@ -72,6 +72,48 @@ describeBundledAddon('bundled native ffmpeg addon', () => { }); afterAll(() => rmSync(tmpDir, { recursive: true, force: true })); + describe.each(['silk', 'ntsilk', 'extensionless'] as const)('%s duration', (format) => { + it.each([0.02, 1, 2.5])('measures %s seconds from the encoded frames', async (seconds) => { + const addon = loadBundledAddon(); + const wavPath = path.join(tmpDir, `duration-${format}-${seconds}.wav`); + const recordPath = path.join( + tmpDir, + `duration-${format}-${seconds}${format === 'extensionless' ? '' : `.${format}`}`, + ); + writeFileSync(wavPath, makeMonoWav(24_000, seconds)); + await addon.convertToNTSilkTct(wavPath, recordPath); + + if (format === 'silk') { + // Standard SILK has the same packets without the QQ container prefix. + const encoded = readFileSync(recordPath); + expect(encoded.subarray(0, 10)).toEqual( + Buffer.concat([Buffer.from([0x02]), Buffer.from('#!SILK_V3', 'ascii')]), + ); + writeFileSync(recordPath, encoded.subarray(1)); + } + + expect(await addon.getDuration(recordPath)).toBeCloseTo(seconds, 6); + }); + + it('rejects a truncated packet instead of reporting a duration', async () => { + const addon = loadBundledAddon(); + const wavPath = path.join(tmpDir, `truncated-${format}.wav`); + const recordPath = path.join( + tmpDir, + `truncated-${format}${format === 'extensionless' ? '' : `.${format}`}`, + ); + writeFileSync(wavPath, makeMonoWav()); + await addon.convertToNTSilkTct(wavPath, recordPath); + const encoded = readFileSync(recordPath); + writeFileSync( + recordPath, + encoded.subarray(format === 'silk' ? 1 : 0, encoded.length - 1), + ); + + await expect(addon.getDuration(recordPath)).rejects.toThrow(/Invalid data/); + }); + }); + it('converts a mono QQ-style SILK record to a decodable MP3 through the public transcode seam', async () => { const addon = loadBundledAddon(); const wavPath = path.join(tmpDir, 'mono-input.wav'); diff --git a/packages/runtime/native/ffmpeg/README.md b/packages/runtime/native/ffmpeg/README.md new file mode 100644 index 00000000..cf22bff5 --- /dev/null +++ b/packages/runtime/native/ffmpeg/README.md @@ -0,0 +1,24 @@ +# Bundled FFmpeg addon + +These binaries are unmodified build artifacts from +[NapNeko/ffmpegAddon](https://github.com/NapNeko/ffmpegAddon) (upstream package license: MIT). + +- Source commit: [`9ac944793ffdc2a1c5c55f16e24cb32185feb4ec`](https://github.com/NapNeko/ffmpegAddon/commit/9ac944793ffdc2a1c5c55f16e24cb32185feb4ec) +- Successful build: [38025527136](https://github.com/NapNeko/ffmpegAddon/actions/runs/38025527136) +- Each downloaded artifact archive was verified against its GitHub SHA-256 digest before extraction. + +| Bundled file | Upstream artifact | Binary SHA-256 | +| --- | --- | --- | +| `ffmpegAddon.win32.x64.node` | `ffmpeg-addon-windows` | `80a4dfbb170f093f4a64fe241b8583fb630c58219100cad7a3cad798f71864db` | +| `ffmpegAddon.linux.x64.node` | `ffmpeg-addon-linux` | `b75e45ba54d3ba5dbea42ed0cbe13cbcc4a2e38e889272aca272913675ff6402` | +| `ffmpegAddon.linux.arm64.node` | `ffmpeg-addon-linux-arm64` | `92f04767db5cb292a2158d8a7451a07c2cba9b4ba8654b18b7f668991c2c160b` | +| `ffmpegAddon.darwin.arm64.node` | `ffmpeg-addon-macos-arm64` | `c578932c04b40e36b32601a86d3833dbd9892df13bd13dbe9355623da0144cbf` | + +`getDuration(path)` supports standard SILK and QQ NTSILK containers, including +files without an extension. It measures the encoded frames and rejects truncated +packets. SnowLuma's existing voice upload path uses this duration when accepting +an already encoded SILK file. + +Run `pnpm test:native` from the repository root to exercise the bundled addon on +Windows x64 or Linux x64/arm64. The tests generate synthetic audio and cover +SILK/NTSILK durations, truncated packets, and QQ/QQ AI voice transcoding. diff --git a/packages/runtime/native/ffmpeg/ffmpegAddon.darwin.arm64.node b/packages/runtime/native/ffmpeg/ffmpegAddon.darwin.arm64.node index 88feea5b..11b16ed7 100644 Binary files a/packages/runtime/native/ffmpeg/ffmpegAddon.darwin.arm64.node and b/packages/runtime/native/ffmpeg/ffmpegAddon.darwin.arm64.node differ diff --git a/packages/runtime/native/ffmpeg/ffmpegAddon.linux.arm64.node b/packages/runtime/native/ffmpeg/ffmpegAddon.linux.arm64.node index 29380a7b..87642d82 100644 Binary files a/packages/runtime/native/ffmpeg/ffmpegAddon.linux.arm64.node and b/packages/runtime/native/ffmpeg/ffmpegAddon.linux.arm64.node differ diff --git a/packages/runtime/native/ffmpeg/ffmpegAddon.linux.x64.node b/packages/runtime/native/ffmpeg/ffmpegAddon.linux.x64.node index e6642345..58802511 100644 Binary files a/packages/runtime/native/ffmpeg/ffmpegAddon.linux.x64.node and b/packages/runtime/native/ffmpeg/ffmpegAddon.linux.x64.node differ diff --git a/packages/runtime/native/ffmpeg/ffmpegAddon.win32.x64.node b/packages/runtime/native/ffmpeg/ffmpegAddon.win32.x64.node index 9e771b74..c76e3fc3 100644 Binary files a/packages/runtime/native/ffmpeg/ffmpegAddon.win32.x64.node and b/packages/runtime/native/ffmpeg/ffmpegAddon.win32.x64.node differ