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 构建中因浏览器自动播放策略导致 Highlights
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. Footnotes
|
There was a problem hiding this comment.
Code Review
这个 PR 很好地解决了浏览器自动播放策略导致音频上下文(AudioContext)被挂起的问题。主要改动包括:
- 将
AudioContext的创建改为按需创建,而不是在脚本初始化时创建。 - 在播放语音前,通过新的
ensureAudioContextReady函数确保AudioContext处于 'running' 状态,如果失败则会跳过口型同步并记录警告,避免阻塞语音播放。 - 为
VocalControl.play()添加了 Promise 的catch处理,以优雅地处理播放被浏览器阻止的情况。 - 通过
finishPerform函数重构了演出结束的逻辑,提高了代码的复用性。 - 修复了
maxAudioLevel没有被重置的问题。
这些改动增强了应用的鲁棒性。我提出了一些关于类型安全的小建议,请查看具体的评论。
| audioContextWrapper.source.connect(audioContextWrapper.analyser); | ||
| } | ||
|
|
||
| performMouthAnimation({ | ||
| audioLevel, | ||
| OPEN_THRESHOLD, | ||
| HALF_OPEN_THRESHOLD, | ||
| currentMouthValue, | ||
| lerpSpeed, | ||
| key, | ||
| animationItem, | ||
| pos, | ||
| }); | ||
| }, 50); | ||
| audioContextWrapper.analyser.connect(audioContextWrapper.audioContext.destination); |
There was a problem hiding this comment.
audioContextWrapper.analyser 的类型是 AnalyserNode | undefined。虽然在前面的代码中已经对其进行了初始化,但 TypeScript 编译器可能无法在此处推断出其为非空。为了代码的健壮性和避免潜在的运行时错误,建议在调用 .connect 之前使用非空断言 !。
| audioContextWrapper.source.connect(audioContextWrapper.analyser); | |
| } | |
| performMouthAnimation({ | |
| audioLevel, | |
| OPEN_THRESHOLD, | |
| HALF_OPEN_THRESHOLD, | |
| currentMouthValue, | |
| lerpSpeed, | |
| key, | |
| animationItem, | |
| pos, | |
| }); | |
| }, 50); | |
| audioContextWrapper.analyser.connect(audioContextWrapper.audioContext.destination); | |
| audioContextWrapper.source.connect(audioContextWrapper.analyser!); | |
| } | |
| audioContextWrapper.analyser!.connect(audioContextWrapper.audioContext.destination); |
| dataArray: Uint8Array, | ||
| bufferLength: number, | ||
| ): number => { | ||
| analyser.getByteFrequencyData(dataArray as any); |
介绍
Warning
AI CODED PULL REQUEAST
修复 web 构建产物,会因为玩家的浏览器的自动播放设置被拦截,导致 audioContext.state 为 suspended,导致语音不播放和口型没有被驱动
更改
测试