From 1f9fc464d4937f8f0a7b9d42c966da7337163b95 Mon Sep 17 00:00:00 2001 From: Ein Anderssono Date: Thu, 15 Oct 2026 09:56:42 +0200 Subject: [PATCH] Disclose browser speech processing before microphone use --- README.md | 2 +- index.html | 16 ++++++++++++++++ scripts/check-frontend.sh | 2 ++ voice.js | 3 ++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b5c7cb7..5bf021c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The separate `/admin` route provides an authenticated, read-only operations view The game is text- and dialogue-based and uses no images. Place descriptions include sound, smell, air/temperature, touch/surface, and spatial-orientation cues. Visible details may also be described in words, but are never required to understand the scene or play. The transcript is screen-reader announced, and Enter submits the input while Shift+Enter inserts a newline; no separate send button is required. -Voice input and output are optional browser features. The microphone button beside the text field uses Web Speech API when available and sends only its final Swedish transcript through the same submission path as typed text. Writing `röstinställningar` or saying `röstkommando alternativ` opens the temporary controls in the dialogue. The player can choose `Spelets röst`, `Skärmläsare`, or `Endast text`, select available Swedish speech voices and rate, and enable auto-read and short audio cues. The default mode is `Skärmläsare`; auto-read is off. These preferences are stored in browser `localStorage`. If speech APIs are unavailable or permission is denied, text play remains available. No audio is uploaded or stored by this feature. +Voice input and output are optional browser features. The microphone button beside the text field uses Web Speech API when available and sends only its final Swedish transcript through the same submission path as typed text. Before its first use, the client explains that the browser may process audio through a provider-selected service; the game itself does not receive or store recordings, while the final transcript is saved as ordinary dialogue. Writing `röstinställningar` or saying `röstkommando alternativ` opens the temporary controls in the dialogue. The player can choose `Spelets röst`, `Skärmläsare`, or `Endast text`, select available Swedish speech voices and rate, and enable auto-read and short audio cues. The default mode is `Skärmläsare`; auto-read is off. These preferences are stored in browser `localStorage`. If speech APIs are unavailable or permission is denied, text play remains available. System voice commands require the prefix `röstkommando`: `upprepa`, `avbryt`, `hjälp`, `alternativ`, or `paus`. Without the prefix, the same words remain ordinary dialogue. Speech recognition and synthesis are browser-dependent; release acceptance must record which real iPhone/Safari/VoiceOver and Android/Chrome/TalkBack combinations were actually checked. diff --git a/index.html b/index.html index c289b67..96240b0 100644 --- a/index.html +++ b/index.html @@ -88,6 +88,7 @@ let voiceSettings = window.GameVoice.loadSettings(localStorage, voiceSettingsKey); let voiceController; let audioContext; + let voiceDisclosureAcknowledged = false; let adminOffset = 0; const adminPageSize = 50; @@ -211,6 +212,20 @@ addVoiceButton(item, 'Stäng röstinställningar', () => item.remove()); transcript.append(item); item.scrollIntoView({block: 'end'}); mode.focus(); } + function requestVoiceDisclosure() { + const item = document.createElement('li'); item.dataset.role = 'voice-controls'; + item.setAttribute('aria-label', 'Information om mikrofonen'); + const message = document.createElement('p'); + message.textContent = 'Innan du startar: webbläsarens taligenkänning kan behandla ljud genom en tjänst som webbläsaren väljer. Spelet tar inte emot eller sparar ljudinspelningen. Den färdiga transkriberingen skickas och sparas som din vanliga dialog. Fortsätt bara om du godkänner webbläsarens hantering av tal.'; + item.append(message); + addVoiceButton(item, 'Jag förstår – starta mikrofonen', () => { + voiceDisclosureAcknowledged = true; + item.remove(); + voiceController.startListening(); + }); + transcript.append(item); item.scrollIntoView({block: 'end'}); + item.querySelector('button').focus(); + } function handleVoiceCommand(message, source) { const parsed = window.GameVoice.parseVoiceCommand(message, {requirePrefix: source === 'voice'}); if (!parsed) return false; @@ -226,6 +241,7 @@ } document.querySelector('#microphone').addEventListener('click', () => { if (voiceController.getState() === 'LISTENING') voiceController.stopListening(); + else if (!voiceDisclosureAcknowledged && voiceController.supportsRecognition()) requestVoiceDisclosure(); else voiceController.startListening(); }); document.addEventListener('visibilitychange', () => { if (document.hidden) voiceController.stopAll(); }); diff --git a/scripts/check-frontend.sh b/scripts/check-frontend.sh index e253ba8..70dcfb8 100755 --- a/scripts/check-frontend.sh +++ b/scripts/check-frontend.sh @@ -11,6 +11,8 @@ grep -q 'id="message" name="message"' index.html grep -q 'id="microphone" aria-pressed="false"' index.html grep -q 'id="voice-status" role="status" aria-live="polite"' index.html grep -q "window.GameVoice.createVoiceController" index.html +grep -q 'Jag förstår – starta mikrofonen' index.html +grep -q 'supportsRecognition' voice.js grep -q 'COPY voice.js /usr/share/nginx/html/voice.js' Dockerfile grep -q "SpeechRecognition || win.webkitSpeechRecognition" voice.js grep -q "submitMessage(text, 'voice')" index.html diff --git a/voice.js b/voice.js index d8fa653..a96e2da 100644 --- a/voice.js +++ b/voice.js @@ -201,7 +201,8 @@ function getState() { return state; } function getSettings() { return {...settings}; } function getVoices() { return availableVoices(); } - return {startListening, stopListening, speak, cancelSpeech, stopAll, update, getState, getSettings, getVoices}; + function supportsRecognition() { return Boolean(win.SpeechRecognition || win.webkitSpeechRecognition); } + return {startListening, stopListening, speak, cancelSpeech, stopAll, update, getState, getSettings, getVoices, supportsRecognition}; } root.GameVoice = {createVoiceController, DEFAULT_SETTINGS, parseVoiceCommand, loadSettings, saveSettings};