voice-mcp
Transcribe voice messages to text and generate spoken audio from text, served as cached Ogg/Opus files for instant playback.
README
voice-mcp
Speech-to-text and text-to-speech as one small service, exposed over both an MCP (streamable-HTTP) interface and a plain REST interface.
- STT — faster-whisper on CPU (int8). Transcribe voice messages (ogg/opus, mp3, wav, m4a…) to text.
- TTS — Vietnamese speech via gTTS,
with an optional Google Cloud TTS fallback. Server-side ffmpeg transcodes the
mp3 to Ogg/Opus (
libopus, 48 kbit/s) so the clip renders as a native Telegram voice bubble. Returns a URL to a cached.ogg, never a base64 blob. No bot needs ffmpeg — it is baked into the image.
This is the packaged evolution of the original single-file whisper-mcp (STT
only); the STT behaviour and API are kept 100% backward-compatible.
About
voice-mcp gives AI agents (Claude Code, chat bots, automation) a single, self-hosted voice endpoint: send audio, get text back; send text, get a shareable voice clip back. It runs on a modest CPU VPS, keeps audio on your own infrastructure (nothing is sent to a third-party STT/TTS service beyond the optional cloud-TTS fallback you opt into), and exposes the same two capabilities over both MCP and REST so any tool can consume it. Built for Vietnamese first (Whisper + gTTS), usable for any language Whisper/gTTS support.
Interfaces
| Route | Auth | Description |
|---|---|---|
POST /mcp (MCP streamable-HTTP) |
Bearer | tools: transcribe, speak |
POST /transcribe {audio_base64, language} |
Bearer | → {text, language} |
POST /speak {text, lang} |
Bearer | → {url, cached, engine, format} |
GET /audio/<sha>.ogg |
none | serves a cached .ogg/.mp3 (opaque hashed name) |
GET /healthz |
none | liveness / model info |
MCP endpoint path is /mcp with no trailing slash.
speak (both the MCP tool and REST) returns a short URL string to an
.ogg (Ogg/Opus) clip, never base64 audio — a base64 blob in a tool result
would blow up the model's context window. The file is served by
GET /audio/<sha>.ogg with Content-Type: audio/ogg (the same route also
serves the intermediate .mp3 as audio/mpeg).
Run
Prebuilt image (GHCR)
docker run -d --name voice-mcp \
-p 127.0.0.1:8767:8767 \
-e MCP_TOKEN=your-secret \
-e WHISPER_MODEL=small \
-e PUBLIC_BASE_URL=https://whisper.veasy.vn \
-v voice-models:/models \
-v voice-audio:/audio \
--memory 1200m --cpus 2 \
ghcr.io/<owner>/voice-mcp:latest
Build locally
docker build -t voice-mcp .
# or, without Docker:
pip install -e ".[dev]"
MCP_TOKEN=dev PUBLIC_BASE_URL=http://localhost:8767 voice-mcp
Config (env)
See .env.example: MCP_TOKEN, WHISPER_MODEL, AUDIO_DIR,
PUBLIC_BASE_URL, and the optional GOOGLE_APPLICATION_CREDENTIALS.
Model sizing
CPU int8, rough footprint / accuracy trade-off:
| Model | RAM (approx) | Notes |
|---|---|---|
tiny / base |
~0.3–0.5 GB | fastest, lower accuracy |
small |
~0.7–1 GB | default — good VN accuracy / speed balance |
medium |
~2–3 GB | better accuracy, heavier |
large-v3 |
~4–5 GB | best accuracy, needs plenty of RAM |
Cap the container (e.g. --memory 1200m --cpus 2) on small hosts so it can't OOM
the box; small fits comfortably.
TTS engine rationale
The provider chain lives in src/voice_mcp/tts.py:
- gTTS (Google Translate TTS,
lang="vi") — primary, free, no credentials, outputs mp3. - Google Cloud TTS (voice
vi-VN-Wavenet-A, female) — fallback, only used when gTTS raises (e.g. HTTP 429). RequiresGOOGLE_APPLICATION_CREDENTIALS; skipped entirely when unset.
Deliberately not used (do not re-add):
- Piper — voice quality rejected.
- edge-tts — Microsoft blocks datacenter IPs (403 from the VPS).
The mp3 is then transcoded to Ogg/Opus by ffmpeg
(ffmpeg -y -loglevel error -i in.mp3 -c:a libopus -b:a 48k out.ogg), baked
into the image. Both the .mp3 (kept for the chain) and the returned .ogg are
cached content-addressed by sha256(text + lang + engine) in AUDIO_DIR, so
repeated requests return the .ogg instantly without re-running gTTS or ffmpeg.
Serving audio
The app serves GET /audio/<file> itself (streams the .ogg/.mp3 with the
matching Content-Type, no auth — the filename is an opaque hash), so no extra
web-server config is required. For efficiency you can instead let nginx serve
AUDIO_DIR directly:
location /audio/ {
alias /path/to/audio/;
add_header Cache-Control "public, max-age=31536000, immutable";
}
Speech-to-speech helper pattern
Chain the two tools for a voice-in → voice-out loop:
text = transcribe(audio_base64=clip_b64, language="vi") # STT
reply = my_llm(text) # your logic
url = speak(text=reply, lang="vi") # TTS -> Ogg/Opus URL
# download `url` (an .ogg) and send it back as a Telegram voice message
Development
pip install -e ".[dev]"
ruff check .
pytest # pure-logic tests (cache keying, config parsing) — no network/models
Contributing
Contributions are welcome. See CONTRIBUTING.md for the dev setup,
the ruff + pytest checks to run before a PR, and the design principles (two APIs /
never return bulk audio inline / engines as a fallback chain).
License
MIT © Edward Nguyen
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。