Fix voice button audio unlock hang

This commit is contained in:
2026-04-26 23:03:27 +02:00
parent 68486557dc
commit 1b9933dea7
3 changed files with 13 additions and 7 deletions

View File

@@ -59,12 +59,17 @@ function addBubble(text, role = "assistant") {
async function unlockAudio() {
if (audioUnlocked) return;
const audio = new Audio();
audio.muted = true;
try {
await audio.play();
const AudioContext = window.AudioContext || window.webkitAudioContext;
if (AudioContext) {
const context = new AudioContext();
if (context.state === "suspended") {
await context.resume();
}
await context.close();
}
} catch {
// Mobile browsers only need the attempt to happen inside a tap handler.
// The click itself is enough to authorize later playback in most browsers.
}
audioUnlocked = true;
}
@@ -97,6 +102,7 @@ async function sendText() {
}
async function toggleVoice() {
setStatus("Activation du micro", "live");
await unlockAudio();
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {