Install
openclaw skills install telegram-voice-group向指定 Telegram 群组发送语音消息
openclaw skills install telegram-voice-group使用 Telegram 群组话题功能实现隔离上下文替代 Discord,并可以指定 Telegram 群组发送语音消息。
agent:main:telegram:group:{groupId}:topic:{threadId}edge-tts - 用于生成语音ffmpeg - 用于格式转换向 agent:main:telegram:group:[GROUP_ID]:topic:[TOPIC_ID] 发送语音: 你的语音内容
"向 {群组会话键} 发送语音: {语音内容}"
例如: "向 agent:main:telegram:group:[GROUP_ID]:topic:[TOPIC_ID] 发送语音: 大家好,我是[ASSISTANT_NAME],[NICKNAME]的AI助理。很高兴在[MOLTBOT_COMMUNITY]社区与大家见面,祝大家交流愉快!"
await sessions_spawn({
task: "向 agent:main:telegram:group:[GROUP_ID]:topic:[TOPIC_ID] 发送语音: 这是一条测试消息",
agentId: "telegram-voice-group"
})
const { sendVoiceToTelegramGroup } = require('./index.js');
await sendVoiceToTelegramGroup({
text: "语音内容",
groupId: "agent:main:telegram:group:[GROUP_ID]:topic:[TOPIC_ID]",
voice: "zh-CN-XiaoxiaoNeural",
rate: "+5%"
});
可通过 threadId 参数向特定话题发送语音消息:
const { message } = require('@openclaw/core');
await message({
action: 'send',
channel: 'telegram',
to: '[GROUP_ID]',
message: '语音消息内容',
asVoice: true,
media: '语音文件路径',
threadId: [TOPIC_ID] // 指定话题ID
});
const { sendVoiceToTelegramGroup } = require('./index.js');
await sendVoiceToTelegramGroup({
text: "语音内容",
groupId: "agent:main:telegram:group:[GROUP_ID]:topic:[TOPIC_ID]",
voice: "zh-CN-XiaoxiaoNeural",
rate: "+5%",
threadId: [TOPIC_ID] // 可选:指定话题ID
});
当检测到用户请求向群组发送语音消息时,系统将自动执行以下步骤:
使用 edge-tts 生成语音文件
edge-tts --voice zh-CN-XiaoxiaoNeural --rate=+5% --text "语音内容" --write-media /tmp/voice_msg.mp3
使用 ffmpeg 转换为 Telegram 兼容格式
ffmpeg -y -i /tmp/voice_msg.mp3 -c:a libopus -b:a 48k -ac 1 -ar 48000 -application voip /tmp/voice_msg.ogg
使用 message 工具发送语音文件到指定群组
message({action: 'send', channel: 'telegram', to: '[GROUP_ID]', message: '', asVoice: true, media: '/tmp/voice_msg.ogg', threadId: [TOPIC_ID]})
asVoice: true 参数确保以语音气泡形式发送,而非文件为避免朗读出标记符号,技能会自动清洗文本内容:
| 需移除 | 示例 |
|---|---|
| Markdown 标记 | **加粗**、`代码`、# 标题 |
| URL 链接 | https://example.com |
| 特殊符号 | ---、***、>>> |
agent:main:telegram:group:{groupId}:topic:{threadId}agent:main:telegram:group:{groupId}:topic:{threadId})单独配置 AI 模型agent:main:telegram:group:{groupId}:topic:{threadId}