mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
Fix AEC3 pitch drift by using the AudioContext's actual sample rate
The requested AudioContext sampleRate is only a hint - some backends (notably Linux/PulseAudio) silently run at their own native rate anyway. AEC3 was told the requested rate (48000) regardless, so its internal frame timing drifted from the actual sample rate its buffers came in at, audibly heard as the echo's pitch descending with each repeat instead of being cancelled. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
258d108f59
commit
effabafa23
1 file changed
+7
-1
+7
-1
@@ -7913,7 +7913,13 @@ function AppInner() {
|
||||
try {
|
||||
const audioContext = ensureAudioContext();
|
||||
if (audioContext.state === "suspended") await audioContext.resume();
|
||||
const aec3 = await createAec3(SAMPLE_RATE, 2, 1);
|
||||
// The context is *requested* at SAMPLE_RATE, but that constructor hint
|
||||
// isn't guaranteed - some audio backends (notably Linux/PulseAudio) run
|
||||
// it at their own native rate regardless. AEC3 must be told the rate
|
||||
// its ScriptProcessorNode buffers are actually sampled at, or its
|
||||
// internal frame timing drifts - audibly, as a progressively descending
|
||||
// pitch on repeated echo.
|
||||
const aec3 = await createAec3(audioContext.sampleRate, 2, 1);
|
||||
aec3Ref.current = aec3;
|
||||
audioPlayerRef.current?.attachAecRenderTap(aec3);
|
||||
setAec3Enabled(true);
|
||||
|
||||
Reference in new issue
Block a user