From 1b9933dea7cf9573ff01356cf796c9bdd4c53963 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Sun, 26 Apr 2026 23:03:27 +0200 Subject: [PATCH] Fix voice button audio unlock hang --- static/app.js | 14 ++++++++++---- static/index.html | 2 +- static/sw.js | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/static/app.js b/static/app.js index b43f08e..0ef3d6e 100644 --- a/static/app.js +++ b/static/app.js @@ -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) { diff --git a/static/index.html b/static/index.html index df3e6d0..8a08def 100644 --- a/static/index.html +++ b/static/index.html @@ -50,6 +50,6 @@ - + diff --git a/static/sw.js b/static/sw.js index c1aa375..98263ee 100644 --- a/static/sw.js +++ b/static/sw.js @@ -1,8 +1,8 @@ -const CACHE_NAME = "opensquared-assistant-v3"; +const CACHE_NAME = "opensquared-assistant-v4"; const ASSETS = [ "/", "/styles.css", - "/app.js", + "/app.js?v=4", "/manifest.webmanifest", "/icons/icon-v2.svg" ];