✨ feat: Web Audio 音频输出优化#958
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 本次拉取请求旨在通过引入 Web Audio 的 Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
| sharedContext = new AudioContextClass({ | ||
| latencyHint: settingStore.audioLatencyHint, | ||
| }) as IExtendedAudioContext; | ||
| sharedContext.latencyHint = settingStore.audioLatencyHint; |
| /** 扩充 AudioContext 接口以支持 setSinkId (实验性 API) */ | ||
| export interface IExtendedAudioContext extends AudioContext { | ||
| setSinkId(deviceId: string): Promise<void>; | ||
| latencyHint?: "playback" | "interactive"; |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
能不能加一个全局的歌词偏差让用户改( |
已在 b2a739b 加上了 |
|
/gemini review |
| sharedContext = new AudioContextClass({ | ||
| latencyHint: settingStore.audioLatencyHint, | ||
| }) as IExtendedAudioContext; | ||
| sharedContext.latencyHint = settingStore.audioLatencyHint; |
There was a problem hiding this comment.
我把这里的return (this.audioElement.currentTime || 0) + this.compensatedLatency; 换为return (this.audioElement.currentTime || 0) - this.compensatedLatency;,它的作用是?
|
/gemini review |
There was a problem hiding this comment.
Code Review
本次 PR 为 Web Audio 输出引入了 latencyHint 选项,允许用户在低延迟和高效能模式之间切换,并为高效能模式添加了延迟补偿,同时还增加了一个手动调整歌词同步偏移的设置。整体实现很清晰,通过添加必要的设置,将其应用于 AudioContext,并相应地调整了 currentTime 的计算。
我发现了一个小问题:代码尝试对一个只读属性进行赋值,这是多余的,应该移除。此外,我还建议改进相关的类型定义,以防止未来出现类似问题。总体而言,这是一项出色的功能增强。
| sharedContext = new AudioContextClass({ | ||
| latencyHint: settingStore.audioLatencyHint, | ||
| }) as IExtendedAudioContext; | ||
| sharedContext.latencyHint = settingStore.audioLatencyHint; |
There was a problem hiding this comment.
AudioContext 实例上的 latencyHint 属性是只读的。它的值在创建时确定,之后无法更改。
你已经在第 26 行的 AudioContext 构造函数中正确地传递了 latencyHint。因此,这一行代码是多余且不正确的,应当移除。
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…-audio-optimization
|
/gemini review |

本次修改为 Web Audio 输出引入了 latencyHint 配置选项,允许用户根据使用场景在 低延迟模式(interactive)与高效能模式(playback) 模式间切换。
低延迟模式(interactive)
技术特性: 申请极小的音频缓冲区(Small Buffer),维持高频率的 CPU 中断。
优点: 响应速度极快,适合对同步要求极高的场景。
缺点: CPU 负担较重,且在移动端(如 Android)通常会绕过系统级 DSP(如杜比全景声、内置音效),导致音质表现平平。
高效能模式(playback)
技术特性: 申请较大的音频缓冲区(Deep Buffer),降低 CPU 唤醒频率。
优点:允许操作系统启用硬件离线处理(Audio Offload)和系统级 DSP 音效(如小米音效、杜比全景声)。
节能降耗: 显著降低音频子系统的 CPU 占用,提升设备续航并减少发热。
缺点: 可能存在明显的硬件输出延迟(Hardware Output Latency)1,需要配合 UI 层的延迟补偿逻辑以确保歌词同步。
Footnotes
针对
playback模式带来的物理延迟,已在 currentTime 获取逻辑中集成了 baseLatency 和 outputLatency 补偿算法,确保在开启系统音效的情况下,歌曲输出、进度条与歌词进度仍保持高度同步。 ↩