Trie Chen's picture

Trie Chen

TrieChen
Β·

AI & ML interests

None yet

Recent Activity

View all activity

Organizations

None yet

TrieChen's activity

replied to Xenova's post 11 days ago
view reply

Hi, I’m trying to use kokoro-js in a Next.js 15 project, but I keep getting the following error:

Module not found: Can't resolve './'
./node_modules/kokoro-js/dist/kokoro.web.js:1:742149

ζˆͺεœ– 2025-01-30 上午10.00.14.png

However, when I test the same setup in a React + Vite project, it runs without any additional configuration and works as expected.

Here’s my package.json setup:

"kokoro-js": "^1.0.1",
"next": "^15.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"

And my Next.js next.config.mjs webpack configuration:

const nextConfig = {
  webpack: (config) => {
    config.resolve.alias = {
      ...config.resolve.alias,
      sharp$: false,
      "onnxruntime-node$": false,
      "onnxruntime-web$": false,
    };
    return config;
  },
};

export default nextConfig;

This is how I initialize kokoro-js in my worker.ts file:

import { KokoroTTS } from "kokoro-js";

addEventListener(
  "message",
  async (event: MessageEvent<{ type: string; number: number }>) => {
    const { type, number } = event.data;
    console.log("Initializing model...");
    const tts = await KokoroTTS.from_pretrained(
      "onnx-community/Kokoro-82M-ONNX",
      {
        dtype: "q8",
      }
    );
  }
);

Is there any known issue with using kokoro-js in Next.js 15?

Since the same code runs fine in React + Vite without any extra setup, is there something specific I need to configure in Next.js to make kokoro-js work properly?

Any help would be appreciated! Thanks.

replied to Xenova's post 11 days ago
reacted to Xenova's post with πŸ”₯ 14 days ago
view post
Post
5139
Introducing Kokoro.js, a new JavaScript library for running Kokoro TTS, an 82 million parameter text-to-speech model, 100% locally in the browser w/ WASM. Powered by πŸ€— Transformers.js. WebGPU support coming soon!
πŸ‘‰ npm i kokoro-js πŸ‘ˆ

Try it out yourself: webml-community/kokoro-web
Link to models/samples: onnx-community/Kokoro-82M-ONNX

You can get started in just a few lines of code!
import { KokoroTTS } from "kokoro-js";

const tts = await KokoroTTS.from_pretrained(
  "onnx-community/Kokoro-82M-ONNX",
  { dtype: "q8" }, // fp32, fp16, q8, q4, q4f16
);

const text = "Life is like a box of chocolates. You never know what you're gonna get.";
const audio = await tts.generate(text,
  { voice: "af_sky" }, // See `tts.list_voices()`
);
audio.save("audio.wav");

Huge kudos to the Kokoro TTS community, especially taylorchu for the ONNX exports and Hexgrad for the amazing project! None of this would be possible without you all! πŸ€—

The model is also extremely resilient to quantization. The smallest variant is only 86 MB in size (down from the original 326 MB), with no noticeable difference in audio quality! 🀯
Β·