语音AGI MCP服务器
结合本地STT/TTS和Letta风格会话管理的有状态语音控制AGI系统
概述
Voice AGI是一种高级MCP服务器,提供:
- 有状态的对话 -具有上下文保留功能的多回合对话
- 语音过程中的工具执行 -呼叫AGI通过语音自然运行
- 本地STT/TTS -经济高效的Whisper+Edge TTS(无API成本)
- 意图检测 -使用当地Ollama的先进NLU
- AGI集成 -直接控制目标、任务、记忆和研究
- 延迟跟踪 -优化性能指标
建筑
User Voice → Voice Pipeline (STT) → Intent Detector (Ollama)
↓
Tool Registry
↓
┌──────────────────────┼──────────────────────┐
↓ ↓ ↓
Conversation Manager Enhanced Memory MCP Agent Runtime MCP
│ │ │
└──────────────────────┴──────────────────────┘
↓
AGI Orchestrator特性
🎯 有状态的对话管理
- 上下文保留 跨越多个转弯(最后10个转弯)
- 用户上下文 跟踪(姓名、偏好等)
- 对话历史 存储在增强型存储器中
- 无缝多回合对话 (“我刚才问的是什么?”)
🔧 语音可调用AGI工具
search_agi_memory-通过语音搜索过去的记忆create_goal_from_voice-“创建优化内存的目标”list_pending_tasks-“我有什么任务?”trigger_consolidation-“运行内存整合”start_research-“研究变压器架构”check_system_status-“系统运行得怎么样?”remember_name/recall_name-用户上下文管理start_improvement_cycle-“提高整合速度”decompose_goal-“将此目标分解为任务”- 总共10+个工具,易于扩展
🧠 意图检测
- 当地Ollama LLM (llama3.2)用于复杂的NLU
- 意图分类 -自动路由到适当的工具
- 参数提取 -从自然语音中提取参数
- 上下文感知 -使用对话历史记录以更好地理解
- 回退启发式 -即使Ollama不在,也能正常工作
🎤 语音管道
- 语音转文字:pywhispercpp(本地,兼容Python 3.14)
- 文本转语音:微软Edge TTS(免费神经语音)
- 音频反馈:状态更改提示音
- 延迟跟踪:STT、TTS和总往返度量
- 灵活的:以后可以轻松添加云STT/TTS
📊 性能指标
- STT延迟 跟踪(ms)
- TTS延迟 跟踪(ms)
- 往返总次数 延迟
- 对话统计 (转弯、单词、持续时间)
- 工具调用 计数
安装
1.安装依赖项
cd /mnt/agentic-system/mcp-servers/voice-agi-mcp
pip install -r requirements.txt2.确保先决条件
必需:
- Python 3.10+
edge-tts(通过requirements.txt安装)arecord(也是实用工具):sudo dnf install alsa-utils- 音频播放器:
mpg123,ffplay,或vlc - 奥利玛与骆驼3.2:
ollama pull llama3.2
可选(适用于短期租约):
pywhispercpp:已在requirements.txt中- 麦克风接入
3.在Claude代码中配置
添加 ~/.claude.json:
{
"mcpServers": {
"voice-agi": {
"command": "python3",
"args": ["/mnt/agentic-system/mcp-servers/voice-agi-mcp/src/server.py"],
"disabled": false
}
}
}4.重新启动克劳德代码
# Restart Claude Code to load the new MCP server用法
基本语音聊天
# From Claude Code, use the voice_chat tool:
result = voice_chat(text="Create a goal to optimize memory consolidation")
# Output:
# {
# 'response': '[Tool executed: create_goal]',
# 'tool_used': 'create_goal_from_voice',
# 'tool_result': {'goal_id': 'goal_123', ...},
# 'conversation_turns': 1
# }语音对话循环
# Start interactive voice conversation:
result = voice_conversation_loop(max_turns=10)
# System will:
# 1. Greet you
# 2. Listen for your speech
# 3. Process intent and execute tools
# 4. Respond naturally
# 5. Continue until you say "goodbye" or max_turns reached只听
# Just transcribe speech:
result = voice_listen(duration=5)
# Returns: {'text': 'transcribed speech', 'success': True}只说话
# Just speak text:
result = voice_speak(text="Hello, this is your AGI assistant")
# Returns: {'success': True, 'audio_file': '/tmp/...'}获取对话上下文
# View conversation history:
context = get_conversation_context()
# Returns:
# {
# 'context': 'User: ...\nAssistant: ...',
# 'summary': {'session_id': '...', 'total_turns': 5},
# 'stats': {'total_user_words': 50, ...},
# 'user_context': {'name': 'Marc'}
# }列出语音工具
# See all registered voice-callable tools:
tools = list_voice_tools()
# Returns: {'tools': [...], 'count': 10}获取性能统计数据
# View latency and performance metrics:
stats = get_voice_stats()
# Returns:
# {
# 'latency': {'avg_stt_ms': 800, 'avg_tts_ms': 1500, ...},
# 'stt_available': True,
# 'tts_available': True,
# 'conversation_stats': {...},
# 'registered_tools': 10
# }语音通话工具
当在用户语音中检测到意图时,会自动调用工具。
存储器操作
搜索内存:
User: "Search for information about transformers"
System: [Searches enhanced-memory and speaks results]记住用户信息:
User: "My name is Marc"
System: "Got it, I'll remember your name is Marc"
...
User: "What is my name?"
System: "Your name is Marc"目标与任务管理
创建目标:
User: "Create a goal to optimize memory consolidation"
System: "Goal created with ID goal_1732345678"列出任务:
User: "What tasks do I have?"
System: "You have 2 tasks. Task 1: Example task 1, Task 2: ..."分解目标:
User: "Break down the optimization goal into tasks"
System: "Created 5 tasks from your goal"AGI运营
记忆巩固:
User: "Run memory consolidation"
System: "Starting memory consolidation. This may take a moment."
[After processing]
System: "Consolidation complete. Found 5 patterns."自主研究:
User: "Research transformer attention mechanisms"
System: "Starting research on transformer attention mechanisms. I'll notify you when complete."自我完善:
User: "Improve consolidation speed"
System: "Starting self-improvement cycle for consolidation speed"系统状态:
User: "How is the system doing?"
System: "System is operational. 12 agents active."扩展系统
添加新的语音通话工具
在 src/server.py:
@tool_registry.register(
intents=["your", "trigger", "keywords"],
description="What your tool does",
priority=8 # Higher = matched first
)
async def my_custom_tool(param: str) -> Dict[str, Any]:
"""Tool implementation"""
try:
# Your logic here
result = do_something(param)
# Speak response
await voice_pipeline.synthesize_speech(
f"Completed: {result}",
play_audio=True
)
return result
except Exception as e:
logger.error(f"Error: {e}")
return {'error': str(e)}自定义意图检测
编辑 src/intent_detector.py 致:
- 添加新的意图类别
- 调整LLM提示
- 调整置信阈值
- 添加特定于域的NLU
与其他MCP服务器集成
编辑 src/mcp_integrations.py 致:
- 添加新的MCP客户端类
- 实现实际的API调用(当前已存根)
- 配置MCP服务器URL
演出
在Mac Pro 5.1上测量 (双至强X5680,24线程):
| 操作 | 延迟 |
|---|---|
| STT(基本型号) | ~800ms |
| TTS(边缘) | ~1500ms |
| 意图检测 | ~500ms |
| 总往返时间 | ~2.8秒 |
优化技巧:
- 使用较小的Whisper型号(
tiny)更快的STT - 启动时预装Whisper型号
- 如果GPU可用,请使用GPU(系统上的GTX 680)
- 为延迟关键用例启用云STT/TTS
故障排除
Whisper不可用
# Install pywhispercpp
pip install pywhispercpp
# Test:
python3 -c "from pywhispercpp.model import Model; print('✓ Whisper available')"Edge TTS不工作
# Install edge-tts
pip install edge-tts
# Test:
edge-tts --list-voices | grep en-IEOllama没有回应
# Check Ollama is running
curl http://localhost:11434/api/generate -d '{"model":"llama3.2","prompt":"test"}'
# Pull model if needed
ollama pull llama3.2录音失败
# Install ALSA utils
sudo dnf install alsa-utils
# Test recording
arecord -D default -f cd -t wav -d 3 /tmp/test.wav
# List audio devices
arecord -l无音频输出
# Install audio player
sudo dnf install mpg123 ffmpeg
# Test playback
mpg123 /tmp/test.mp3建筑细部
对话流程
1. User speaks → 2. STT transcribes → 3. Intent detector analyzes
↓
4. Tool registry matches
↓
5. Tool executes
↓
6. Result spoken via TTS
↓
7. Turn stored in conversation有状态的上下文
对话管理器维护:
- 消息历史记录 (最后10圈)
- 用户上下文 (姓名、偏好)
- 会话元数据 (开始时间、转弯次数)
- 工具调用 (使用了哪些工具)
上下文会自动:
- 传递给意图检测器以获得更好的NLU
- 存储在增强型内存中,可长期保存
- 用于多回合理解
工具调用
在以下情况下调用工具:
- 意向信心>0.6
- 意图名称与注册的工具匹配
- 可以提取所需的参数
通过以下方式提取参数:
- 基于LLM的提取 (奥拉马)
- 模式匹配 (正则表达式)
- 会话上下文 (前几轮)
- 默认值 (如果在工具定义中指定)
与Letta Voice的比较
| 功能 | Letta Voice | 语音AGI(此) |
|---|---|---|
| 语音转文字 | Deepgram(云) | Whisper(本地) |
| 文本转语音 | Cartesia(云) | Edge TTS(本地) |
| 记忆 | Letta状态框架 | 增强内存MCP |
| 工具 | 功能调用 | 语音调用工具 |
| 成本 | 约620美元/月(8小时/天) | 约5美元/月 |
| 延迟 | ~700ms | ~2.8s(本地CPU) |
| 隐私 | ❌ 云数据 | ✅ 完全本地化 |
| AGI集成 | ❌ 无 | ✅ 深度集成 |
两全其美:该系统将Letta的有状态对话方法与您现有的本地基础设施相结合。
未来的增强功能
第4阶段:流媒体和VAD(计划中)
- 语音活动检测(silero-vad)
- 流式转录(连续缓冲区)
- 中断处理
- Whisper的GPU加速
第五阶段:云升级(可选)
- 自适应管道(基于上下文的本地与云)
- Deepgram STT集成
- Cartesia TTS集成
- Livekit用于实时流媒体
配置
环境变量
# Ollama configuration
OLLAMA_URL=http://localhost:11434
OLLAMA_MODEL=llama3.2
# Voice configuration
WHISPER_MODEL=base # tiny, base, small, medium, large
TTS_VOICE=en-IE-EmilyNeural
TTS_RATE=+0%
TTS_VOLUME=+0%
# MCP server URLs (for integrations)
ENHANCED_MEMORY_URL=http://localhost:3000
AGENT_RUNTIME_URL=http://localhost:3001
AGI_ORCHESTRATOR_URL=http://localhost:8000对话设置
在 src/server.py:
conversation_manager = ConversationManager(
max_turns=10, # Conversation history window
enable_memory=True # Store in enhanced-memory
)语音管道设置
voice_pipeline = VoicePipeline(
stt_model="base", # Whisper model size
tts_voice="en-IE-EmilyNeural", # TTS voice
enable_latency_tracking=True # Track metrics
)api参考
请参阅以下文件中的内联文档字符串:
src/server.py-主要MCP工具src/conversation_manager.py-会话管理src/voice_pipeline.py-STT/TTS运营src/tool_registry.py-工具注册src/intent_detector.py-意图检测src/mcp_integrations.py-MCP客户端接口
贡献
要添加新功能,请执行以下操作:
- 新的语音通话工具:添加到
src/server.py随着@tool_registry.register() - 增强的意图检测:更新
src/intent_detector.py - MCP集成:实施实际呼叫
src/mcp_integrations.py - 性能优化:添加VAD、流媒体、GPU加速
- 云提供商:添加Deepgram/Cartesia客户端
许可证
Mac Pro 5.1代理系统的一部分-请参阅主系统文档。
支持
对于问题或疑问:
- 检查日志:
journalctl -f | grep voice-agi - 单独测试组件(请参阅故障排除)
- 查阅AGI系统文档
/home/marc/
______________________________________________________________________
语音AGI v0.1.0 -递归自改进AGI系统的状态语音控制
