Compare commits

...
7 Commits
Author SHA1 Message Date
Gitea Actions 5354132489 Release 0.1.31 [auto-version-bump] 2026-10-15 10:46:29 +02:00
Ein Anderssono 0005bb1c83 Support NPC-led conversation flow
Build and publish frontend / publish (push) Successful in 38s
2026-10-15 10:45:33 +02:00
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
7 changed files with 54 additions and 14 deletions
+3 -1
View File
@@ -6,11 +6,13 @@ After login, character creation and play use one dialogue history and one text i
During play the UI has no persistent location, task, inventory, economy, status, or purchase panels. The player asks for information or writes an action in the same input. Rust validates state changes; the AI can only propose a typed intent. A direct request to travel may establish a new place and an encounter when Rust commits that movement. During play the UI has no persistent location, task, inventory, economy, status, or purchase panels. The player asks for information or writes an action in the same input. Rust validates state changes; the AI can only propose a typed intent. A direct request to travel may establish a new place and an encounter when Rust commits that movement.
If the player asks to find or approach someone and no NPC is present, the direct dialogue scene may propose one person and an opening line. Rust creates that NPC only for the explicit request and commits the first exchange idempotently; a later turn continues the saved conversation. Clear requests about the current location are answered from its saved facts without asking the player to restate what they want to inspect.
The separate `/admin` route provides an authenticated, read-only operations view for player search/profile/trace, YAML prompt assets, generated Luau rules with validation results, and the append-only audit log. All privileged data comes from the Rust `/api/admin/...` API; the browser never connects directly to PostgreSQL. Backend endpoints require `accounts.is_admin=true`. The separate `/admin` route provides an authenticated, read-only operations view for player search/profile/trace, YAML prompt assets, generated Luau rules with validation results, and the append-only audit log. All privileged data comes from the Rust `/api/admin/...` API; the browser never connects directly to PostgreSQL. Backend endpoints require `accounts.is_admin=true`.
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.31
+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.31
appVersion: "0.1.28" appVersion: "0.1.31"
+16 -5
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;
@@ -115,6 +115,17 @@
} }
return line; return line;
} }
function explainDialogueError(error) {
const code = String(error?.message || '');
const known = {
dialogue_temporarily_unavailable: 'Berättartjänsten svarar inte just nu. Vänta en stund och försök igen.',
world_version_conflict: 'Världen hann ändras medan du skrev. Jag har uppdaterat läget; skicka meddelandet igen.',
world_not_available: 'Världen är inte tillgänglig just nu. Försök igen om en liten stund.',
};
return known[code] || (/^[a-z0-9_]+$/.test(code)
? 'Jag kunde inte behandla det just nu. Försök igen om en liten stund.'
: code || 'Ett tillfälligt fel uppstod. Försök igen om en liten stund.');
}
function setVoiceStatus(message = '') { document.querySelector('#voice-status').textContent = message; } function setVoiceStatus(message = '') { document.querySelector('#voice-status').textContent = message; }
function refreshMicrophone() { function refreshMicrophone() {
const button = document.querySelector('#microphone'); const button = document.querySelector('#microphone');
@@ -534,19 +545,19 @@
gameState.world.version = result.world_version; gameState.world.version = result.world_version;
gameState.world.world_time = result.world_time; gameState.world.world_time = result.world_time;
pendingDialogue = null; pendingDialogue = null;
if (result.intent === 'move') { if (result.intent === 'move' || result.intent === 'meet') {
try { try {
const refreshed = await request('/api/world'); const refreshed = await request('/api/world');
if (refreshed.world) gameState = refreshed; if (refreshed.world) gameState = refreshed;
} catch (_) { /* The committed dialogue stays successful if this optional view refresh fails. */ } } catch (_) { /* The committed dialogue stays successful if this optional view refresh fails. */ }
} }
const speakingNpc = result.intent === 'speak' ? gameState.world.npc : null; const speakingNpc = ['speak', 'meet'].includes(result.intent) ? gameState.world.npc : null;
appendLine('assistant', result.reply, speakingNpc appendLine('assistant', result.reply, speakingNpc
? {speaker: speakingNpc.name, voice: {characterId: speakingNpc.id, voiceIdentity: speakingNpc.voice_identity}} ? {speaker: speakingNpc.name, voice: {characterId: speakingNpc.id, voiceIdentity: speakingNpc.voice_identity}}
: {speaker: 'Berättelsen', voice: {role: 'narrator', voiceIdentity: 'neutral'}}); : {speaker: 'Berättelsen', voice: {role: 'narrator', voiceIdentity: 'neutral'}});
} catch (error) { } catch (error) {
messageField.value = message; messageField.value = message;
appendLine('assistant', `Meddelandet kunde inte behandlas: ${error.message}. Texten ligger kvar i inmatningen; skicka igen för att försöka på nytt.`); appendLine('assistant', `${explainDialogueError(error)} Ditt meddelande ligger kvar i inmatningen.`);
} }
messageField.disabled = false; messageField.disabled = false;
messageField.focus(); messageField.focus();
+2
View File
@@ -26,6 +26,8 @@ grep -q "event.key === 'Enter' && !event.shiftKey" index.html
grep -q "request('/api/character/draft'" index.html grep -q "request('/api/character/draft'" index.html
grep -q "request('/api/world/draft'" index.html grep -q "request('/api/world/draft'" index.html
grep -q "request('/api/dialogue'" index.html grep -q "request('/api/dialogue'" index.html
grep -q "result.intent === 'move' || result.intent === 'meet'" index.html
grep -q 'dialogue_temporarily_unavailable:' index.html
grep -q 'id="admin-view"' index.html grep -q 'id="admin-view"' index.html
grep -q '/api/admin/players?' index.html grep -q '/api/admin/players?' index.html
grep -q "request('/api/admin/prompts'" index.html grep -q "request('/api/admin/prompts'" index.html
+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));