Chinese TTS Voice Generation
Generate natural Chinese speech using Microsoft Edge TTS and send as Feishu voice messages.
Quick Reference
CODEBLOCK0
Critical Rules
- 1. Always set UTF-8 env vars — System locale is ISO-8859-1, Chinese text will be corrupted without INLINECODE0
- Must use opus format — Feishu only treats
.opus as voice messages; MP3/WAV become file attachments - Must send from workspace —
/tmp is not in Feishu's mediaLocalRoots whitelist; files there fail silently and fall back to plain text - Use ASCII filenames — Chinese filenames may cause encoding issues in multipart uploads
Voice Options
| Voice | Gender | Style |
|---|
| INLINECODE4 | Male | Natural, warm (recommended) |
| INLINECODE5 |
Female | Natural, friendly |
|
zh-CN-YunjianNeural | Male | Authoritative |
For Long Text
Write text to a file and use -f flag:
CODEBLOCK1
Troubleshooting
- - Gibberish audio → Missing UTF-8 env vars
- File sent as attachment, not voice → Not opus format, or not from workspace path
- Upload fails silently → File not in
mediaLocalRoots (use workspace dir) - "哈米" instead of "虾米" → Google TTS (gtts) issue; use edge-tts instead
中文TTS语音生成
使用Microsoft Edge TTS生成自然的中文语音,并以飞书语音消息形式发送。
快速参考
bash
1. 生成MP3文件
LANG=en
US.UTF-8 LCALL=en_US.UTF-8 /home/clawpi/.local/bin/edge-tts \
--voice zh-CN-YunxiNeural \
--text 你的文本内容 \
--write-media /tmp/output.mp3
2. 转换为Opus格式
ffmpeg -i /tmp/output.mp3 -c:a libopus -b:a 64k -ar 48000 \
/home/node/.openclaw/workspace/output.opus -y
3. 通过飞书发送
message(asVoice=true, contentType=audio/ogg,
filePath=/home/node/.openclaw/workspace/output.opus,
filename=output.opus)
关键规则
- 1. 始终设置UTF-8环境变量 — 系统区域设置为ISO-8859-1,未设置LANG=enUS.UTF-8 LCALL=en_US.UTF-8会导致中文文本乱码
- 必须使用opus格式 — 飞书仅将.opus文件识别为语音消息;MP3/WAV格式会变成文件附件
- 必须从工作空间发送 — /tmp目录不在飞书的mediaLocalRoots白名单中;该目录下的文件会静默失败并回退为纯文本
- 使用ASCII文件名 — 中文文件名可能导致多部分上传时出现编码问题
语音选项
| 语音 | 性别 | 风格 |
|---|
| zh-CN-YunxiNeural | 男声 | 自然、温暖(推荐) |
| zh-CN-XiaoxiaoNeural |
女声 | 自然、友好 |
| zh-CN-YunjianNeural | 男声 | 权威 |
长文本处理
将文本写入文件并使用-f参数:
bash
echo 长文本内容... > /tmp/text.txt
LANG=enUS.UTF-8 LCALL=en_US.UTF-8 /home/clawpi/.local/bin/edge-tts \
--voice zh-CN-YunxiNeural -f /tmp/text.txt --write-media /tmp/output.mp3
故障排除
- - 音频乱码 → 缺少UTF-8环境变量
- 文件以附件形式发送而非语音 → 不是opus格式,或未使用工作空间路径
- 上传静默失败 → 文件不在mediaLocalRoots中(请使用工作空间目录)
- 哈米代替虾米 → Google TTS(gtts)的问题;请改用edge-tts