mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-25 08:33:53 +08:00
Merge pull request #2514 from Harold-Guo/fix/web_audio
fix(web-audio): Fix AudioWorklet recording and AudioContext state issues
This commit is contained in:
@@ -1430,6 +1430,13 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
log('使用AudioWorklet处理音频', 'success');
|
log('使用AudioWorklet处理音频', 'success');
|
||||||
|
|
||||||
|
// 需要连接输出,否则不会触发处理
|
||||||
|
// 我们创建一个静音通道
|
||||||
|
const silent = audioContext.createGain();
|
||||||
|
silent.gain.value = 0;
|
||||||
|
audioProcessor.connect(silent);
|
||||||
|
silent.connect(audioContext.destination);
|
||||||
return { node: audioProcessor, type: 'worklet' };
|
return { node: audioProcessor, type: 'worklet' };
|
||||||
} else {
|
} else {
|
||||||
// 使用旧版ScriptProcessorNode作为回退方案
|
// 使用旧版ScriptProcessorNode作为回退方案
|
||||||
@@ -1604,6 +1611,11 @@
|
|||||||
// 创建音频上下文和分析器
|
// 创建音频上下文和分析器
|
||||||
audioContext = getAudioContextInstance();
|
audioContext = getAudioContextInstance();
|
||||||
|
|
||||||
|
// 浏览器出于安全和性能考虑,新创建的 AudioContext 默认处于 suspended 状态,必须显式调用 resume() 才会开始处理音频。
|
||||||
|
if (audioContext.state === 'suspended') {
|
||||||
|
await audioContext.resume();
|
||||||
|
}
|
||||||
|
|
||||||
// 创建音频处理器
|
// 创建音频处理器
|
||||||
const processorResult = await createAudioProcessor();
|
const processorResult = await createAudioProcessor();
|
||||||
if (!processorResult) {
|
if (!processorResult) {
|
||||||
|
|||||||
Reference in New Issue
Block a user