Spaces:
Sleeping
Sleeping
Add pause button, question modal, and answer audio management to Voice Guide
Browse files- Play/Pause button with voice commands (pause/stopp/play/fortsetzen)
- Questions now open in a modal overlay instead of replacing step content
- Answer TTS audio stored in vg.answerAudio for proper cleanup on modal close
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
557 unmodified lines55855956056156256395 unmodified lines6596606616626636649 unmodified lines674675676677678679189 unmodified lines869870871872873874128 unmodified lines1003100410051006100710081 unmodified line101010111012101310141015103 unmodified lines1119112011211122112311243 unmodified lines1128112911301131113211332 unmodified lines11361137113811391140114179 unmodified lines12211222122312241225122612271228122912301231123211 unmodified lines124412451246124712481249125012511252125312541255125612571258125913 unmodified lines1273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309557 unmodified linesfont-size: 0.8rem;cursor: pointer;}</style></head><body>95 unmodified lines<!-- Controls --><div class="vg-controls"><button class="vg-btn" id="vgBtnBack" onclick="vgBack()" disabled>Zurück</button><button class="vg-btn" id="vgBtnReplay" onclick="vgReplay()">Nochmal</button><button class="vg-btn vg-btn-mic" id="vgBtnMic" onclick="vgToggleMic()">🎤</button><button class="vg-btn primary" id="vgBtnNext" onclick="vgNext()">Weiter</button>9 unmodified lines</div></div></div></div></main>189 unmodified linesstepIdx: 0,phases: [],audio: null,isPlaying: false,prefetchedNext: null, // { text, sources, audio }recognition: null,128 unmodified lines}}function vgDisplayStep(text, sources, audioUrl) {let html = `<div class="vg-step-text">${text.replace(/</g, '<').replace(/>/g, '>')}</div>`;if (sources && sources.length > 0) {1 unmodified line}document.getElementById('vgStepCard').innerHTML = html;document.getElementById('vgStatus').textContent = '';// Play audioif (vg.audio) {103 unmodified linesif (vg.audio) {vg.audio.currentTime = 0;vg.audio.play().catch(() => {});}}3 unmodified linesURL.revokeObjectURL(vg.audio.src);vg.audio = null;}if (vg.recognition && vg.isListening) {vg.recognition.stop();vg.isListening = false;2 unmodified linesURL.revokeObjectURL(vg.prefetchedNext.audio);}vg.prefetchedNext = null;document.getElementById('vgActive').style.display = 'none';document.getElementById('vgModeSelect').style.display = 'flex';79 unmodified lines// Intent classificationconst continueWords = ['weiter', 'ja', 'ok', 'okay', 'nächster', 'nächste', 'fertig', 'next', 'yes'];const backWords = ['nochmal', 'zurück', 'wiederhole', 'wiederholen', 'nochmals', 'repeat', 'back'];const words = text.split(/\s+/);const isContinue = continueWords.some(w => words.includes(w));const isBack = backWords.some(w => words.includes(w));if (isContinue) {vgNext();} else if (isBack) {vgReplay();11 unmodified linesawait vgAskQuestionText(question);}async function vgAskQuestionText(question) {// Pause current audioif (vg.audio && vg.isPlaying) {vg.audio.pause();}const card = document.getElementById('vgStepCard');const savedContent = card.innerHTML;card.innerHTML = `<div class="vg-step-text" style="color: var(--primary)">Frage: ${question.replace(/</g, '<')}</div><div class="loading"><span></span><span></span><span></span></div>`;document.getElementById('vgStatus').textContent = 'Beantworte Frage...';try {13 unmodified linesconst audioBlob = await audioResp.blob();const audioUrl = URL.createObjectURL(audioBlob);card.innerHTML = `<div class="vg-step-text" style="color: var(--primary); font-size: 0.85rem; margin-bottom: 0.5rem;">Frage: ${question.replace(/</g, '<')}</div><div class="vg-step-text">${data.answer.replace(/</g, '<').replace(/>/g, '>')}</div><div class="sources">Quellen: ${data.sources.join(', ')}</div><div style="margin-top: 0.75rem; text-align: center;"><button class="vg-btn" onclick="vgResumeWalkthrough()">Zurück zum Walkthrough</button></div>`;// Play answer audioconst answerAudio = new Audio(audioUrl);answerAudio.play().catch(() => {});document.getElementById('vgStatus').textContent = '';// Save walkthrough content to restorevg._savedStepContent = savedContent;} catch (err) {card.innerHTML = `<p style="color: var(--primary)">Fehler: ${err.message}</p><div style="margin-top: 0.75rem; text-align: center;"><button class="vg-btn" onclick="vgResumeWalkthrough()">Zurück zum Walkthrough</button></div>`;vg._savedStepContent = savedContent;document.getElementById('vgStatus').textContent = '';}}function vgResumeWalkthrough() {if (vg._savedStepContent) {document.getElementById('vgStepCard').innerHTML = vg._savedStepContent;vg._savedStepContent = null;}document.getElementById('vgStatus').textContent = 'Sage "Weiter" oder drücke den Button';}</script></body></html>557 unmodified lines55855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361495 unmodified lines7107117127137147157169 unmodified lines726727728729730731732733734735736737738739740741742743189 unmodified lines933934935936937938939128 unmodified lines106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901 unmodified line1092109310941095109610971098103 unmodified lines12021203120412051206120712083 unmodified lines12121213121412151216121712182 unmodified lines1221122212231224122512261227122879 unmodified lines1308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133311 unmodified lines13451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013 unmodified lines139413951396139713981399140014011402140314041405140614071408140914101411141214131414557 unmodified linesfont-size: 0.8rem;cursor: pointer;}/* Voice Guide Question Modal */.vg-modal {position: fixed;inset: 0;background: rgba(0, 0, 0, 0.7);display: flex;align-items: center;justify-content: center;z-index: 90;padding: 1rem;}.vg-modal.hidden { display: none; }.vg-modal-content {background: var(--surface);border: 1px solid var(--border);border-radius: 16px;padding: 1.25rem;max-width: 600px;width: 100%;max-height: 80vh;overflow-y: auto;line-height: 1.6;font-size: 0.95rem;}.vg-modal-content .vg-modal-question {color: var(--primary);font-size: 0.85rem;margin-bottom: 0.75rem;font-weight: 600;}.vg-modal-content .vg-modal-answer {white-space: pre-wrap;}.vg-modal-content .sources {margin-top: 0.75rem;padding-top: 0.5rem;border-top: 1px solid var(--border);font-size: 0.8rem;color: var(--text-muted);}.vg-modal-content .vg-modal-actions {margin-top: 1rem;text-align: center;}</style></head><body>95 unmodified lines<!-- Controls --><div class="vg-controls"><button class="vg-btn" id="vgBtnBack" onclick="vgBack()" disabled>Zurück</button><button class="vg-btn" id="vgBtnPause" onclick="vgTogglePause()">Pause</button><button class="vg-btn" id="vgBtnReplay" onclick="vgReplay()">Nochmal</button><button class="vg-btn vg-btn-mic" id="vgBtnMic" onclick="vgToggleMic()">🎤</button><button class="vg-btn primary" id="vgBtnNext" onclick="vgNext()">Weiter</button>9 unmodified lines</div></div></div><!-- Question Modal --><div id="vgQuestionModal" class="vg-modal hidden"><div class="vg-modal-content"><div id="vgModalBody"><div class="loading"><span></span><span></span><span></span></div></div><div class="vg-modal-actions"><button class="vg-btn" onclick="vgCloseModal()">Zurück zum Walkthrough</button></div></div></div></div></main>189 unmodified linesstepIdx: 0,phases: [],audio: null,answerAudio: null,isPlaying: false,prefetchedNext: null, // { text, sources, audio }recognition: null,128 unmodified lines}}function vgResetPauseButton() {const btn = document.getElementById('vgBtnPause');btn.textContent = 'Pause';}function vgTogglePause() {if (!vg.audio) return;const btn = document.getElementById('vgBtnPause');if (vg.audio.paused) {vg.audio.play().catch(() => {});btn.textContent = 'Pause';} else {vg.audio.pause();btn.textContent = 'Weiter \u25B6';}}function vgDisplayStep(text, sources, audioUrl) {let html = `<div class="vg-step-text">${text.replace(/</g, '<').replace(/>/g, '>')}</div>`;if (sources && sources.length > 0) {1 unmodified line}document.getElementById('vgStepCard').innerHTML = html;document.getElementById('vgStatus').textContent = '';vgResetPauseButton();// Play audioif (vg.audio) {103 unmodified linesif (vg.audio) {vg.audio.currentTime = 0;vg.audio.play().catch(() => {});vgResetPauseButton();}}3 unmodified linesURL.revokeObjectURL(vg.audio.src);vg.audio = null;}vgStopAnswerAudio();if (vg.recognition && vg.isListening) {vg.recognition.stop();vg.isListening = false;2 unmodified linesURL.revokeObjectURL(vg.prefetchedNext.audio);}vg.prefetchedNext = null;vgResetPauseButton();vgCloseModal();document.getElementById('vgActive').style.display = 'none';document.getElementById('vgModeSelect').style.display = 'flex';79 unmodified lines// Intent classificationconst continueWords = ['weiter', 'ja', 'ok', 'okay', 'nächster', 'nächste', 'fertig', 'next', 'yes'];const backWords = ['nochmal', 'zurück', 'wiederhole', 'wiederholen', 'nochmals', 'repeat', 'back'];const pauseWords = ['pause', 'stopp', 'stop', 'halt', 'anhalten'];const playWords = ['weiter abspielen', 'play', 'fortsetzen', 'abspielen'];const words = text.split(/\s+/);const isContinue = continueWords.some(w => words.includes(w));const isBack = backWords.some(w => words.includes(w));const isPause = pauseWords.some(w => words.includes(w));const isPlay = playWords.some(w => text.includes(w));if (isPlay) {if (vg.audio && vg.audio.paused) {vg.audio.play().catch(() => {});vgResetPauseButton();}} else if (isPause) {if (vg.audio && !vg.audio.paused) {vg.audio.pause();document.getElementById('vgBtnPause').textContent = 'Weiter \u25B6';}} else if (isContinue) {vgNext();} else if (isBack) {vgReplay();11 unmodified linesawait vgAskQuestionText(question);}function vgStopAnswerAudio() {if (vg.answerAudio) {vg.answerAudio.pause();URL.revokeObjectURL(vg.answerAudio.src);vg.answerAudio = null;}}function vgOpenModal() {document.getElementById('vgQuestionModal').classList.remove('hidden');}function vgCloseModal() {document.getElementById('vgQuestionModal').classList.add('hidden');vgStopAnswerAudio();document.getElementById('vgStatus').textContent = 'Sage "Weiter" oder drücke den Button';}async function vgAskQuestionText(question) {// Pause current walkthrough audioif (vg.audio && !vg.audio.paused) {vg.audio.pause();document.getElementById('vgBtnPause').textContent = 'Weiter \u25B6';}// Open modal with loading stateconst modalBody = document.getElementById('vgModalBody');modalBody.innerHTML = `<div class="vg-modal-question">Frage: ${question.replace(/</g, '<')}</div><div class="loading"><span></span><span></span><span></span></div>`;vgOpenModal();document.getElementById('vgStatus').textContent = 'Beantworte Frage...';try {13 unmodified linesconst audioBlob = await audioResp.blob();const audioUrl = URL.createObjectURL(audioBlob);modalBody.innerHTML = `<div class="vg-modal-question">Frage: ${question.replace(/</g, '<')}</div><div class="vg-modal-answer">${data.answer.replace(/</g, '<').replace(/>/g, '>')}</div><div class="sources">Quellen: ${data.sources.join(', ')}</div>`;// Play answer audio (stored in vg state for cleanup)vgStopAnswerAudio();vg.answerAudio = new Audio(audioUrl);vg.answerAudio.play().catch(() => {});document.getElementById('vgStatus').textContent = '';} catch (err) {modalBody.innerHTML = `<div class="vg-modal-question">Frage: ${question.replace(/</g, '<')}</div><p style="color: var(--primary)">Fehler: ${err.message}</p>`;document.getElementById('vgStatus').textContent = '';}}</script></body></html>
frontend/index.html+136-31