Update Kokoro.js: WebGPU support, v1.0 integration (#60)
* Set up JS project * Finalise JS library * Update README * Fix package.json repository url * Rename package -> `kokoro-js` * Fix samples in README * Cleanup README * Bump `phonemizer` version * Create web demo * Run prettier * Link to model used in demo * Enable multithreading in HF space demo (~40% faster) * Add link to demo in README * Bump to v1.0.1 * Update voices * Update versions * Update phonemize JSDoc * Use updated voice pack * Update versions * Update demo (v1.0 & WebGPU support) * Update README * Enforce maximum number of tokens * Update README * [version] Update to 1.1.1
This commit is contained in:
@@ -1,11 +1,20 @@
|
||||
import { KokoroTTS } from "kokoro-js";
|
||||
import { detectWebGPU } from "./utils.js";
|
||||
|
||||
const model_id = "onnx-community/Kokoro-82M-ONNX";
|
||||
// Device detection
|
||||
const device = (await detectWebGPU()) ? "webgpu" : "wasm";
|
||||
self.postMessage({ status: "device", device });
|
||||
|
||||
// Load the model
|
||||
const model_id = "onnx-community/Kokoro-82M-v1.0-ONNX";
|
||||
const tts = await KokoroTTS.from_pretrained(model_id, {
|
||||
dtype: "q8", // Options: "fp32", "fp16", "q8", "q4", "q4f16"
|
||||
dtype: device === "wasm" ? "q8" : "fp32",
|
||||
device,
|
||||
}).catch((e) => {
|
||||
self.postMessage({ status: "error", error: e.message });
|
||||
throw e;
|
||||
});
|
||||
|
||||
self.postMessage({ status: "ready" });
|
||||
self.postMessage({ status: "ready", voices: tts.voices, device });
|
||||
|
||||
// Listen for messages from the main thread
|
||||
self.addEventListener("message", async (e) => {
|
||||
|
||||
Reference in New Issue
Block a user