feat(onebot): voice-to-text action fetch_ptt_text (#79)
Adds NapCat-compatible voice-to-text. New `fetch_ptt_text` action (aliases
`get_ptt_text` / `get_record_text`) takes a message_id, resolves the cached
`record` fingerprint (uuid + md5 + duration/size/format), drives QQ's native
`pttTrans.TransC2CPttReq` / `pttTrans.TransGroupPttReq`, and returns { text }.
The response carries the text inline once transcription is done; an empty
text means the server is still transcribing (there is no dedicated push
command — confirmed via RE), so the bridge re-sends with a short backoff
until the text lands, mirroring NapCat's fire-then-re-read shape.
Layers:
- proto-defs/ptt-trans: PttTransReq/Resp + per-scene items.
- core ExtrasApi.translatePttToText: encode -> sendRawPacket -> decode -> poll.
- onebot media-actions.fetchPttText + api-handler/instance-context wiring.
- onebot extended: register the action + aliases.
The commands + request/response field tags were reverse-engineered from
QQ-NT wrapper.node (im_core/msg/ptt/ptt_trans_worker.cc). The numeric tags
are solid; the length-delimited fields (uuid/md5) and the response text tag
are RE-derived and want one live capture to confirm before relying on them.
This commit is contained in:
7 files changed
+237
No files matched your search
@@ -426,6 +426,25 @@ export const actions = [
|
||||
},
|
||||
}),
|
||||
|
||||
defineAction({
|
||||
// Primary name matches NapCat for drop-in migration; the rest are aliases.
|
||||
name: ['fetch_ptt_text', 'get_ptt_text', 'get_record_text'],
|
||||
summary: '获取语音转文字结果',
|
||||
params: {
|
||||
message_id: f.string().default(''),
|
||||
},
|
||||
// `raw` so message_id works whether the client sends a number or a string.
|
||||
run: async (_p, ctx, raw) => {
|
||||
const messageId = asNumber(raw.message_id);
|
||||
if (!messageId) return failedResponse(RETCODE.BAD_REQUEST, 'message_id is required');
|
||||
try {
|
||||
return okResponse(await ctx.fetchPttText(messageId));
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, e instanceof Error ? e.message : '获取语音转文字结果失败');
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
// Cookie、CSRF 令牌和账号信息
|
||||
defineAction({
|
||||
name: 'get_cookies',
|
||||
|
||||
Reference in new issue
Block a user