使用 Kokoro 实现本地、低 CPU 占用且高质量的语音合成 (TTS)
Local, CPU-Friendly, High-Quality TTS (Text-to-Speech) with Kokoro

原始链接: https://ariya.io/2026/03/local-cpu-friendly-high-quality-tts-text-to-speech-with-kokoro/

得益于 **Kokoro** 等模型,本地语音生成变得既高度易用又注重隐私。Kokoro 仅有 8200 万参数,仅需使用计算机 CPU 即可生成逼真的多语言语音,从而将 GPU 释放出来,用于大语言模型推理等其他任务。 使用 **Kokoro-FastAPI** 容器可以轻松部署 Kokoro,该容器提供了 Web 用户界面和兼容 OpenAI 的 API。这使得开发者能够利用 Python 或 JavaScript,将高质量的语音合成(TTS)轻松集成到现有应用程序中。该系统效率极高,即使在 12 年前的英特尔 i7-4770K 处理器上,也能在几秒钟内生成清晰的音频。用户还可以从 50 种不同的音色中进行选择,以自定义输出效果。 对于有更多功能需求的用户,**Speaches** 是一个值得关注的替代方案。它提供了兼容 OpenAI 的接口,并内置了 Whisper 模型,为语音转文字(STT)和文字转语音(TTS)需求提供了一站式解决方案。通过在本地运行这些工具,用户无需牺牲数据隐私,即可将大语言模型的交互方式从文本转变为语音。

Hacker News 社区对 **Kokoro** 表现出了极大的热情。这是一款高质量、轻量级的语音合成(TTS)模型,无需昂贵的 GPU,在消费级 CPU 上也能出色运行。 **核心要点:** * **性能与质量:** 用户称赞 Kokoro 输出的语音非常自然,许多人认为其品质可与 ElevenLabs 等高端服务相媲美。它占用空间小,非常适合本地化及隐私性强的应用。 * **应用场景:** 开发者正将其集成到各种项目中,包括文章阅读器、播客生成器、家庭自动化(Home Assistant)、辅助功能工具以及语言学习应用。 * **技术优势:** 它支持手动 IPA 发音指南,且运行速度极快。一些用户已将其移植到移动端(iPhone ANE)和 WebGPU/Wasm,以实现更广泛的覆盖。 * **常见局限:** 该模型在处理极短输入(如单个单词)时表现不佳,常会产生多余的声音。用户建议采用“填充”方案作为变通方法,即输入完整的句子,之后再裁剪出特定的单词。 * **社区评价:** 许多人认为 Kokoro 是本地 AI 领域的“游戏规则改变者”。他们指出,在普通硬件上实现高性能、私密且高效的模型,正在改变个人开发者的能力边界。
相关文章

原文

Just a few years ago, realistic local speech generation seemed unimaginable. Today, its quality is exceptional and, crucially, it delivers these results without compromising privacy.

The video above showcases audio generated from a sample text, running entirely on the local machine previously discussed in the GTX 1080 Ti for Local LLM article. While this machine has a dedicated GPU, the GPU is fully reserved for LLM inference and the speech synthesis is powered entirely by the CPU.

The model used is Kokoro, which, despite having only 82M parameters, produces realistic speech in multiple languages including English, Mandarin, and Hindi. It provides around 50 distinct voices, primarily optimized for English.

There are several ways to set up a server for Kokoro. The simplest method involves using a pre-made container image called Kokoro-FastAPI, which includes pre-downloaded voice models. Because of that, the container image is rather large, at about 5 GB in size.

To launch the container using Docker or Podman, use the following command:

podman run -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-cpu

To quickly verify that it runs correcly, the container serves a simple web UI at localhost:8880/web. Here you can generate (and automatically play) an audio given some text.

Kokoro web UI

In addition to the simple web UI, this container also serves a TTS interface compatible with the OpenAI speech API, making it easy to adapt existing programs that already use the OpenAI speech API. To facilitate a quick test, sample code in both JavaScript and Python is available at github.com/remotebrowser/speak. Cloning this repository will enable you to follow the subsequent demonstration.

For JavaScript:

export TTS_API_BASE_URL=http://127.0.0.1:8880/v1
./speak.js "Good morning! How are you today?"

For Python, the command is very similar:

export TTS_API_BASE_URL=http://127.0.0.1:8880/v1
./speak.py "Good morning! How are you today?"

The generated audio will be saved as an MP3 file. If SoX or Sound eXchange (see sox.sf.net for details) is installed on your machine, the audio will also play back automatically.

You can also select a different voice by setting the TTS_VOICE environment variable:

export TTS_API_BASE_URL=http://127.0.0.1:8880/v1
export TTS_VOICE="am_eric"
./speak.js "Good morning! How are you today?"

A complete list of available voices can be found on the official Kokoro project page: huggingface.co/hexgrad/Kokoro-82M/blob/main/VOICES.md.

How fast is the synthesis? Here are some measurements using the am_eric voice on a short test paragraph:

Jupiter is the largest and most massive planet in our solar system. This gas giant, made mostly of hydrogen and helium, is known for its Great Red Spot—a massive storm observed for centuries.

The following list summarizes the generation time (best of 3 runs) across different CPUs:

  • Intel Core i7-4770K: 4.7 seconds
  • Apple M2 Pro: 4.5 seconds
  • AMD Ryzen 7 8745HS: 1.5 seconds

The first CPU in the list was released 12 years ago. If that ancient CPU can do the job just fine, you know that this is a highly capable TTS system.

Finally, for an alternative OpenAI-compatible containerized TTS service, consider Speaches (speaches.ai). Unlike Kokoro-FastAPI, Speaches requires you to explicitly download voice weights via its API, as they are not bundled in the container image. However, Speaches offers an advantage by including Whisper, OpenAI’s renowned high-quality Speech-to-Text (STT) system. If your application needs both TTS and STT functionality, Speaches could be your one-stop solution.

When combined with a local LLM, a speech synthesis system like this allows you to enjoy listening to LLM answers instead of reading them!

Note: This article originally appeared on the Remote Browser Substack.

联系我们 contact @ memedata.com