Local generation, no Token required — Uses Microsoft Edge-TTS to generate high-quality Chinese speech, fully offline processing, no need to apply for any API Key.
Features
- 🔒 Fully local: No need for OpenAI / Google / Azure or other cloud service Tokens
- 🎯 Zero cost: Edge-TTS is free to use, no call limits
- 🗣️ High-quality voices: Uses Microsoft Xiaoxiao (zh-CN-XiaoxiaoNeural) by default
- 📱 Native Telegram support: Output format conforms to the voice bubble standard
Install dependencies
# Edge-TTS
pip install edge-tts
FFmpeg (Debian/Ubuntu)
apt install ffmpeg
## 使用方法
```bash
# 1. 生成原始音频
edge-tts --voice zh-CN-XiaoxiaoNeural --rate=+5% --text "你好,这是测试" --write-media raw.mp3
# 2. 转换为 Telegram 语音格式
ffmpeg -y -i raw.mp3 -c:a libopus -b:a 48k -ac 1 -ar 48000 -application voip voice.ogg
Technical specifications
Text format cleaning
Text must be cleaned before generating speech to avoid reading out markup symbols:
| Needs to be removed | Example |
|---|---|
| Markdown markup | **加粗**、`代码`、# 标题 |
| URL links | https://example.com |
| Special symbols | ---、***、>>> |
Cleaning example:
# 简单清洗(去除常见 Markdown)
TEXT=$(echo "$RAW_TEXT" | sed 's/\*\*//g; s/`//g; s/^#\+ //g')
Telegram voice bubble format
Telegram requires voice messages to use OGG Opus format, otherwise they will be displayed as files instead of voice bubbles:
ffmpeg -i input.mp3 -c:a libopus -b:a 48k -ac 1 -ar 48000 -application voip output.ogg
Parameter description:
| Parameter | Value | Description |
|---|---|---|
-c:a |
libopus |
Encoder required by Telegram |
-b:a |
48k |
Audio bitrate |
-ac |
1 |
Mono (voice standard) |
-ar |
48000 |
Sampling rate 48kHz |
-application |
voip |
Optimized for speech |
Available voices
# 查看所有中文声线
edge-tts --list-voices | grep zh-CN
Recommended:
zh-CN-XiaoxiaoNeural— Female voice, natural and friendly (default)zh-CN-YunxiNeural— Male voice, steady and professionalzh-CN-XiaoyiNeural— Female voice, lively and young
Speech rate adjustment
# 加速 5%
edge-tts --rate=+5% --text "..." --write-media out.mp3
# 减速 10%
edge-tts --rate=-10% --text "..." --write-media out.mp3
Acknowledgements
Tuned and maintained by @sanwecn .