fix: Kokoro.js falls back to WASM when the browser has WebGPU but no GPU adapter (#33233)

This commit is contained in:
G30 2026-10-27 13:21:48 -04:00 • committed by GitHub
parent 7a76e9fed6
commit bafe181330
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -133,9 +133,10 @@
const model_id = 'onnx-community/Kokoro-82M-v1.0-ONNX';
const { KokoroTTS } = await import('kokoro-js');
const adapter = await navigator?.gpu?.requestAdapter().catch(() => null);
TTSModel = await KokoroTTS.from_pretrained(model_id, {
dtype: TTSEngineConfig.dtype, // Options: "fp32", "fp16", "q8", "q4", "q4f16"
device: !!navigator?.gpu ? 'webgpu' : 'wasm', // Detect WebGPU
device: adapter ? 'webgpu' : 'wasm', // Detect WebGPU
progress_callback: (e) => {
TTSModelProgress = e;
console.log(e);

View file

@ -18,9 +18,10 @@ self.onmessage = async (event) => {
self.postMessage({ status: 'init:start' });
try {
const adapter = await navigator?.gpu?.requestAdapter().catch(() => null);
tts = await KokoroTTS.from_pretrained(model_id, {
dtype,
device: !!navigator?.gpu ? 'webgpu' : 'wasm' // Detect WebGPU
device: adapter ? 'webgpu' : 'wasm' // Detect WebGPU
});
isInitialized = true; // Mark as initialized after successful loading
self.postMessage({ status: 'init:complete' });