语音处理技能 - 完整的语音输入输出解决方案。功能:(1) 语音识别 ASR - 将用户语音转录为文字(使用 Whisper)(2) 语音合成 TTS - 将文字转换为语音(使用 Edge TTS)。触发场景:用户发送语音消息、主动要求"用语音读..."、"语音回复"等。支持平台:Telegram、Discord...
⚠️ 安装后请将 scripts/ 目录下的 .txt 文件名后缀去掉(去掉 .txt)才能正常使用!
完整的语音输入输出解决方案,同时支持语音识别(ASR)和语音合成(TTS)。
| 方向 | 技术 | 说明 |
|---|---|---|
| 语音→文字 | Whisper (本地) | 用户发语音时自动转录 |
| 文字→语音 | Edge TTS | 生成语音回复 |
# 必须安装的包
pip install edge-tts whisper torch click
# 如果没有 ffmpeg(音频处理需要)
# macOS: brew install ffmpeg
# Ubuntu: sudo apt install ffmpeg
要在 OpenClaw 中使用语音识别,需要修改 openclaw.json:
{
"tools": {
"media": {
"audio": {
"enabled": true,
"models": [
{
"type": "cli",
"command": "python3",
"args": [
"{{SkillPath}}/voice-tts/scripts/whisper",
"--model",
"base",
"{{MediaPath}}"
]
}
]
}
}
}
}
说明:
{{SkillPath}} 会自动替换为 skill 安装路径--model base 可以改为 turbo 等其他模型openclaw gateway restart 重启生效当用户发送语音消息时:
当用户说以下话术时:
Skill 自带两个脚本:
位置:{{SkillPath}}/scripts/whisper
# 基本用法
python3 {{SkillPath}}/scripts/whisper audio.mp3
# 指定模型(默认 base)
python3 {{SkillPath}}/scripts/whisper audio.mp3 --model turbo
# 输出 JSON(带语言检测)
python3 {{SkillPath}}/scripts/whisper audio.mp3 --json
# 带时间戳
python3 {{SkillPath}}/scripts/whisper audio.mp3 --timestamps
可用模型:
| 模型 | 大小 | 速度 | 精度 |
|---|---|---|---|
| tiny | 39M | 最快 | 较低 |
| base | 74M | 快 | 中等 |
| small | 244M | 中等 | 较好 |
| turbo | 809M | 快 | 较好 |
| large-v3 | 1.5GB | 慢 | 最高 |
推荐:首次使用下载 base 或 turbo 模型,后续可直接使用。
位置:{{SkillPath}}/scripts/edge_tts
# 基本用法
python3 {{SkillPath}}/scripts/edge_tts "要说的内容" -f output.mp3
# 指定声音
python3 {{SkillPath}}/scripts/edge_tts "你好" -v zh-CN-XiaoxiaoNeural -f output.mp3
# 调整语速
python3 {{SkillPath}}/scripts/edge_tts "你好" -r +10% -f output.mp3
推荐声音:
zh-CN-XiaoxiaoNeural - 中文女声(默认推荐)zh-CN-YunxiNeural - 中文男声en-US-JennyNeural - 英文女声自动检查未处理的语音消息并批量处理。
python3 {{SkillPath}}/scripts/auto_voice_check
功能:
~/.openclaw/media/inbound/ 下的新音频用于自动合成语音回复的钩子。
# 设置环境变量
export REPLY_TEXT="你好,我是AI助手"
export MEDIA_OUT="{{Workspace}}/media/outbound"
# 执行钩子
python3 {{SkillPath}}/scripts/voice_reply_hook
用户发送语音 → 系统转录 → 你理解内容 → 语音+文字回复
transcript 字段(转录文字)文字内容 → Edge TTS 合成 → 发送语音消息
mkdir -p {{Workspace}}/media/outbound/python3 {{SkillPath}}/scripts/edge_tts "内容" -f {{Workspace}}/media/outbound/voice.mp3~/.openclaw/media/inbound/(系统自动存放){{Workspace}}/media/outbound/FEISHU_APP_ID - 飞书应用 IDFEISHU_APP_SECRET - 飞书应用密钥FEISHU_CHAT_ID - 群聊 IDmessage(
action="send",
channel="telegram",
media="{{Workspace}}/media/outbound/voice.mp3",
asVoice=True,
message="这里是文字说明"
)
| 参数 | 说明 |
|---|---|
asVoice=True | 关键!设为 True 显示为语音消息 |
message(action="send", channel="discord", media=voice_path, message=text)
message(action="send", channel="whatsapp", media=voice_path, message=text)
飞书不支持直接发语音,用文件消息:
# 1. 获取 token
TENANT_TOKEN=$(curl -s -X POST "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal" \
-H "Content-Type: application/json" \
-d "{\"app_id\": \"${FEISHU_APP_ID}\", \"app_secret\": \"${FEISHU_APP_SECRET}\"}" | \
python3 -c "import json,sys; print(json.load(sys.stdin).get('tenant_access_token',''))")
# 2. 上传音频
FILE_KEY=$(curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/files" \
-H "Authorization: Bearer ${TENANT_TOKEN}" \
-F "file_type=mp3" \
-F "file=@{{Workspace}}/media/outbound/voice.mp3" | \
python3 -c "import json,sys; print(json.load(sys.stdin).get('data',{}).get('file_key',''))")
# 3. 发送
curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id" \
-H "Authorization: Bearer ${TENANT_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"receive_id\": \"${FEISHU_CHAT_ID}\", \"msg_type\": \"file\", \"content\": \"{\\\"file_key\\\": \\\"${FILE_KEY}\\\"}\"}"
或用卡片发文字说明:
curl -s -X POST "${FEISHU_WEBHOOK_URL}" \
-H "Content-Type: application/json" \
-d '{"msg_type": "interactive", "card": {"header": {"title": {"tag": "plain_text", "content": "🎙️ 语音消息"}, "template": "blue"}, "elements": [{"tag": "markdown", "content": "**文字内容:**\n\n要说的内容"}]}}'
用户语音:"今天天气怎么样?"
处理:
用户:"用语音读一下这段话:AI正在改变世界"
处理:
ffmpeg -versionls -la ~/.openclaw/media/inbound/python3 -c "import edge_tts"提示:这个技能可以自动和天气、新闻、日程等技能结合,用语音播报信息。
ZIP package — ready to use