Web TTS Speaker

网页一键朗读:URL/文本 → TTS语音 → 多渠道自动匹配(飞书语音条 / 微信/TG/Discord MP3)

Audits

Pass

Install

openclaw skills install web-tts-speaker

web-tts-speaker v3.0

网页/文字 → TTS语音 → 自动匹配来源渠道发送


🧠 Agent 工具定义

当用户希望朗读网页将文字转为语音时,按以下流程操作。

触发条件

  • "朗读 / 读一下 / 帮我读 / 听一下" + URL/文本
  • 直接发送 URL(自动朗读)
  • "转语音 / 生成语音 / TTS"

执行流程

Step 1:提取目标

"朗读 https://abc.com/article"  → URL
"读一下:你好世界"              → 文本
直接发 URL                      → URL

Step 2:获取来源渠道

从 inbound context 的 channel 字段获取:

来源
openclaw-weixin微信
feishu飞书
telegramTelegram
discordDiscord

Step 3:调用 CLI(安全模式)

⚠️ 安全规则:

  1. 必须用 exec 的数组(argv)模式,禁止拼接 shell 字符串
  2. URL 必须验证以 http://https:// 开头
  3. 不处理含密钥、密码、内部文档的敏感内容
# ✅ 安全:argv 数组传参,不走 shell 解析
TOOL_DIR = r"C:\Users\www\.openclaw\workspace\skills\web-tts-speaker"

# 朗读网页
result = exec(
    command=["python", "cli.py", "--url", url],
    workdir=TOOL_DIR,
    timeout=300
)

# 文字转语音
result = exec(
    command=["python", "cli.py", "--text", text],
    workdir=TOOL_DIR,
    timeout=300
)

注意:workdir 参数指定工作目录,执行时自动切换到该目录。

Step 4:解析输出

CLI 一次性输出全部渠道标记。根据来源渠道选取对应的:

来源 channel取用标记发送文件
openclaw-weixin[WECHAT_VOICE]file=xxx.mp3
feishu[FEISHU_VOICE]file=xxx.opus
telegram[TELEGRAM_VOICE]file=xxx.mp3
discord[DISCORD_VOICE]file=xxx.mp3

Step 5:发送语音

# 微信
message(action="send", channel="openclaw-weixin", media=file_path)

# 飞书语音条
message(action="send", channel="feishu", asVoice=true, filePath=file_path)

# Telegram / Discord
message(action="send", channel="telegram", media=file_path)

完整调用示例

# 用户说:朗读 https://zshttp.com/2981.html

# Step 2
channel = "openclaw-weixin"         # 从 inbound context 获取

# Step 3 - 安全调用
import re
if not re.match(r"^https?://", url):
    return "仅支持 http/https 链接"

result = exec(
    command=["python", "cli.py", "--url", url],
    workdir=r"C:\Users\www\.openclaw\workspace\skills\web-tts-speaker",
    timeout=300
)

# Step 4 - 解析标记
for line in result.stdout.split("\n"):
    if line.startswith("[WECHAT_VOICE]"):
        # 取下几行找到 file=xxx
        ...

# Step 5 - 发送
message(action="send", channel=channel, media=file_path)

快速命令

# 自动模式(推荐):生成全部格式
python cli.py --url https://example.com/article
python cli.py --text "你好世界"

# 指定单渠道
python cli.py --channel feishu --text "你好"
python cli.py -c wechat --text "你好"

支持渠道

渠道格式发送方式
feishu.opus (16kHz)asVoice=true
wechat.mp3 (24kHz)media=xxx
telegram.mp3 (24kHz)media=xxx
discord.mp3 (24kHz)media=xxx

⚠️ 微信说明openclaw-weixin 插件暂未实现原生语音气泡发送(GH#61031),当前以 MP3 文件形式发送。

长文本支持

自动分块 + 拼接,不限长度。输出进度:

[1/2] 生成语音 (2772 字符)... 9分18秒
[2/2] 生成语音 (1543 字符)... 5分19秒
✅ 合成完成
📁 wechat: voice.mp3 (5140KB, 14分37秒)

语音角色

python cli.py --text "你好" --voice zh-CN-YunxiNeural
  • zh-CN-XiaoxiaoNeural — 晓晓(女声,默认)
  • zh-CN-YunxiNeural — 云希(男声,活泼)
  • zh-CN-YunyangNeural — 云扬(男声,新闻)
  • zh-CN-XiaoyiNeural — 晓伊(女声,柔和)

输出标记示例

[WECHAT_VOICE]
channel=wechat
file=/path/to/voice.mp3
text=新闻摘要...
dur=877
size=5262860
full=微信文件消息
[/WECHAT_VOICE]

依赖

pip install -r requirements.txt

依赖锁定的精确版本(ClawScan 推荐):

  • edge-tts==7.2.8
  • beautifulsoup4==4.14.3
  • requests==2.33.1

额外依赖:FFmpeg(系统级)。