Serve Swedish Piper voices from frontend origin
Build and publish frontend / publish (push) Successful in 1m34s

This commit is contained in:
Ein Anderssono
2026-10-16 07:07:48 +02:00
parent bdc63a588e
commit 94078686b4
11 changed files with 152 additions and 5 deletions
+13
View File
@@ -1,7 +1,20 @@
import {TtsSession} from '@mintplex-labs/piper-tts-web';
import {localPiperModelUrl} from './piper-model-routing.mjs';
const VOICE_ID = 'sv_SE-nst-medium';
const ASSET_ROOT = '/tts/piper-wasm-v1';
const localFetch = self.fetch.bind(self);
// The pinned TTS library uses a fixed Hugging Face URL. Keep its OPFS cache logic,
// but serve every model/config request from this frontend origin instead.
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 inferenceQueue = Promise.resolve();