feat(voice): 提升桌面端语音交互与本地任务执行支持

This commit is contained in:
Blizzard
2026-07-24 16:40:25 +08:00
parent e9a8b9b4c6
commit aba88193d8
33 changed files with 1909 additions and 102 deletions
@@ -55,8 +55,17 @@ func (h *Handler) VoiceStream(c *gin.Context) {
tenantID: tenantID(c), sessionID: sessionID(c),
jarvisName: jname, jarvisPersona: jpersona,
}
// 语音事件通道(JARVIS 动作/主动播报):会话生命周期内订阅本用户主题。
// navigate → 转发客户端执行;announce → 对话流显示 + TTS 念出来。
unsubEv, everr := h.bus.SubscribeVoiceEvent(uid, sess.onVoiceEvent)
if everr != nil {
log.Printf("[voice] 订阅语音事件失败 uid=%s: %v", uid, everr) // 降级:会话照常,仅无动作/播报
}
sess.send(voice.ServerMsg{Type: voice.ServerReady})
sess.run()
if unsubEv != nil {
_ = unsubEv()
}
sess.stopASR() // 连接结束,收掉在跑的识别会话
sess.stopTTS() // 连带停掉在朗读的下行 TTS
}
@@ -86,6 +95,9 @@ type voiceSession struct {
turnMu sync.Mutex // 护住一轮的转写累计 + 提交去重(ASR 结果 goroutine 与 ClientEnd 兜底 goroutine 都访问)
latestText string // 本轮最近一次转写(部分/最终);ClientEnd 时兜底用它提交
submitted bool // 本轮是否已提交——Final 与 ClientEnd 两条路径只落一次
annMu sync.Mutex // 护住主动播报队列(NATS 事件 goroutine 与 TTS 收尾 goroutine 都访问)
pendingAnn []string // 正在朗读时到达的播报先排队,本轮 TTS 播完再念(别抢麦)
}
// send 下发一条控制/事件消息(文本帧,JSON)。并发安全。