Spaces:
Sleeping
Sleeping
Fix mic start failing when pre-init recognition still active
Browse filesIf the permission pre-check recognition is still running when the user
taps mic, stop it first and retry. Also retry once on start() failure
since recognition may need a moment to fully stop.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1480 unmodified lines1481148214831484148514861 unmodified line14881489149014911492149314941480 unmodified linesif (vg.isListening) {vgStopListening();} else {// Pause audio while listeningif (vg.audio && vg.isPlaying) {vg.audio.pause();1 unmodified linetry {vg.recognition.start();} catch(e) {document.getElementById('vgStatus').textContent = 'Mikrofon konnte nicht gestartet werden';return;}vg.isListening = true;1480 unmodified lines148114821483148414851486148714881489149014911492149314941 unmodified line1496149714981499150015011502150315041505150615071508150915101511151215131480 unmodified linesif (vg.isListening) {vgStopListening();} else {// If pre-init is still running, stop it firstif (vg._permissionPending) {vg._permissionPending = false;try { vg.recognition.stop(); } catch(e) {}// Brief delay to let recognition fully stop before restartingsetTimeout(() => vgToggleMic(), 150);return;}// Pause audio while listeningif (vg.audio && vg.isPlaying) {vg.audio.pause();1 unmodified linetry {vg.recognition.start();} catch(e) {// Recognition may still be stopping — retry oncesetTimeout(() => {try {vg.recognition.start();vg.isListening = true;document.getElementById('vgBtnMic').classList.add('listening');document.getElementById('vgBtnMic').innerHTML = '■';document.getElementById('vgStatus').textContent = 'Höre zu... (Tap zum Stoppen)';} catch(e2) {document.getElementById('vgStatus').textContent = 'Mikrofon konnte nicht gestartet werden';}}, 200);return;}vg.isListening = true;
frontend/index.html+20-1