Voice Assistant MCP Demo

Voice Assistant MCP Demo

A cloud backend for a voice assistant that processes natural language commands, manages tasks, and provides speech responses. Integrates with MCP protocol and Gemini API for Vietnamese language support.

Category
访问服务器

README

Voice Assistant MCP Demo — Phase 1: Cloud Backend

Ba service Python chạy độc lập, kết nối qua URL env vars.

api_server  →  mcp_server  →  gateway  ←  Android app / curl

Chạy local (test Phase 1)

pip install -r requirements.txt
cp .env.example .env        # điền GEMINI_API_KEY và GATEWAY_SHARED_TOKEN

# Terminal 1
python api_server.py        # :8000

# Terminal 2
python mcp_server.py        # :8001  (MCP_BASE_URL=http://localhost:8000 đã có trong .env)

# Terminal 3
python gateway.py           # :8002

Test bằng curl:

# Không có auth token (để trống GATEWAY_SHARED_TOKEN trong .env khi test local)
curl -X POST http://localhost:8002/command \
  -H "Content-Type: application/json" \
  -d '{"text": "việc hôm nay có gì", "session_id": "test-1"}'

# Kết quả mong đợi:
# {"speech": "Hôm nay bạn có 4 việc, trong đó 3 việc chưa xong...", "session_id": "test-1"}

# Multi-turn — follow-up cùng session
curl -X POST http://localhost:8002/command \
  -H "Content-Type: application/json" \
  -d '{"text": "đánh dấu xong việc gọi khách hàng", "session_id": "test-1"}'

Deploy lên Render (3 service riêng)

Bước 1 — Push repo lên GitHub

git init && git add . && git commit -m "init phase 1"
git remote add origin <your-github-repo-url>
git push -u origin main

Bước 2 — Tạo Service 1: API Server

  • Render Dashboard → New → Web Service → chọn repo
  • Name: task-api
  • Build Command: pip install -r requirements.txt
  • Start Command: python api_server.py
  • Environment Variables:
    • PORT → để Render tự điền

Sau khi deploy xong, copy URL dạng https://task-api-xxxx.onrender.com.

Bước 3 — Tạo Service 2: MCP Server

  • Name: task-mcp
  • Start Command: python mcp_server.py
  • Environment Variables:
    • API_BASE_URL → URL của Service 1 (bước 2)

Sau khi deploy, copy URL: https://task-mcp-xxxx.onrender.com.

Bước 4 — Tạo Service 3: Gateway

  • Name: task-gateway
  • Start Command: python gateway.py
  • Environment Variables:
    • MCP_BASE_URL → URL của Service 2 (bước 3)
    • GEMINI_API_KEY → key từ Google AI Studio
    • GATEWAY_SHARED_TOKEN → chuỗi ngẫu nhiên (dùng openssl rand -hex 16)

Bước 5 — Test end-to-end trên cloud

GATEWAY_URL=https://task-gateway-xxxx.onrender.com
TOKEN=your_shared_token

curl -X POST $GATEWAY_URL/command \
  -H "Content-Type: application/json" \
  -H "X-Auth-Token: $TOKEN" \
  -d '{"text": "việc hôm nay có gì", "session_id": "s1"}'

Lưu ý cold-start: Render free tier ngủ sau 15 phút idle. Request đầu tiên mất ~30s. Chấp nhận được cho demo.


Biến môi trường tổng hợp

Service Biến Bắt buộc Ghi chú
api_server PORT auto Render tự set
mcp_server PORT auto
mcp_server API_BASE_URL URL của api_server
gateway PORT auto
gateway MCP_BASE_URL URL của mcp_server
gateway GEMINI_API_KEY Google AI Studio
gateway GATEWAY_SHARED_TOKEN khuyến nghị Bảo vệ endpoint public

Cấu trúc request/response gateway

POST /command

Headers: X-Auth-Token: <token> (nếu có GATEWAY_SHARED_TOKEN)

Body:

{
  "text": "lệnh giọng nói đã chuyển thành text",
  "session_id": "uuid-từ-app"
}

Response:

{
  "speech": "Câu trả lời tiếng Việt tự nhiên để đọc lên",
  "session_id": "uuid-từ-app"
}

Session tự reset sau 30 phút không có request.


Mốc Phase 1 ✓

curl POST /command {"text": "việc hôm nay có gì"}
→ {"speech": "Hôm nay bạn có ..."}

Phase 2 — Android App (Push-to-Talk)

Cấu trúc

android/
├── app/src/main/java/com/demo/voiceassistant/
│   ├── Config.kt           ← URL gateway + auth token
│   ├── MainActivity.kt     ← 1 nút "Nói", quản lý luồng
│   ├── SpeechController.kt ← STT vi-VN (SpeechRecognizer)
│   ├── ApiClient.kt        ← POST /command qua OkHttp
│   └── SpeakController.kt  ← TTS đọc kết quả
└── app/src/main/res/
    └── layout/activity_main.xml

Mở trong Android Studio

  1. File → Open → chọn thư mục android/
  2. Android Studio tự tải Gradle và sync dependencies
  3. Cắm máy thật (hoặc bật AVD) → Run

Nếu dùng máy ảo (AVD): chọn image có Google Play để SpeechRecognizer hoạt động với vi-VN.

Luồng hoạt động Phase 2

Bấm nút "Nói"
  → SpeechRecognizer (vi-VN) nghe ~5 giây
  → text → POST https://task-gateway-0le7.onrender.com/command
             header: X-Auth-Token: <token>
  → {"speech": "..."} → TextToSpeech đọc lên

Lưu ý cold-start: Request đầu tiên sau 15 phút idle mất ~30s (Render free tier). Timeout của ApiClient đã set 90s.

Đổi gateway / token

Sửa android/app/src/main/java/com/demo/voiceassistant/Config.kt:

object Config {
    const val GATEWAY_URL = "https://task-gateway-xxxx.onrender.com"
    const val AUTH_TOKEN  = "your_token_here"
}

Mốc Phase 2 ✓

Bấm nút → nói "việc hôm nay có gì" → app đọc lại danh sách bằng giọng tiếng Việt.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选