Files
game-driver/pkg/audio/doc.go
mapleafgo 6ac23c28f1
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
feat(audio): 添加单声道转立体声转换功能
- 新增 monoToStereoReader 将单声道 WAV 实时转换为立体声
- PlayWav 自动检测单声道并应用转换管线
- 添加完整的单元测试覆盖转换逻辑
- 整理 import 顺序(goimports)

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-09 10:34:45 +08:00

35 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package audio 提供基于 oto/v3 的音频播放功能。
//
// 播放模式:
// - 一次性播放: PlayWav(), PlayMP3() - 阻塞直到完成或 context 取消
// - 循环播放: PlayMP3Loop() - 非阻塞,返回 player 和清理函数
//
// 使用示例:
//
// // 一次性播放 WAV
// err := audio.PlayWav(ctx, wavReader)
// if err != nil && !errors.Is(err, context.Canceled) {
// log.Printf("播放失败: %v", err)
// }
//
// // 循环播放 MP3
// player, cleanup, err := audio.PlayMP3Loop(mp3Reader)
// if err != nil {
// return err
// }
// defer cleanup()
// // ... 播放中 ...
//
// 采样率说明:
// - 统一采样率:固定使用 16000 HzTTS 原生采样率)
// - oto/v3 只支持一个全局 Context统一采样率可避免冲突
// - 其他采样率会自动重采样到 16000 Hz线性插值
// - 16000 Hz 音频TTS正常速度 ✅
// - 44100 Hz 音频BGM自动重采样正常速度 ✅
// - 其他采样率:自动重采样,正常速度 ✅
//
// 资源管理:
// - 一次性播放: 函数内部自动管理所有资源
// - 循环播放: 调用者必须调用 defer cleanup() 清理资源
package audio