fix(tts): 修复 TTS 播放卡死问题并增强日志
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
- 添加 SoundWithContext 方法,使用请求 context 而非全局 context - 修复 TTS 使用服务器全局 context 导致无法取消的问题 - 添加详细的诊断日志(解码、播放、TTS 合成各阶段) - 检测并记录 TTS 合成数据为空的情况 修复前 TTS 播放使用全局 context,当播放卡住时无法通过超时 或取消机制中断,导致后续任务永远无法执行。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,16 +10,24 @@ import (
|
||||
func SoundStart() leaf.HandlerFunc {
|
||||
return func(c *leaf.Context) {
|
||||
pm := leaf.Value[*schema.PlayModal](c, PayloadJSONKey)
|
||||
tts.DefaultTTS.Sound(pm.TTS.Start)
|
||||
|
||||
// 使用请求的 context,支持取消和超时
|
||||
if pm.TTS.Start != "" {
|
||||
tts.DefaultTTS.SoundWithContext(c, pm.TTS.Start)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
var text string
|
||||
switch leaf.Value[leaf.EndType](c, leaf.EndKey) {
|
||||
case leaf.End:
|
||||
tts.DefaultTTS.Sound(pm.TTS.End)
|
||||
text = pm.TTS.End
|
||||
case leaf.EndTimeout:
|
||||
tts.DefaultTTS.Sound(pm.TTS.Timeout)
|
||||
text = pm.TTS.Timeout
|
||||
case leaf.EndStop:
|
||||
tts.DefaultTTS.Sound(pm.TTS.Stop)
|
||||
text = pm.TTS.Stop
|
||||
}
|
||||
if text != "" {
|
||||
tts.DefaultTTS.SoundWithContext(c, text)
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user