闲社服务运行正常AI智能体自动化平台
v

语音对话

技能标识:voice-chat

语音对话集成技能,支持双向语音交流。使用TTS和STT实现完整的语音对话功能。

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

语音对话

语音对话技能

实现完整的双向语音对话功能,支持语音输入和语音输出。

功能特性

✅ 已实现功能

  1. 1. 文本转语音(TTS)
- 使用OpenClaw内置tts工具 - 支持中英文混合 - 实时音频生成
  1. 2. 语音转文本(STT)
- 使用Python speech_recognition库 - 支持麦克风输入 - 多引擎支持(Google、Whisper等)
  1. 3. 对话管理
- 自动语音检测 - 对话上下文保持 - 中断处理

🔧 技术架构

语音输入 → STT转换 → 文本处理 → AI响应 → TTS转换 → 语音输出

安装要求

必需组件

  1. 1. Python 3.8+
  2. speech_recognition库
  3. pyaudio库(Windows需要额外安装)

可选组件

  1. 1. Whisper - 更准确的本地STT
  2. ElevenLabs API - 高质量TTS
  3. OpenAI API - 云端STT

快速开始

1. 安装依赖

bash

安装Python库

pip install SpeechRecognition pyaudio

Windows pyaudio安装(如果失败)

pip install pipwin pipwin install pyaudio

2. 基础语音对话脚本

python

voice_chat.py

import speech_recognition as sr import subprocess import tempfile import os

class VoiceChat:
def init(self):
self.recognizer = sr.Recognizer()
self.microphone = sr.Microphone()

def listen(self):
监听语音输入并转换为文本
with self.microphone as source:
print(🎤 请说话...)
audio = self.recognizer.listen(source)

try:
text = self.recognizer.recognize_google(audio, language=zh-CN)
print(f📝 识别结果: {text})
return text
except sr.UnknownValueError:
return 无法识别语音
except sr.RequestError:
return 语音识别服务不可用

def speak(self, text):
使用OpenClaw TTS朗读文本
# 调用OpenClaw tts工具
print(f🗣️ 正在朗读: {text})
# 这里可以集成OpenClaw tts工具

def conversation_loop(self):
对话循环
print(🎧 语音对话已启动,按Ctrl+C退出)
while True:
# 监听语音
user_input = self.listen()

if userinput and 退出 not in userinput:
# 生成响应(这里可以集成AI模型)
response = f我听到你说: {user_input}

# 语音输出
self.speak(response)

if name == main:
chat = VoiceChat()
chat.conversation_loop()

3. 集成OpenClaw TTS

python def openclawtts(text, outputfile=output.mp3): 调用OpenClaw TTS工具 import subprocess import json

# 创建临时文件
with tempfile.NamedTemporaryFile(mode=w, suffix=.json, delete=False) as f:
tts_request = {
text: text,
channel: webchat
}
json.dump(tts_request, f)
request_file = f.name

try:
# 调用tts工具(需要OpenClaw环境)
result = subprocess.run([
node, path/to/openclaw/tts-tool.js,
--input, request_file,
--output, output_file
], capture_output=True, text=True)

if result.returncode == 0:
print(f✅ 语音文件已生成: {output_file})
# 播放音频
subprocess.run([start, output_file], shell=True)
else:
print(f❌ TTS失败: {result.stderr})
finally:
os.unlink(request_file)

高级配置

使用Whisper进行本地STT

python def whisperstt(audiofile): 使用Whisper进行语音识别 import whisper

model = whisper.load_model(base)
result = model.transcribe(audio_file, language=zh)
return result[text]

使用ElevenLabs高质量TTS

python def elevenlabstts(text, voiceid=21m00Tcm4TlvDq8ikWAM, api_key=None): 使用ElevenLabs TTS import requests

url = fhttps://api.elevenlabs.io/v1/text-to-speech/{voice_id}
headers = {
xi-api-key: apikey or os.environ.get(ELEVENLABSAPI_KEY),
Content-Type: application/json
}

data = {
text: text,
modelid: elevenmultilingual_v2,
voice_settings: {
stability: 0.5,
similarity_boost: 0.5
}
}

response = requests.post(url, json=data, headers=headers)
if response.status_code == 200:
with open(output.mp3, wb) as f:
f.write(response.content)
return output.mp3
else:
raise Exception(fElevenLabs TTS失败: {response.text})

故障排除

常见问题

  1. 1. 麦克风无法识别
- 检查麦克风权限 - 尝试指定麦克风设备索引
  1. 2. pyaudio安装失败
- Windows: 使用pipwin install pyaudio - macOS: brew install portaudio
  1. 3. 语音识别准确率低
- 调整环境噪音 - 使用更准确的模型(Whisper large) - 添加语音训练

性能优化

  1. 1. 缓存模型:预加载Whisper模型
  2. 流式处理:实时语音处理
  3. 降噪处理:改善语音质量

安全注意事项

  1. 1. API密钥保护:不要硬编码API密钥
  2. 隐私保护:语音数据本地处理
  3. 权限管理:麦克风访问权限控制

扩展功能

计划中的功能

  1. 1. 多语言支持:自动检测语言
  2. 语音命令:特定语音指令识别
  3. 情绪识别:从语音中识别情绪
  4. 实时翻译:跨语言语音对话

技能版本: 1.0.0 最后更新: 2026-02-28

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 voice-chat-skill-1776285614 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 voice-chat-skill-1776285614 技能

通过命令行安装

skillhub install voice-chat-skill-1776285614

下载

⬇ 下载 voice-chat v1.0.0(免费)

文件大小: 19.59 KB | 发布时间: 2026-4-16 17:28

v1.0.0 最新 2026-4-16 17:28
voice-chat-skill v1.0.0

- Initial release of voice-chat skill, enabling bi-directional voice conversation.
- Supports speech-to-text (STT) using speech_recognition (Google, Whisper, etc.).
- Supports text-to-speech (TTS) through OpenClaw built-in tools and optional ElevenLabs API.
- Maintains conversation context and includes voice activity detection.
- Includes robust setup instructions, advanced configuration options, troubleshooting, and security guidelines.
返回顶部