diff --git a/pkg/audio/play.go b/pkg/audio/play.go index 7d4a89e..c9cb2a7 100644 --- a/pkg/audio/play.go +++ b/pkg/audio/play.go @@ -39,17 +39,8 @@ func PlayWav(c context.Context, r io.Reader) { s := beep.Resample(4, format.SampleRate, DefaultSampleRate, streamer) ctrl := &beep.Ctrl{Streamer: s} - - // 测试 Streamer 是否可以正常读取数据 - testSamples := make([][2]float64, 10) - n, ok := s.Stream(testSamples) - zap.S().Debugf("测试读取 Resampler: 读取 %d 样本, ok=%v, 数据=%v", n, ok, testSamples[:n]) - - // 重置 streamer - s = beep.Resample(4, format.SampleRate, DefaultSampleRate, streamer) - ctrl.Streamer = s - done := make(chan struct{}) + speaker.Play(beep.Seq(ctrl, beep.Callback(func() { zap.S().Debugln("音频播放完成") close(done) @@ -79,9 +70,9 @@ func PlayWav(c context.Context, r io.Reader) { currentTime := float64(pos) / float64(format.SampleRate) zap.S().Debugf("播放进度: %d/%d (%.1f%%), %.2f秒", pos, totalSamples, progress, currentTime) lastPos = pos - } else { - zap.S().Debugf("播放停滞在位置: %d/%d, Streamer状态: %v", - pos, totalSamples, ctrl.Streamer != nil) + } else if lastPos > 0 { + // 只有在已经开始播放后才报告停滞 + zap.S().Debugf("播放停滞在位置: %d/%d", pos, totalSamples) } } }