fix(protocol): transcode QQ AI voice recordings
Normalize the observed AI SILK container marker at the shared audio transcode boundary before invoking the bundled decoder. Preserve caller-owned bytes and leave ordinary SILK, AMR, and unrelated inputs unchanged. Add unit and packaged-addon regression coverage for MP3 conversion, payload preservation, and input immutability. Fixes #268
This commit is contained in:
3 files changed
+80
-2
No files matched your search
@@ -1,5 +1,12 @@
|
||||
import { afterAll, describe, expect, it, vi } from 'vitest';
|
||||
import { mkdtempSync, promises as fsPromises, readdirSync, rmSync, writeFileSync } from 'fs';
|
||||
import {
|
||||
mkdtempSync,
|
||||
promises as fsPromises,
|
||||
readFileSync,
|
||||
readdirSync,
|
||||
rmSync,
|
||||
writeFileSync,
|
||||
} from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { AUDIO_OUT_FORMATS, convertAudioBytes, isAudioOutFormat } from '@snowluma/protocol/highway/ffmpeg-addon';
|
||||
@@ -31,6 +38,31 @@ describe('isAudioOutFormat / AUDIO_OUT_FORMATS', () => {
|
||||
});
|
||||
|
||||
describe('convertAudioBytes', () => {
|
||||
it('accepts the QQ AI SILK container without mutating the caller bytes', async () => {
|
||||
const input = Buffer.concat([
|
||||
Buffer.from([0x03]),
|
||||
Buffer.from('#!SILK_V3', 'ascii'),
|
||||
Buffer.from([0x04, 0x00, 0x11, 0x22, 0x33, 0x44]),
|
||||
]);
|
||||
const originalInput = Buffer.from(input);
|
||||
let stagedInput: Buffer | null = null;
|
||||
const addon = {
|
||||
decodeAudioToFmt: async (inputPath: string, outputPath: string, format: string) => {
|
||||
stagedInput = readFileSync(inputPath);
|
||||
writeFileSync(outputPath, Buffer.from('MP3DATA'));
|
||||
return { result: true, sampleRate: 24_000, channels: 1, format };
|
||||
},
|
||||
};
|
||||
|
||||
await convertAudioBytes(input, 'mp3', { addon, tmpDir });
|
||||
|
||||
expect(stagedInput?.subarray(0, 10)).toEqual(
|
||||
Buffer.concat([Buffer.from([0x02]), Buffer.from('#!SILK_V3', 'ascii')]),
|
||||
);
|
||||
expect(stagedInput?.subarray(10)).toEqual(input.subarray(10));
|
||||
expect(input).toEqual(originalInput);
|
||||
});
|
||||
|
||||
it('transcodes and returns base64 + size of the addon output', async () => {
|
||||
const r = await convertAudioBytes(new Uint8Array([1, 2, 3]), 'wav', { addon: fakeOk, tmpDir });
|
||||
expect(Buffer.from(r.base64, 'base64').toString()).toBe('WAVDATA');
|
||||
|
||||
@@ -86,4 +86,28 @@ describeBundledAddon('bundled native ffmpeg addon', () => {
|
||||
expect(duration).toBeGreaterThan(0.9);
|
||||
expect(duration).toBeLessThan(1.2);
|
||||
});
|
||||
|
||||
it('converts the QQ AI SILK container variant through the public transcode seam', async () => {
|
||||
const addon = loadBundledAddon();
|
||||
const wavPath = path.join(tmpDir, 'ai-input.wav');
|
||||
const silkPath = path.join(tmpDir, 'ai-input.ntsilk');
|
||||
writeFileSync(wavPath, makeMonoWav());
|
||||
await addon.convertToNTSilkTct(wavPath, silkPath);
|
||||
|
||||
const aiSilk = readFileSync(silkPath);
|
||||
expect(aiSilk.subarray(0, 10)).toEqual(
|
||||
Buffer.concat([Buffer.from([0x02]), Buffer.from('#!SILK_V3', 'ascii')]),
|
||||
);
|
||||
aiSilk[0] = 0x03;
|
||||
|
||||
const result = await convertAudioBytes(aiSilk, 'mp3', { addon, tmpDir });
|
||||
const mp3 = Buffer.from(result.base64, 'base64');
|
||||
const outputPath = path.join(tmpDir, 'ai-output.mp3');
|
||||
writeFileSync(outputPath, mp3);
|
||||
|
||||
expect(hasMp3Signature(mp3)).toBe(true);
|
||||
const duration = await addon.getDuration(outputPath);
|
||||
expect(duration).toBeGreaterThan(0.9);
|
||||
expect(duration).toBeLessThan(1.2);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user