fix(audio): 修复音频播放死循环并增强错误日志
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
- 修复 PlayWav 和 PlayMP3 在 context 取消时的死循环 bug - 添加 WAV/MP3 解码失败的错误日志 - 添加 TTS 播放开始/完成的日志,便于排查问题 修复前 context 取消会导致无限循环,阻塞后续任务执行。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,7 @@ func init() {
|
||||
func PlayWav(c context.Context, r io.Reader) {
|
||||
streamer, format, err := wav.Decode(r)
|
||||
if err != nil {
|
||||
zap.S().Errorln("WAV解码失败: ", err)
|
||||
return
|
||||
}
|
||||
defer streamer.Close()
|
||||
@@ -45,6 +46,7 @@ func PlayWav(c context.Context, r io.Reader) {
|
||||
speaker.Lock()
|
||||
ctrl.Streamer = nil
|
||||
speaker.Unlock()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,6 +55,7 @@ func PlayWav(c context.Context, r io.Reader) {
|
||||
func PlayMP3(c context.Context, r io.ReadCloser) {
|
||||
streamer, format, err := mp3.Decode(r)
|
||||
if err != nil {
|
||||
zap.S().Errorln("MP3解码失败: ", err)
|
||||
return
|
||||
}
|
||||
defer streamer.Close()
|
||||
@@ -74,6 +77,7 @@ func PlayMP3(c context.Context, r io.ReadCloser) {
|
||||
speaker.Lock()
|
||||
ctrl.Streamer = nil
|
||||
speaker.Unlock()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user