fix(audio): 移除 Resampler 测试代码并优化停滞检测
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
通过测试确认 Resampler 和 WAV 解码正常工作,移除测试代码: - 移除手动读取 Resampler 的测试代码(测试读取会破坏 Resampler 内部状态) - 优化停滞检测逻辑:只有在已经开始播放后才报告停滞 - 修复语法错误(多余的闭合括号) 测试表明 Resampler 本身工作正常,数据读取成功。现在移除测试代码, 观察是否能正常播放完整音频。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -39,17 +39,8 @@ func PlayWav(c context.Context, r io.Reader) {
|
|||||||
s := beep.Resample(4, format.SampleRate, DefaultSampleRate, streamer)
|
s := beep.Resample(4, format.SampleRate, DefaultSampleRate, streamer)
|
||||||
|
|
||||||
ctrl := &beep.Ctrl{Streamer: s}
|
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{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
speaker.Play(beep.Seq(ctrl, beep.Callback(func() {
|
speaker.Play(beep.Seq(ctrl, beep.Callback(func() {
|
||||||
zap.S().Debugln("音频播放完成")
|
zap.S().Debugln("音频播放完成")
|
||||||
close(done)
|
close(done)
|
||||||
@@ -79,9 +70,9 @@ func PlayWav(c context.Context, r io.Reader) {
|
|||||||
currentTime := float64(pos) / float64(format.SampleRate)
|
currentTime := float64(pos) / float64(format.SampleRate)
|
||||||
zap.S().Debugf("播放进度: %d/%d (%.1f%%), %.2f秒", pos, totalSamples, progress, currentTime)
|
zap.S().Debugf("播放进度: %d/%d (%.1f%%), %.2f秒", pos, totalSamples, progress, currentTime)
|
||||||
lastPos = pos
|
lastPos = pos
|
||||||
} else {
|
} else if lastPos > 0 {
|
||||||
zap.S().Debugf("播放停滞在位置: %d/%d, Streamer状态: %v",
|
// 只有在已经开始播放后才报告停滞
|
||||||
pos, totalSamples, ctrl.Streamer != nil)
|
zap.S().Debugf("播放停滞在位置: %d/%d", pos, totalSamples)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user