fix: 修复语音消息取错、时长精度与转写不刷新

- 时长解析:改取 <voicemsg voicelength>(毫秒),不再误取 length(SILK 字节数)
- 时长显示:四舍五入对齐微信口径,有原生时长时不被解码时长覆盖
- 转写:重新识别改为强制重算,跳过身份级缓存短路(音频级缓存仍生效)
- 日报:语音累计秒数显示取整,不再出现小数
This commit is contained in:
Wxw-Gu committed 2026-09-20 15:40:01 +08:00
1 parent 9b82d29037
commit 9593ca0f54
21 files changed
+435 -52

No files matched your search

+21 -13
View File
@@ -37,21 +37,29 @@ export class VoicePipeline {
async run(
accountId: string,
reference: VoiceMessageReference,
signal?: AbortSignal
signal?: AbortSignal,
options?: { force?: boolean }
): Promise<{ transcript: string; language?: string; durationMs: number; cached: boolean }> {
const messageIdentity = voiceMessageIdentity(reference)
const compatible = this.transcripts.findCompatible({
accountId,
messageIdentity,
processorVersion: this.audioProcessor.version,
...this.recognizer.metadata
})
if (compatible?.transcript.trim()) {
return {
transcript: compatible.transcript.trim(),
language: compatible.language,
durationMs: compatible.durationMs,
cached: true
/*
* findCompatible 只按消息身份匹配,不含 audio_hash:音频被换掉(例如取音频的
* 逻辑修好后)时它仍会命中旧记录。用户主动触发的识别必须跳过它,重新取一次
* 音频 —— 音频级缓存 find(key) 带 audio_hash,才是正确的失效机制。
*/
if (!options?.force) {
const compatible = this.transcripts.findCompatible({
accountId,
messageIdentity,
processorVersion: this.audioProcessor.version,
...this.recognizer.metadata
})
if (compatible?.transcript.trim()) {
return {
transcript: compatible.transcript.trim(),
language: compatible.language,
durationMs: compatible.durationMs,
cached: true
}
}
}
@@ -23,6 +23,7 @@ type TranscriptUpdateListener = (update: VoiceTranscriptUpdate) => Promise<void>
type RecognitionOptions = {
priority?: VoiceRecognitionPriority
publishTranscriptUpdate?: boolean
force?: boolean
}
export class VoiceRecognitionUseCase {
@@ -108,7 +109,9 @@ export class VoiceRecognitionUseCase {
error: '请先下载语音识别模型'
} as const
}
const result = await pipeline.run(accountId, reference, signal)
const result = await pipeline.run(accountId, reference, signal, {
force: options?.force
})
if (signal.aborted || !this.isCurrentAccount(accountId, generation)) {
throw new DOMException('Recognition cancelled', 'AbortError')
}