Fix voice button audio unlock hang
This commit is contained in:
@@ -59,12 +59,17 @@ function addBubble(text, role = "assistant") {
|
|||||||
|
|
||||||
async function unlockAudio() {
|
async function unlockAudio() {
|
||||||
if (audioUnlocked) return;
|
if (audioUnlocked) return;
|
||||||
const audio = new Audio();
|
|
||||||
audio.muted = true;
|
|
||||||
try {
|
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 {
|
} 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;
|
audioUnlocked = true;
|
||||||
}
|
}
|
||||||
@@ -97,6 +102,7 @@ async function sendText() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function toggleVoice() {
|
async function toggleVoice() {
|
||||||
|
setStatus("Activation du micro", "live");
|
||||||
await unlockAudio();
|
await unlockAudio();
|
||||||
|
|
||||||
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
||||||
|
|||||||
@@ -50,6 +50,6 @@
|
|||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<script src="/app.js" type="module"></script>
|
<script src="/app.js?v=4" type="module"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const CACHE_NAME = "opensquared-assistant-v3";
|
const CACHE_NAME = "opensquared-assistant-v4";
|
||||||
const ASSETS = [
|
const ASSETS = [
|
||||||
"/",
|
"/",
|
||||||
"/styles.css",
|
"/styles.css",
|
||||||
"/app.js",
|
"/app.js?v=4",
|
||||||
"/manifest.webmanifest",
|
"/manifest.webmanifest",
|
||||||
"/icons/icon-v2.svg"
|
"/icons/icon-v2.svg"
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user