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
@@ -87,6 +87,30 @@ describe('parseMessage', () => {
|
||||
expect(result[0].url).toBe('https://example.com/img.png');
|
||||
});
|
||||
|
||||
it('parses record segment from data.file', async () => {
|
||||
const result = await parseMessage(
|
||||
[{ type: 'record', data: { file: 'file:///tmp/voice.amr' } }] as any,
|
||||
false,
|
||||
);
|
||||
expect(result).toEqual([{ type: 'record', url: 'file:///tmp/voice.amr' }]);
|
||||
});
|
||||
|
||||
it('parses record segment from data.path (NapCat parity)', async () => {
|
||||
const result = await parseMessage(
|
||||
[{ type: 'record', data: { path: 'C:\\voices\\hi.silk' } }] as any,
|
||||
false,
|
||||
);
|
||||
expect(result).toEqual([{ type: 'record', url: 'C:\\voices\\hi.silk' }]);
|
||||
});
|
||||
|
||||
it('drops record segment with empty source', async () => {
|
||||
const result = await parseMessage(
|
||||
[{ type: 'record', data: {} }] as any,
|
||||
false,
|
||||
);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it('parses at segment', async () => {
|
||||
const result = await parseMessage(
|
||||
[{ type: 'at', data: { qq: 12345 } }] as any,
|
||||
@@ -144,6 +168,24 @@ describe('parseMessage', () => {
|
||||
expect(protoElems[0].text?.str).toBe('@User ');
|
||||
});
|
||||
|
||||
it('skips record send when SendContext is absent (graceful no-bridge path)', async () => {
|
||||
// Without a SendContext, buildSendElems can't run highway upload —
|
||||
// it should warn and drop the element instead of throwing into the
|
||||
// ffmpegAddon (which would explode for callers that don't actually
|
||||
// need to send).
|
||||
const elements = await parseMessage(
|
||||
[
|
||||
{ type: 'text', data: { text: 'hi ' } },
|
||||
{ type: 'record', data: { file: '/tmp/x.silk' } },
|
||||
] as any,
|
||||
false,
|
||||
);
|
||||
const protoElems = await buildSendElems(elements);
|
||||
// Only the leading text should make it through.
|
||||
expect(protoElems).toHaveLength(1);
|
||||
expect(protoElems[0].text?.str).toBe('hi ');
|
||||
});
|
||||
|
||||
it('parses multiple segments', async () => {
|
||||
const result = await parseMessage(
|
||||
[
|
||||
|
||||
Reference in new issue
Block a user