Compare commits

...
9 Commits
Author SHA1 Message Date
Gitea Actions 34adad88b8 Release 0.1.50 [auto-version-bump] 2026-10-16 07:33:02 +02:00
Ein Anderssono ed0a8b90a6 Serve Piper speech assets from dedicated static service
Build and publish frontend / publish (push) Successful in 49s
2026-10-16 07:32:34 +02:00
Gitea Actions 1458fa8382 Release 0.1.49 [auto-version-bump] 2026-10-16 07:16:18 +02:00
Ein Anderssono 145c025f05 Update Piper asset MIME source check
Build and publish frontend / publish (push) Successful in 1m32s
2026-10-16 07:15:30 +02:00
Ein Anderssono c618d2e31e Fix Piper ONNX runtime asset URLs
Build and publish frontend / publish (push) Failing after 2s
2026-10-16 07:15:12 +02:00
Gitea Actions 696a47a9a2 Release 0.1.48 [auto-version-bump] 2026-10-16 07:11:26 +02:00
Ein Anderssono 95d308b326 Serve Piper voice credits as readable text
Build and publish frontend / publish (push) Successful in 1m10s
2026-10-16 07:10:55 +02:00
Gitea Actions 971c457c13 Release 0.1.47 [auto-version-bump] 2026-10-16 07:08:39 +02:00
Ein Anderssono 94078686b4 Serve Swedish Piper voices from frontend origin
Build and publish frontend / publish (push) Successful in 1m34s
2026-10-16 07:07:48 +02:00
14 changed files with 110 additions and 37 deletions
+1 -3
View File
@@ -29,14 +29,12 @@ jobs:
python3 scripts/bump-version.py --check python3 scripts/bump-version.py --check
scripts/check-frontend.sh scripts/check-frontend.sh
- name: Build Piper WebAssembly assets - name: Bundle Piper worker client code
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
npm install --no-audit --no-fund npm install --no-audit --no-fund
npm run build:piper npm run build:piper
test -s public/tts/piper-wasm-v1/piper/piper_phonemize.wasm
test -s public/tts/piper-wasm-v1/piper/piper_phonemize.data
test -s public/tts/piper-wasm-v1/piper-worker.js test -s public/tts/piper-wasm-v1/piper-worker.js
test -s public/piper-runtime.js test -s public/piper-runtime.js
+2 -2
View File
@@ -7,5 +7,5 @@
- Changes are written locally and built, checked, published, and exercised by Gitea Actions on the existing `large` runner and Kubernetes. Never run apps, tests, containers, images, or binaries locally. Do not create or register runners. - Changes are written locally and built, checked, published, and exercised by Gitea Actions on the existing `large` runner and Kubernetes. Never run apps, tests, containers, images, or binaries locally. Do not create or register runners.
- Never commit secrets, generated credentials, kubeconfigs, or environment files. - Never commit secrets, generated credentials, kubeconfigs, or environment files.
- Helm charts are published to `harbor.k3s.k0.nu/ai-spel`; Argo CD uses the existing `ai-spel` project and namespace. - Helm charts are published to `harbor.k3s.k0.nu/ai-spel`; Argo CD uses the existing `ai-spel` project and namespace.
- Player-facing speech uses the local Piper WebAssembly adapter when the player has activated audio. The voice model is downloaded once from the configured model repository and cached by the browser; game text is synthesized on-device and must never be sent to a TTS provider. - Player-facing speech uses the local Piper WebAssembly adapter when the player has activated audio. The separate `ai-spel-static` Nginx service serves pinned Swedish Piper models and ONNX/Piper runtime files from same-origin `/static/piper-wasm-v1/` URLs with immutable caching. Game text is synthesized on-device and must never be sent to a TTS provider.
- Build Piper/ONNX WebAssembly files in the `large` runner and serve them from the frontend image under the versioned `/tts/piper-wasm-v1/` path. Never build or run these assets locally. - This pipeline bundles only the Piper worker/client glue. Model/runtime downloads, image builds, and deployment belong to `ai-spel/ai-spel-static` and the existing `large` runner. Never build or run these assets locally.
+1 -1
View File
@@ -14,7 +14,7 @@ The game is text- and dialogue-based and uses no images. Place descriptions incl
Player-facing speech uses Piper TTS in WebAssembly in the browser after audio is activated by a user gesture. It reads game dialogue, onboarding, account responses, character and world creation, gameplay replies, in-game errors, and microphone disclosures; the `/admin` route is excluded. The audio is decoded and played through the Web Audio API, independently of `speechSynthesis`. The first unauthenticated visit keeps the introduction visible and it can be started with `Läs introduktionen`. New game replies are read automatically and the transcript remains available to screen readers and as text. Returning players hear the latest saved game reply when they reopen the game. The player can change speaking rate; narrator pitch is neutral and character pitch is varied consistently by voice identity. These preferences are stored in browser `localStorage`. If WebAssembly, model loading, or audio playback fails, the same content remains available as text and the dialogue offers a retry. Player-facing speech uses Piper TTS in WebAssembly in the browser after audio is activated by a user gesture. It reads game dialogue, onboarding, account responses, character and world creation, gameplay replies, in-game errors, and microphone disclosures; the `/admin` route is excluded. The audio is decoded and played through the Web Audio API, independently of `speechSynthesis`. The first unauthenticated visit keeps the introduction visible and it can be started with `Läs introduktionen`. New game replies are read automatically and the transcript remains available to screen readers and as text. Returning players hear the latest saved game reply when they reopen the game. The player can change speaking rate; narrator pitch is neutral and character pitch is varied consistently by voice identity. These preferences are stored in browser `localStorage`. If WebAssembly, model loading, or audio playback fails, the same content remains available as text and the dialogue offers a retry.
The Piper engine and WebAssembly runtime are served by the frontend from a versioned same-origin path. The Swedish voice model (about 63 MB) downloads on first use from Hugging Face and is cached in browser storage when supported. Only the model files are fetched from that service; dialogue text is synthesized on the device and is not sent to a TTS provider. The frontend CI builds and packages the runtime; there is no Piper server or Kubernetes TTS service. The Piper engine, ONNX WebAssembly runtime, and all three Swedish medium voice models (Alma, Lisa, and NST) are served by the separate `ai-spel-static` Nginx service from same-origin `/static/piper-wasm-v1/`. Its own Gitea pipeline downloads pinned models, verifies sizes and hashes, and publishes a versioned image and Helm chart independently from frontend changes. The frontend's Piper adapter redirects the library's built-in model URLs to this static service; it does not request voice files from Hugging Face. Voice models are fetched on first use and cached in browser storage when supported. Dialogue text is synthesized on the device and is not sent to a TTS provider. Attribution is available at `/static/piper-wasm-v1/voices/ATTRIBUTION.txt`.
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 temporary voice controls in the dialogue. The player can adjust speaking rate and enable or disable short audio cues. Voice preferences are stored in browser `localStorage`. 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 temporary voice controls in the dialogue. The player can adjust speaking rate and enable or disable short audio cues. Voice preferences are stored in browser `localStorage`.
+1 -1
View File
@@ -1 +1 @@
0.1.46 0.1.50
+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.46 version: 0.1.50
appVersion: "0.1.46" appVersion: "0.1.50"
+4
View File
@@ -259,6 +259,10 @@
voice.value = piperVoice.value; voice.value = piperVoice.value;
voiceSettings.voiceName = piperVoice.value; voiceSettings.voiceName = piperVoice.value;
voiceLabel.append(voice); fieldset.append(voiceLabel); voiceLabel.append(voice); fieldset.append(voiceLabel);
const modelCredits = document.createElement('a');
modelCredits.href = '/static/piper-wasm-v1/voices/ATTRIBUTION.txt';
modelCredits.textContent = 'Svenska rösters upphov och licenser';
fieldset.append(modelCredits);
const signalLabel = document.createElement('label'); const signals = document.createElement('input'); const signalLabel = document.createElement('label'); const signals = document.createElement('input');
signals.type = 'checkbox'; signals.checked = voiceSettings.soundSignals; signals.type = 'checkbox'; signals.checked = voiceSettings.soundSignals;
signalLabel.append(signals, document.createTextNode(' Ljudsignal vid röstinmatning')); fieldset.append(signalLabel); signalLabel.append(signals, document.createTextNode(' Ljudsignal vid röstinmatning')); fieldset.append(signalLabel);
+4 -1
View File
@@ -12,7 +12,10 @@ server {
location ^~ /tts/piper-wasm-v1/ { location ^~ /tts/piper-wasm-v1/ {
types { types {
application/wasm wasm; application/wasm wasm;
application/javascript js; application/javascript js mjs;
application/json json;
application/octet-stream onnx;
text/plain txt;
} }
add_header Cache-Control "public, max-age=31536000, immutable" always; add_header Cache-Control "public, max-age=31536000, immutable" always;
add_header Cross-Origin-Opener-Policy "same-origin" always; add_header Cross-Origin-Opener-Policy "same-origin" always;
+9
View File
@@ -0,0 +1,9 @@
const PIPER_MODEL_ORIGIN = 'https://huggingface.co/diffusionstudio/piper-voices/resolve/main/';
const localPathPrefix = '/static/piper-wasm-v1/voices/';
export function localPiperModelUrl(requestedUrl, origin) {
if (!requestedUrl.startsWith(PIPER_MODEL_ORIGIN)) return null;
const relativePath = requestedUrl.slice(PIPER_MODEL_ORIGIN.length);
if (!/^[\w./-]+$/.test(relativePath) || relativePath.split('/').includes('..')) return null;
return new URL(`${localPathPrefix}${relativePath}`, origin).href;
}
+7
View File
@@ -0,0 +1,7 @@
const assetRoot = '/static/piper-wasm-v1/onnx/';
export function createOnnxWasmPaths(origin) {
const absoluteAssetRoot = new URL(assetRoot, origin).href;
return absoluteAssetRoot;
}
+16 -2
View File
@@ -1,7 +1,21 @@
import {TtsSession} from '@mintplex-labs/piper-tts-web'; import {TtsSession} from '@mintplex-labs/piper-tts-web';
import {localPiperModelUrl} from './piper-model-routing.mjs';
import {createOnnxWasmPaths} from './piper-onnx-config.mjs';
const VOICE_ID = 'sv_SE-nst-medium'; const VOICE_ID = 'sv_SE-nst-medium';
const ASSET_ROOT = '/tts/piper-wasm-v1'; const ASSET_ROOT = '/static/piper-wasm-v1';
const localFetch = self.fetch.bind(self);
// Keep the TTS library's OPFS cache logic, but serve models/config from the
// same-origin static asset service instead of its built-in external model URL.
self.fetch = (resource, options) => {
const requestedUrl = resource instanceof Request ? resource.url : String(resource);
const localModelUrl = localPiperModelUrl(requestedUrl, self.location.origin);
if (!localModelUrl) return localFetch(resource, options);
const redirected = resource instanceof Request ? new Request(localModelUrl, resource) : localModelUrl;
return localFetch(redirected, options);
};
let sessionPromise; let sessionPromise;
let inferenceQueue = Promise.resolve(); let inferenceQueue = Promise.resolve();
@@ -11,7 +25,7 @@ async function getSession(onProgress) {
voiceId: VOICE_ID, voiceId: VOICE_ID,
progress: onProgress, progress: onProgress,
wasmPaths: { wasmPaths: {
onnxWasm: `${ASSET_ROOT}/onnx/`, onnxWasm: createOnnxWasmPaths(self.location.origin),
piperData: `${ASSET_ROOT}/piper/piper_phonemize.data`, piperData: `${ASSET_ROOT}/piper/piper_phonemize.data`,
piperWasm: `${ASSET_ROOT}/piper/piper_phonemize.wasm`, piperWasm: `${ASSET_ROOT}/piper/piper_phonemize.wasm`,
}, },
+16 -23
View File
@@ -1,30 +1,13 @@
import {build} from 'esbuild'; import {build} from 'esbuild';
import {cp, mkdir, readdir, rm, stat} from 'node:fs/promises'; import {mkdir, rm, readFile} from 'node:fs/promises';
import {join, resolve} from 'node:path'; import {join, resolve} from 'node:path';
const root = process.cwd(); const root = process.cwd();
const publicRoot = join(root, 'public'); const publicRoot = join(root, 'public');
const assetRoot = join(publicRoot, 'tts', 'piper-wasm-v1'); const workerRoot = join(publicRoot, 'tts', 'piper-wasm-v1');
const onnxSource = join(root, 'node_modules', 'onnxruntime-web', 'dist');
const piperSource = join(root, 'node_modules', '@diffusionstudio', 'piper-wasm', 'build');
const piperWasm = join(piperSource, 'piper_phonemize.wasm');
const piperData = join(piperSource, 'piper_phonemize.data');
await rm(assetRoot, {recursive: true, force: true}); await rm(workerRoot, {recursive: true, force: true});
await mkdir(join(assetRoot, 'onnx'), {recursive: true}); await mkdir(workerRoot, {recursive: true});
await mkdir(join(assetRoot, 'piper'), {recursive: true});
const wasmFiles = (await readdir(onnxSource))
.filter(name => name.endsWith('.wasm'));
if (wasmFiles.length === 0) throw new Error('ONNX Runtime WebAssembly files are missing');
for (const file of wasmFiles) {
await cp(join(onnxSource, file), join(assetRoot, 'onnx', file));
}
for (const file of [piperWasm, piperData]) {
const fileStat = await stat(file).catch(() => null);
if (!fileStat?.isFile() || fileStat.size === 0) throw new Error(`Missing Piper WebAssembly asset: ${file}`);
await cp(file, join(assetRoot, 'piper', file.split('/').at(-1)));
}
await build({ await build({
entryPoints: [resolve(root, 'piper-runtime.js')], entryPoints: [resolve(root, 'piper-runtime.js')],
@@ -40,7 +23,7 @@ await build({
await build({ await build({
entryPoints: [resolve(root, 'piper-worker.js')], entryPoints: [resolve(root, 'piper-worker.js')],
outfile: join(assetRoot, 'piper-worker.js'), outfile: join(workerRoot, 'piper-worker.js'),
bundle: true, bundle: true,
format: 'iife', format: 'iife',
platform: 'browser', platform: 'browser',
@@ -50,4 +33,14 @@ await build({
legalComments: 'none', legalComments: 'none',
}); });
console.log(`Piper browser assets prepared at ${assetRoot}`); const workerBundle = await readFile(join(workerRoot, 'piper-worker.js'), 'utf8');
for (const route of [
'https://huggingface.co/diffusionstudio/piper-voices/resolve/main/',
'/static/piper-wasm-v1',
'/static/piper-wasm-v1/voices/',
'/static/piper-wasm-v1/onnx/',
]) {
if (!workerBundle.includes(route)) throw new Error(`The Piper worker is missing static route ${route}`);
}
console.log(`Piper worker bundle prepared at ${workerRoot}`);
+9 -2
View File
@@ -10,7 +10,7 @@ grep -q 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0' nginx
grep -q 'Cross-Origin-Embedder-Policy "require-corp"' nginx/default.conf grep -q 'Cross-Origin-Embedder-Policy "require-corp"' nginx/default.conf
grep -q 'add_header Cross-Origin-Embedder-Policy "require-corp" always;' nginx/default.conf grep -q 'add_header Cross-Origin-Embedder-Policy "require-corp" always;' nginx/default.conf
grep -q 'add_header Cross-Origin-Resource-Policy "same-origin" always;' nginx/default.conf grep -q 'add_header Cross-Origin-Resource-Policy "same-origin" always;' nginx/default.conf
grep -q 'application/javascript js;' nginx/default.conf grep -q 'application/javascript js mjs;' nginx/default.conf
grep -q "request('/version')" index.html grep -q "request('/version')" index.html
grep -Fq "credentials: 'same-origin'" index.html grep -Fq "credentials: 'same-origin'" index.html
grep -q 'id="dialogue" aria-label="Dialoghistorik" role="log" aria-live="polite"' index.html grep -q 'id="dialogue" aria-label="Dialoghistorik" role="log" aria-live="polite"' index.html
@@ -46,6 +46,13 @@ grep -q 'sv_SE-nst-medium' piper-worker.js
grep -q 'new Worker(workerUrl)' piper-runtime.js grep -q 'new Worker(workerUrl)' piper-runtime.js
grep -q 'worker.js?v=' piper-runtime.js grep -q 'worker.js?v=' piper-runtime.js
grep -q 'worker.onmessageerror' piper-runtime.js grep -q 'worker.onmessageerror' piper-runtime.js
grep -q 'localPiperModelUrl' piper-worker.js
grep -q 'createOnnxWasmPaths(self.location.origin)' piper-worker.js
grep -q '/static/piper-wasm-v1/onnx/' piper-onnx-config.mjs
grep -q 'PIPER_MODEL_ORIGIN' piper-model-routing.mjs
grep -q '/static/piper-wasm-v1/voices/' piper-model-routing.mjs
grep -q 'ai-spel-static' README.md
grep -q 'ATTRIBUTION.txt' index.html
grep -q "SpeechRecognition || win.webkitSpeechRecognition" voice.js grep -q "SpeechRecognition || win.webkitSpeechRecognition" voice.js
grep -q "submitMessage(text, 'voice')" index.html grep -q "submitMessage(text, 'voice')" index.html
grep -q 'Spelets repliker läses alltid upp' index.html grep -q 'Spelets repliker läses alltid upp' index.html
@@ -80,6 +87,6 @@ if sed -n '/<section id="play"/,/^ <\/section>/p' index.html | grep '<button'
exit 1 exit 1
fi fi
node --test tests/voice.test.cjs node --test tests/*.test.cjs
echo 'Frontend source checks passed.' echo 'Frontend source checks passed.'
+23
View File
@@ -0,0 +1,23 @@
const test = require('node:test');
const assert = require('node:assert/strict');
test('Piper model and config requests use the same-origin voice mirror', async () => {
const {localPiperModelUrl} = await import('../piper-model-routing.mjs');
const origin = 'https://ai-spel.k3s.k0.nu';
assert.equal(
localPiperModelUrl('https://huggingface.co/diffusionstudio/piper-voices/resolve/main/sv/sv_SE/nst/medium/sv_SE-nst-medium.onnx', origin),
'https://ai-spel.k3s.k0.nu/static/piper-wasm-v1/voices/sv/sv_SE/nst/medium/sv_SE-nst-medium.onnx',
);
assert.equal(
localPiperModelUrl('https://huggingface.co/diffusionstudio/piper-voices/resolve/main/sv/sv_SE/lisa/medium/sv_SE-lisa-medium.onnx.json', origin),
'https://ai-spel.k3s.k0.nu/static/piper-wasm-v1/voices/sv/sv_SE/lisa/medium/sv_SE-lisa-medium.onnx.json',
);
});
test('Piper model routing leaves unrelated URLs alone and rejects traversal paths', async () => {
const {localPiperModelUrl} = await import('../piper-model-routing.mjs');
const origin = 'https://ai-spel.k3s.k0.nu';
assert.equal(localPiperModelUrl('https://example.com/model.onnx', origin), null);
assert.equal(localPiperModelUrl('https://huggingface.co.evil.test/diffusionstudio/piper-voices/resolve/main/model.onnx', origin), null);
assert.equal(localPiperModelUrl('https://huggingface.co/diffusionstudio/piper-voices/resolve/main/../secret', origin), null);
});
+15
View File
@@ -0,0 +1,15 @@
const test = require('node:test');
const assert = require('node:assert/strict');
test('ONNX Runtime receives an absolute same-origin base URL', async () => {
const {createOnnxWasmPaths} = await import('../piper-onnx-config.mjs');
const wasmPaths = createOnnxWasmPaths('https://ai-spel.k3s.k0.nu');
assert.equal(wasmPaths, 'https://ai-spel.k3s.k0.nu/static/piper-wasm-v1/onnx/');
assert.equal(new URL('ort-wasm-simd-threaded.mjs', wasmPaths).href,
'https://ai-spel.k3s.k0.nu/static/piper-wasm-v1/onnx/ort-wasm-simd-threaded.mjs');
});
test('ONNX Runtime base URL rejects an invalid worker origin', async () => {
const {createOnnxWasmPaths} = await import('../piper-onnx-config.mjs');
assert.throws(() => createOnnxWasmPaths('undefined'), TypeError);
});