给 OpenClaw 套上通话功能 - 语音 AI Agent 实战

给 OpenClaw 套上通话功能 - 语音 AI Agent 实战

来源:X @铁锤人 https://x.com/i/status/2029127930920780028

背景

作者为了让老爸(一个普通中国老年人)能够使用 OpenClaw,给他添加了语音通话功能。老爸觉得 OpenClaw”软件不错,能控制很多东西,相当于有手脚了,但是就是不好用”——因为需要打字,而老年人老花眼。豆包可以说句话就能实现AI交互,所以作者决定给 OpenClaw 加上语音功能。

技术方案

使用 ten-framework 作为语音 AI agent 框架,将语音对话能力与 OpenClaw Gateway 连接。

核心技术栈

组件 用途
Deepgram 语音识别 (STT) - 将用户语音实时转为文字
DeepSeek LLM 大语言模型 - 国内直连,OpenAI 兼容接口,价格极低(约 OpenAI 的 1/50)
ElevenLabs TTS 语音合成
Agora 实时音视频通信
OpenClaw AI Agent 控制能力

为什么选择 ten-framework?

  1. 文档完善,部署流程清晰
  2. star 比较多,社区活跃
  3. 与 OpenClaw 架构兼容

免费服务注册指南

1. DeepSeek(LLM)

注册地址:https://deepseek.com

  • 手机号或邮箱注册
  • 最低充值 ¥2,¥10 能用很久
  • 获取 API Key

2. Deepgram(语音识别)

注册地址:https://deepgram.com

  • 支持 Google / GitHub 登录
  • 新账号赠送 $200 免费额度
  • 获取 API Key

3. ElevenLabs(TTS)

  • 注册获取 API Key
  • 免费额度足够个人测试

4. Agora(实时通信)

注册地址:https://agora.io

  • 创建项目,获取 App ID 和 Certificate
  • 在 Signaling 选择数据中心开启 rtm
  • 每月 10,000 分钟免费

部署步骤

1. 克隆项目

git clone <ten-framework-repo>

2. 配置环境变量

ai_agents/ 下创建 .env 文件:

# --- 服务配置 ---
LOG_PATH=/tmp/ten_agent
LOG_STDOUT=true
GRAPH_DESIGNER_SERVER_PORT=49483
SERVER_PORT=8080
WORKERS_MAX=100
WORKER_QUIT_TIMEOUT_SECONDS=60

# --- 前端 ---
AGENT_SERVER_URL=http://localhost:8080
TEN_DEV_SERVER_URL=http://localhost:49483
NEXT_PUBLIC_EDIT_GRAPH_MODE=false

# --- Agora RTC/RTM ---
AGORA_APP_ID=<你的 Agora App ID>
AGORA_APP_CERTIFICATE=<你的 Agora App Certificate>

# --- LLM (DeepSeek) ---
OPENAI_API_BASE=https://api.deepseek.com
OPENAI_API_KEY=<你的 DeepSeek API Key>
OPENAI_MODEL=deepseek-chat

# --- STT (Deepgram) ---
DEEPGRAM_API_KEY=<你的 Deepgram API Key>

# --- TTS (ElevenLabs) ---
ELEVENLABS_TTS_KEY=<你的 ElevenLabs API Key>

# --- OpenClaw Gateway ---
OPENCLAW_GATEWAY_URL=ws://host.docker.internal:18789
OPENCLAW_GATEWAY_PASSWORD=<你的 Gateway 密码>
OPENCLAW_GATEWAY_ORIGIN=http://host.docker.internal:18789
OPENCLAW_GATEWAY_SCOPES=operator.write
OPENCLAW_GATEWAY_DEVICE_IDENTITY_PATH=/data/openclaw/device_identity.js

3. OpenClaw 配置

# 设置密码模式
openclaw config set gateway.auth.mode password
openclaw config set gateway.auth.password lxfater

在 OpenClaw 的 Settings → Gateway → Control UI Allowed Origins 中添加:

http://host.docker.internal:18789

4. 代码修改(适配中文)

修改 ai_agents/agents/examples/openclaw-example/tenapp/property.json

  • STT 语言:en-US → zh
  • STT 模型:nova-3 → nova-2(支持中文)
  • LLM base_url:从硬编码改为 ${env:OPENAI_API_BASE}
  • LLM model:从 gpt-4o 改为 ${env:OPENAI_MODEL}

5. macOS ARM 架构注意事项

Docker 需要开启虚拟化:

  1. 打开 Docker Desktop → Settings → General
  2. 勾选 Use Rosetta for x86_64/amd64 emulation on Apple Silicon
  3. Apply & Restart

构建镜像:

docker build --platform linux/amd64 -f agents/examples/openclaw-example/Dockerfile -t openclaw-example-app .

6. 运行

# 保持 OpenClaw 开启
openclaw gateway --force

# 运行容器
docker run --rm -it --env-file .env -p 8080:8080 -p 3000:3000 openclaw-example-app

访问 http://localhost:3000,选择麦克风和 voice-assistant 配置,即可开始语音对话。

效果

接入语音对话功能后,OpenClaw 开始有能力给不懂技术的普通人使用。作者给老爸的 OpenClaw 添加了一个”修复图片”的 skill,老爷子乐呵呵地把自己年轻时候的照片进行修复。

总结

  • 普通人对 AI 产品只有两个要求:好用,能干活
  • 语音交互大幅降低了 AI Agent 的使用门槛
  • 通过 ten-framework 可以快速将现有 Agent 语音化

本文为付费合作,保证教程步骤本人实验过,真实有效