Compare commits

..
5 Commits
Author SHA1 Message Date
Gitea Actions b3a0e0ca5a Release 0.1.30 [auto-version-bump] 2026-10-15 10:25:53 +02:00
Ein Anderssono de915b4aa6 Migrate players to automatic voice replies
Build and publish frontend / publish (push) Successful in 38s
2026-10-15 10:25:35 +02:00
Gitea Actions 421b14c398 Release 0.1.29 [auto-version-bump] 2026-10-15 10:21:53 +02:00
Ein Anderssono 9efb602653 Keep screen reader voice mode test explicit
Build and publish frontend / publish (push) Successful in 38s
2026-10-15 10:21:29 +02:00
Ein Anderssono 222dcb9054 Enable automatic speech for game replies
Build and publish frontend / publish (push) Failing after 3s
2026-10-15 10:21:00 +02:00
6 changed files with 36 additions and 11 deletions
+1 -1
View File
@@ -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. 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. 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. Voice input and output are browser features. Every new game reply is read automatically with the browser's Swedish speech synthesis by default, including character creation and gameplay; the transcript remains available as text. 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 or disable auto-read and short audio cues. The default mode is `Spelets röst` with auto-read on. Screen-reader and text-only modes remain explicit alternatives. These preferences are stored in browser `localStorage`. If speech APIs are unavailable, text play remains available.
When a character or NPC is created, its saved voice identity is masculine, feminine, or neutral. The biography prompt only assigns masculine/feminine when the character is explicitly described that way; otherwise it uses neutral. Speech synthesis applies a stable, subtly varied pitch/rate profile per character, so a character keeps the same sound across visits. Narration always uses neutral pitch. The browser's selected Swedish voice still determines the underlying voice, so the exact sound depends on installed system voices. When a character or NPC is created, its saved voice identity is masculine, feminine, or neutral. The biography prompt only assigns masculine/feminine when the character is explicitly described that way; otherwise it uses neutral. Speech synthesis applies a stable, subtly varied pitch/rate profile per character, so a character keeps the same sound across visits. Narration always uses neutral pitch. The browser's selected Swedish voice still determines the underlying voice, so the exact sound depends on installed system voices.
+1 -1
View File
@@ -1 +1 @@
0.1.28 0.1.30
+2 -2
View File
@@ -2,5 +2,5 @@ apiVersion: v2
name: ai-spel-frontend name: ai-spel-frontend
description: Static web frontend for the Swedish life simulator description: Static web frontend for the Swedish life simulator
type: application type: application
version: 0.1.28 version: 0.1.30
appVersion: "0.1.28" appVersion: "0.1.30"
+2 -2
View File
@@ -85,8 +85,8 @@
let pendingDialogue = null; let pendingDialogue = null;
let latestAssistantText = ''; let latestAssistantText = '';
let latestAssistantVoice = {role: 'narrator', voiceIdentity: 'neutral'}; let latestAssistantVoice = {role: 'narrator', voiceIdentity: 'neutral'};
const voiceSettingsKey = 'ai-spel.voice-settings.v1'; const voiceSettingsKey = 'ai-spel.voice-settings.v2';
let voiceSettings = window.GameVoice.loadSettings(localStorage, voiceSettingsKey); let voiceSettings = window.GameVoice.loadSettings(localStorage, voiceSettingsKey, 'ai-spel.voice-settings.v1');
let voiceController; let voiceController;
let audioContext; let audioContext;
let voiceDisclosureAcknowledged = false; let voiceDisclosureAcknowledged = false;
+13 -1
View File
@@ -153,6 +153,7 @@ test('TTS and microphone are mutually exclusive', () => {
test('speech is disabled in screen-reader mode and gracefully degrades without synthesis', () => { test('speech is disabled in screen-reader mode and gracefully degrades without synthesis', () => {
const screenReader = makeHarness(); const screenReader = makeHarness();
screenReader.controller.update({mode: 'screen-reader'});
assert.equal(screenReader.controller.speak('dialog'), false); assert.equal(screenReader.controller.speak('dialog'), false);
const noTts = makeHarness({tts: false}); const noTts = makeHarness({tts: false});
noTts.controller.update({mode: 'game-voice'}); noTts.controller.update({mode: 'game-voice'});
@@ -176,6 +177,16 @@ test('settings survive reload and invalid storage falls back to accessible defau
vm.runInNewContext(source, {window: global, globalThis: global, Promise, String, Math, Object}); vm.runInNewContext(source, {window: global, globalThis: global, Promise, String, Math, Object});
const values = new Map(); const values = new Map();
const storage = {getItem: key => values.get(key) || null, setItem: (key, value) => values.set(key, value)}; const storage = {getItem: key => values.get(key) || null, setItem: (key, value) => values.set(key, value)};
const defaults = GameVoice.loadSettings(storage, 'new-player');
assert.equal(defaults.mode, 'game-voice');
assert.equal(defaults.autoSpeak, true);
values.set('voice-v1', JSON.stringify({mode: 'screen-reader', autoSpeak: false, rate: 1.4, voiceName: 'Svensk', soundSignals: false}));
const migrated = GameVoice.loadSettings(storage, 'voice-v2', 'voice-v1');
assert.equal(migrated.mode, 'game-voice');
assert.equal(migrated.autoSpeak, true);
assert.equal(migrated.rate, 1.4);
assert.equal(migrated.voiceName, 'Svensk');
assert.equal(migrated.soundSignals, false);
const requested = {...GameVoice.DEFAULT_SETTINGS, mode: 'game-voice', autoSpeak: true, rate: 1.5, voiceName: 'Svensk'}; const requested = {...GameVoice.DEFAULT_SETTINGS, mode: 'game-voice', autoSpeak: true, rate: 1.5, voiceName: 'Svensk'};
assert.equal(GameVoice.saveSettings(storage, 'voice', requested), true); assert.equal(GameVoice.saveSettings(storage, 'voice', requested), true);
const loaded = GameVoice.loadSettings(storage, 'voice'); const loaded = GameVoice.loadSettings(storage, 'voice');
@@ -184,6 +195,7 @@ test('settings survive reload and invalid storage falls back to accessible defau
assert.equal(loaded.rate, 1.5); assert.equal(loaded.rate, 1.5);
assert.equal(loaded.voiceName, 'Svensk'); assert.equal(loaded.voiceName, 'Svensk');
values.set('voice', '{trasig'); values.set('voice', '{trasig');
assert.equal(GameVoice.loadSettings(storage, 'voice').mode, 'screen-reader'); assert.equal(GameVoice.loadSettings(storage, 'voice').mode, 'game-voice');
assert.equal(GameVoice.loadSettings(storage, 'voice').autoSpeak, true);
assert.equal(GameVoice.saveSettings({setItem() { throw new Error('blocked'); }}, 'voice', requested), false); assert.equal(GameVoice.saveSettings({setItem() { throw new Error('blocked'); }}, 'voice', requested), false);
}); });
+17 -4
View File
@@ -1,8 +1,8 @@
/* Browser voice adapters. Kept independent of the game submission and API layer. */ /* Browser voice adapters. Kept independent of the game submission and API layer. */
(function exposeVoice(root) { (function exposeVoice(root) {
const DEFAULT_SETTINGS = Object.freeze({ const DEFAULT_SETTINGS = Object.freeze({
mode: 'screen-reader', mode: 'game-voice',
autoSpeak: false, autoSpeak: true,
language: 'sv-SE', language: 'sv-SE',
rate: 1, rate: 1,
voiceName: '', voiceName: '',
@@ -25,9 +25,22 @@
return {command: aliases[command] || 'unknown'}; return {command: aliases[command] || 'unknown'};
} }
function loadSettings(storage, key) { function loadSettings(storage, key, legacyKey) {
try { try {
const stored = JSON.parse(storage.getItem(key) || '{}'); const current = storage.getItem(key);
if (!current && legacyKey) {
const legacy = JSON.parse(storage.getItem(legacyKey) || '{}');
const migrated = {
...DEFAULT_SETTINGS,
rate: legacy.rate,
voiceName: legacy.voiceName,
speakerProfiles: legacy.speakerProfiles,
soundSignals: legacy.soundSignals,
};
saveSettings(storage, key, migrated);
return migrated;
}
const stored = JSON.parse(current || '{}');
const settings = {...DEFAULT_SETTINGS, ...stored}; const settings = {...DEFAULT_SETTINGS, ...stored};
if (!['screen-reader', 'game-voice', 'text-only'].includes(settings.mode)) settings.mode = DEFAULT_SETTINGS.mode; if (!['screen-reader', 'game-voice', 'text-only'].includes(settings.mode)) settings.mode = DEFAULT_SETTINGS.mode;
settings.rate = Math.min(2, Math.max(0.5, Number(settings.rate) || 1)); settings.rate = Math.min(2, Math.max(0.5, Number(settings.rate) || 1));