我做了一个 Mac 上的 TTS 工具
我做了一个 Mac 上的 TTS 工具。起因很简单:做完剧后书 APP 之后,需要一个听书功能。
I built a TTS tool for Mac. The reason was simple: after building the Juhoushu app, I needed a text-to-speech feature for audiobook playback.
翻了一圈,结果挺让人失望的。
Looked around, and the results were pretty disappointing.
iOS 上能用的 TTS 方案,要么要付费,要么音质跟机器人一样。装本地 TTS 模型的方案也试过——音质是好了,但你得配推理引擎,得有 N 卡做语音推理。手机上没有 N 卡,就算做成服务端方案,光是 GPU 服务器的月费就够买几百本有声书了。
Usable TTS solutions on iOS either cost money or sound robotic. I tried local TTS models too — the quality was better, but you need an inference engine and an NVIDIA GPU for voice inference. No GPU on a phone. Even as a server-side solution, the monthly GPU cost alone would buy hundreds of audiobooks.
然后我突然想起来一件事。
Then something suddenly occurred to me.
我的 MacBook 上不是有个 Siri 吗?那个朗读声音挺好的。
Doesn't my MacBook have Siri? That voice sounds pretty good.
顺着这个念头去看了下 macOS 的语音系统——还真有。系统自带了大量高质量语音,中文的、英文的、日文的,而且关键是:它不需要本地推理引擎,不用 GPU,纯 CPU 就能跑出很自然的语音。
Following that thought, I looked into macOS's speech system — and it's real. The system comes with a ton of high-quality voices: Chinese, English, Japanese, and more. The key: no inference engine needed, no GPU required, pure CPU can produce natural-sounding speech.
这不就解决了吗?不用付费,不用 GPU,就在那儿等着,只是没人把它包成一个可以直接接管道用的命令行工具而已。
Problem solved, right? No fees, no GPU, just sitting there — only nobody had wrapped it into a command-line tool you could pipe into.
所以我写了一个。
So I wrote one.
叫 tts_pipe,一个不到 50KB 的 Swift 二进制文件,做的事很简单:读文本,调 macOS 的 AVSpeechSynthesizer 合成语音,PCM 音频直接往 stdout 里写。不经过硬盘,不写临时文件,纯粹的 Unix 管道过滤器。
Called tts_pipe — a Swift binary under 50KB. What it does is simple: read text, call macOS's AVSpeechSynthesizer to generate speech, write raw PCM audio straight to stdout. No disk I/O, no temp files, a pure Unix pipe filter.
用法大概是这样:
Usage looks something like this:
echo "早,今天继续听书" | ./tts_pipe --stdin com.apple.voice.premium.zh-CN.Yun 0.5 | ffplay -f s16be -ar 22050 -ac 1 pipe:0 -
echo "Morning, let's continue the book" | ./tts_pipe --stdin com.apple.voice.premium.zh-CN.Yun 0.5 | ffplay -f s16be -ar 22050 -ac 1 pipe:0 -
Yun 这个语音就是 Siri 用的那个——你下载一次免费的 Premium Voice,系统就用它来完成语音输出。不需要你去搞什么 Triton Server、vLLM、HuggingFace 模型仓库。
The Yun voice is the one Siri uses — download the free Premium Voice once, and the system uses it for speech output. No need for Triton Server, vLLM, or HuggingFace model repos.
macOS 的 Premium 语音是 Apple 几十年的语音合成研发成果,中文有云、悦、涵、莉莉、丽莲,英文有 Samantha、Alex、Ava,日文有 Kyoko,德文、法文、韩文也有,质量超过一群开源的本地 TTS 方案。而且因为不涉及模型推理,延迟极低,功耗极低,开一整天也不发烫。
macOS Premium voices are the fruit of decades of Apple speech synthesis R&D. Chinese voices: Yun, Yue, Han, Lili, Lilian. English: Samantha, Alex, Ava. Japanese: Kyoko. German, French, Korean too. Quality surpasses many open-source local TTS solutions. And because there's no model inference involved, latency is extremely low, power draw is minimal — running all day won't heat anything up.
Mac 之外这几个语音其实谁都接触过——Siri 说的就是这些声音。你只是没想过原来可以这样把它从苹果的壳里拆出来,装进自己的应用里。
Beyond Macs, everyone has actually heard these voices — Siri speaks with them. You just never realized you could pull them out of Apple's shell and plug them into your own applications.
后来想既然 TTS 做了,不如把 STT(语音转文字)也加上。macOS 同样有本地的 SFSpeechRecognizer,用它的 Neural Engine 做推理,不上传、无 API Key、不计费。写了 stt_pipe,接上 sox 就能录音转文字。
Later I figured, since TTS was done, why not add STT (speech-to-text) too? macOS also has a local SFSpeechRecognizer — uses the Neural Engine for inference, no uploads, no API key, no billing. Wrote stt_pipe — hook it up to sox and you've got recording-to-text.
一套下来总共就两个微小的可执行文件——TTS 大概 48K,STT 大概 44K。Python 也能调,Node 也能调,Dart Flutter 上接着用当然更没问题,因为本来就是给 APP 做的。
The whole thing is just two tiny executables — TTS about 48KB, STT about 44KB. Callable from Python, Node, Dart/Flutter of course — that's what it was built for in the first place.
这也是为什么我把整个方案开源成了 macOS Voice Toolkit。不是为了做一个「最好的 TTS」,而是发现系统里已经有了足够好的——它不需要 GPU、不需要付费、不需要联网、音质还不差。你只需要把它接出来。
That's why I open-sourced the whole thing as macOS Voice Toolkit. Not trying to build "the best TTS," but realizing the system already has something good enough — no GPU, no fees, no internet required, and decent quality. You just need to wire it out.
说来也有点讽刺。我们找了一圈的 API、SaaS、推理服务,最后答案就躺在系统设置里——辅助功能——语音内容——管理语音。好像很多东西都是这样:最好的方案,往往不是最新的,而是最被忽略的。
Kind of ironic. We searched through APIs, SaaS, inference services — and the answer was sitting in System Settings: Accessibility → Spoken Content → Manage Voices. Feels like many things are this way: the best solution is often not the newest, but the most overlooked.
开源地址:https://github.com/rrlab-tech/mac-tts
https://github.com/rrlab-tech/mac-tts
万一你的 APP 也需要一个听书功能,或者你只是想有个能朗读 Markdown、PDF、代码注释的命令行工具——试试看。
If your app happens to need an audiobook feature, or you just want a command-line tool that reads Markdown, PDFs, code comments aloud — give it a try.