Serve Swedish Piper voices from frontend origin
Build and publish frontend / publish (push) Successful in 1m34s
Build and publish frontend / publish (push) Successful in 1m34s
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user