OpenRouter Voice MCP
Turns text into local audio files (MP3) via OpenRouter speech models, enabling AI coding agents to generate voiceover narrations for video production.
README
OpenRouter Voice MCP
A small MCP server (Python + FastMCP, stdio) that turns text into local audio files using OpenRouter speech models. Default model:
fish-audio/s2.1-pro-free:free
Built for Vietnamese video voiceover: Codex or Claude Code writes a narration
script, calls render_voiceover(), and gets back an absolute path to an MP3 it
can hand straight to FFmpeg.
Codex / Claude Code
| MCP stdio
OpenRouter Voice MCP
| HTTPS
OpenRouter -> fish-audio/s2.1-pro-free:free
|
MP3 bytes -> local file -> FFmpeg / video pipeline
No PyTorch, CUDA, local model downloads, local LLM, or local HTTP port. Just Python, three pure-Python packages and an OpenRouter API key.
Install
Requirements: Python >= 3.10 on PATH, plus ffmpeg if you want
render_long_voiceover() to concatenate segments. Get a free API key at
https://openrouter.ai/keys.
One command does everything -- venv, dependencies, .env, acceptance tests, and
registration with both Claude Code and Codex:
git clone https://github.com/Trandu1/mcp_voice.git D:\VoiceAI\openrouter-voice-mcp
cd D:\VoiceAI\openrouter-voice-mcp
.\install.ps1 -ApiKey "sk-or-v1-..." -Register
Manual equivalent, if you would rather see each step:
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements.txt
copy .env.example .env # then set OPENROUTER_API_KEY=sk-or-v1-...
.\.venv\Scripts\python.exe tests\acceptance.py
On macOS / Linux there is no install.ps1; use the manual steps with
python3 -m venv .venv and .venv/bin/python, then register as shown below.
Register with Claude Code
claude mcp add openrouter-voice --scope user -- `
D:\VoiceAI\openrouter-voice-mcp\.venv\Scripts\python.exe `
D:\VoiceAI\openrouter-voice-mcp\server.py
claude mcp get openrouter-voice # expect: Connected
Register with Codex
codex mcp add openrouter-voice -- `
D:\VoiceAI\openrouter-voice-mcp\.venv\Scripts\python.exe `
D:\VoiceAI\openrouter-voice-mcp\server.py
codex mcp list # expect: openrouter-voice
The API key is read from .env next to server.py, so it never appears on a
command line or in either CLI's config file. You can also export
OPENROUTER_API_KEY in the environment instead — an exported value wins over
.env.
Tools
| Tool | What it does |
|---|---|
health() |
Config + key status. Free auth probe only, never renders audio. |
render_voiceover(...) |
The main tool. Text -> local audio file. |
render_long_voiceover(...) |
Splits a long script into segments, renders each, concatenates with FFmpeg when available. |
preview_voice(text, voice) |
Short sample, written to <output_dir>/previews and opened in the default player. |
list_speech_models() |
Every OpenRouter model with output_modalities: speech (id, name, pricing). |
model_info(model) |
Live provider / tier / pricing / voice-cloning support for one model. |
render_voiceover
render_voiceover(
text: str,
output_path: str = "", # absolute or relative; parents are created
voice: str = "", # empty = model default (correct for Fish Audio)
response_format: str = "", # "mp3" (default) or "pcm"
instructions: str = "", # only sent to providers that document it
overwrite: bool = False, # False never clobbers an existing file
reference_audio_path: str = "", # optional stateless voice cloning
reference_text: str = "",
)
Returns:
{
"status": "ok",
"model": "fish-audio/s2.1-pro-free:free",
"audio_path": "D:\\campaigns\\abc\\audio\\narration.mp3",
"format": "mp3",
"content_type": "audio/mpeg",
"bytes": 123456,
"elapsed_seconds": 2.31,
"duration_seconds": 12.4,
"generation_id": "gen-..."
}
Audio bytes are written to disk and never returned base64-encoded through MCP — the point is a real file for FFmpeg.
Configuration
All settings are environment variables (see .env.example):
| Variable | Default | Notes |
|---|---|---|
OPENROUTER_API_KEY |
— | Required. Never logged or returned. |
OPENROUTER_VOICE_MODEL |
fish-audio/s2.1-pro-free:free |
|
OPENROUTER_VOICE |
empty | Fish Audio documents no preset voice ids; leave empty. |
OPENROUTER_AUDIO_FORMAT |
mp3 |
mp3 or pcm. |
OPENROUTER_TIMEOUT_SECONDS |
120 |
|
OPENROUTER_HTTP_REFERER |
empty | Sent only when set. |
OPENROUTER_APP_TITLE |
OpenRouter Voice MCP |
Sent as X-OpenRouter-Title. |
VOICE_OUTPUT_DIR |
%USERPROFILE%\OpenRouterVoice\output |
Used when the caller passes no output_path. |
OPENROUTER_VOICE_FALLBACK_MODEL |
empty | Leave empty. Only set it if you accept being billed for a paid model when the free one is down. |
What the API actually supports
Verified against the live OpenRouter Speech API and Models API (2026-08-25), not inferred from the older OpenAI TTS API:
- Endpoint
POST https://openrouter.ai/api/v1/audio/speechreturns a raw audio byte stream. Only non-200 responses carry JSON. - Top-level fields:
model,input,voice,response_format,speed,input_references,provider. response_formatismp3orpcm. The API defaults topcm, so this server always sends the format explicitly.instructionsis not a top-level field. It is an OpenAI provider option (provider.options.openai.instructions). Fish Audio documents no provider options, soinstructionsis dropped for Fish models and reported back inwarnings— no invented fields are ever sent.speedis only honoured by some providers (OpenAI, Azure); it is dropped elsewhere rather than silently ignored server-side.- Fish Audio has no preset voice ids (
alloy/nova/shimmerbelong to OpenAI). Leavevoiceempty. - Voice cloning is available: the endpoints API reports
supports_voice_cloning: trueforfish-audio/s2.1-pro-free:free. It is stateless — you pass a base64 audio sample ininput_referenceson every request. There is no persistentvoice_idto create, so this server has noclone_voicetool; usereference_audio_pathonrender_voiceoverinstead. - Attribution headers are
HTTP-RefererandX-OpenRouter-Title.
Free-model limits
fish-audio/s2.1-pro-free:free is a free variant:
- 20 requests/minute, 50 requests/day (1000/day once ≥ $10 of credit has been purchased on the account).
- Availability, queueing and latency are not guaranteed.
- When the free model is unavailable the server returns a clear error. It
never switches to a paid model unless you explicitly set
OPENROUTER_VOICE_FALLBACK_MODEL.
Transient failures (408, 429, 5xx, network errors) are retried twice with short exponential backoff. 400/401/403 are never retried.
Tests
.\.venv\Scripts\python.exe -m pytest tests -q --asyncio-mode=auto # unit, mocked HTTP
.\.venv\Scripts\python.exe tests\smoke_test.py # live, needs a key
.\.venv\Scripts\python.exe tests\acceptance.py # full checklist
smoke_test.py and the live half of acceptance.py skip cleanly without a key.
A skip is reported as SKIP, never as PASS.
Security
- The API key lives in
.env(git-ignored) or the environment. It is never logged, never written to a command line, and never returned through MCP. health()andmodel_info()return configuration, never credentials.- The server speaks stdio only and binds no TCP port.
- It executes no shell commands from tool input. FFmpeg/ffprobe are invoked only on files this server just wrote, and only when present.
- File writes go exactly where the caller asks (Codex needs to write into
arbitrary campaign directories), but directories, invalid Windows filenames and
reserved device names are rejected, and
overwrite=Falsenever clobbers.
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。