<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>VoxCPM2 — API & Crate Docs</title>
<style>
:root {
--bg: #0b0e14;
--surface: #131823;
--surface-2: #1a2130;
--surface-3: #222b3e;
--border: #263148;
--border-hi: #3a4c70;
--text: #f1f5f9;
--muted: #94a3b8;
--accent: #38bdf8;
--accent-bg: rgba(56, 189, 248, 0.13);
--ok: #34d399;
--amber: #fbbf24;
--purple: #c084fc;
--danger: #f87171;
--radius: 14px;
--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
--sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body {
margin: 0; background: var(--bg); color: var(--text);
font-family: var(--sans); font-size: 14.5px; line-height: 1.65;
}
.app { max-width: 1020px; margin: 0 auto; padding: 20px 20px 72px; }
.topbar {
display: flex; align-items: center; justify-content: space-between;
gap: 14px; flex-wrap: wrap; margin-bottom: 22px;
padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; }
.logo {
width: 38px; height: 38px; border-radius: 11px;
background: linear-gradient(135deg, #38bdf8, #818cf8);
display: grid; place-items: center;
font-weight: 800; font-size: 15px; color: #08101c;
}
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.status-inline { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--danger); }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn {
border: 1px solid var(--border-hi); background: var(--surface-2); color: var(--text);
padding: 8px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
text-decoration: none; transition: all 0.15s;
}
.btn:hover { background: var(--surface-3); border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, #38bdf8, #2563eb); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.lang-switch {
display: inline-flex; background: var(--surface); border: 1px solid var(--border);
border-radius: 999px; padding: 3px;
}
.lang-btn {
border: none; background: transparent; color: var(--muted);
padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.lang-btn.active { background: var(--surface-3); color: var(--text); }
.section-tabs {
display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px;
}
.sec-tab {
border: 1px solid var(--border); background: var(--surface); color: var(--muted);
padding: 9px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
cursor: pointer; transition: all 0.15s;
}
.sec-tab:hover { color: var(--text); border-color: var(--border-hi); }
.sec-tab.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.card {
background: var(--surface); border: 1px solid var(--border);
border-radius: var(--radius); padding: 20px 22px; margin-bottom: 16px;
}
h2 { margin: 0 0 10px; font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
h3 { margin: 18px 0 8px; font-size: 15px; font-weight: 700; color: #e2e8f0; }
p { margin: 0 0 10px; color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }
code {
font-family: var(--mono); font-size: 12.5px; background: var(--surface-2);
border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; color: #93c5fd;
}
.code-wrap { position: relative; margin: 10px 0 14px; }
pre {
margin: 0; background: #070a10; border: 1px solid var(--border);
border-radius: 10px; padding: 14px 16px; overflow-x: auto;
font-family: var(--mono); font-size: 12.5px; line-height: 1.55; color: #dbeafe;
}
.copy-btn {
position: absolute; top: 8px; right: 8px;
border: 1px solid var(--border-hi); background: var(--surface-2); color: var(--muted);
padding: 4px 9px; border-radius: 6px; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.copy-btn:hover { color: var(--text); border-color: var(--accent); }
.ep-list { display: flex; flex-direction: column; gap: 8px; }
.ep-row {
display: grid; grid-template-columns: 74px 270px 1fr; gap: 10px; align-items: center;
background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
@media (max-width: 720px) { .ep-row { grid-template-columns: 1fr; } }
.method {
font-family: var(--mono); font-size: 11.5px; font-weight: 700; text-align: center;
padding: 3px 8px; border-radius: 6px; width: fit-content;
}
.method.get { background: rgba(52, 211, 153, 0.14); color: var(--ok); border: 1px solid rgba(52, 211, 153, 0.35); }
.method.post { background: rgba(56, 189, 248, 0.14); color: var(--accent); border: 1px solid rgba(56, 189, 248, 0.35); }
.method.del { background: rgba(248, 113, 113, 0.14); color: var(--danger); border: 1px solid rgba(248, 113, 113, 0.35); }
.ep-path { font-family: var(--mono); font-size: 13px; color: var(--text); word-break: break-all; }
table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; background: var(--bg); }
td:first-child { font-family: var(--mono); color: #93c5fd; white-space: nowrap; }
td:nth-child(2) { font-family: var(--mono); color: var(--amber); white-space: nowrap; }
.try-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
select, textarea {
background: var(--bg); color: var(--text); border: 1px solid var(--border);
border-radius: 10px; padding: 9px 12px; font-family: var(--mono); font-size: 12.5px;
}
select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { width: 100%; min-height: 120px; resize: vertical; line-height: 1.5; }
.try-out {
background: #070a10; border: 1px solid var(--border); border-radius: 10px;
padding: 12px 14px; font-family: var(--mono); font-size: 12px;
max-height: 300px; overflow: auto; white-space: pre-wrap; color: #a7f3d0;
}
audio { width: 100%; margin-top: 8px; }
.arch-flow {
display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 10px; margin: 14px 0;
}
.arch-box {
background: var(--bg); border: 1px solid var(--border-hi); border-radius: 10px;
padding: 12px; display: flex; flex-direction: column; gap: 4px;
}
.arch-num { font-family: var(--mono); font-size: 11px; color: var(--accent); font-weight: 700; }
.arch-name { font-weight: 700; font-size: 13.5px; }
.arch-desc { font-size: 12px; color: var(--muted); }
.hidden { display: none !important; }
.toast {
position: fixed; bottom: 20px; right: 20px; z-index: 99;
background: var(--surface-3); border: 1px solid var(--ok); color: #a7f3d0;
padding: 9px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; display: none;
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<a class="brand" href="/">
<div class="logo">VX2</div>
<div>
<div class="brand-title">VoxCPM2 Docs</div>
<div class="status-inline">
<span id="statusDot" class="dot"></span>
<span id="statusText"></span>
</div>
</div>
</a>
<div class="top-actions">
<a class="btn sm" href="/">← <span data-i18n="backStudio"></span></a>
<div class="lang-switch" role="group" aria-label="Language">
<button type="button" class="lang-btn" data-lang="zh-CN">中文</button>
<button type="button" class="lang-btn" data-lang="en">EN</button>
</div>
</div>
</header>
<nav class="section-tabs" role="tablist">
<button type="button" class="sec-tab active" data-sec="api" data-i18n="tabApi"></button>
<button type="button" class="sec-tab" data-sec="crate" data-i18n="tabCrate"></button>
<button type="button" class="sec-tab" data-sec="cli" data-i18n="tabCli"></button>
<button type="button" class="sec-tab" data-sec="arch" data-i18n="tabArch"></button>
</nav>
<section id="secApi">
<div class="card">
<h2 data-i18n="apiEndpointsTitle"></h2>
<p data-i18n="apiEndpointsSub"></p>
<div class="ep-list">
<div class="ep-row"><span class="method get">GET</span><span class="ep-path">/health</span><span class="muted" data-i18n="epHealth"></span></div>
<div class="ep-row"><span class="method get">GET</span><span class="ep-path">/v1/presets</span><span class="muted" data-i18n="epPresets"></span></div>
<div class="ep-row"><span class="method get">GET</span><span class="ep-path">/v1/voices</span><span class="muted" data-i18n="epVoicesList"></span></div>
<div class="ep-row"><span class="method post">POST</span><span class="ep-path">/v1/voices</span><span class="muted" data-i18n="epVoicesSave"></span></div>
<div class="ep-row"><span class="method get">GET</span><span class="ep-path">/v1/voices/{name}</span><span class="muted" data-i18n="epVoiceGet"></span></div>
<div class="ep-row"><span class="method get">GET</span><span class="ep-path">/v1/voices/{name}/audio/{ref|prompt}</span><span class="muted" data-i18n="epVoiceAudio"></span></div>
<div class="ep-row"><span class="method del">DELETE</span><span class="ep-path">/v1/voices/{name}</span><span class="muted" data-i18n="epVoiceDel"></span></div>
<div class="ep-row"><span class="method post">POST</span><span class="ep-path">/v1/chunk-preview</span><span class="muted" data-i18n="epChunk"></span></div>
<div class="ep-row"><span class="method post">POST</span><span class="ep-path">/v1/tts</span><span class="muted" data-i18n="epTts"></span></div>
<div class="ep-row"><span class="method post">POST</span><span class="ep-path">/v1/tts/stream</span><span class="muted" data-i18n="epTtsStream"></span></div>
</div>
</div>
<div class="card">
<h2 data-i18n="tryTitle"></h2>
<p data-i18n="trySub"></p>
<div class="try-grid">
<div class="row">
<select id="tryPreset">
<option value="health">GET /health</option>
<option value="presets">GET /v1/presets</option>
<option value="voices">GET /v1/voices</option>
<option value="chunk">POST /v1/chunk-preview</option>
<option value="tts" selected>POST /v1/tts (WAV)</option>
</select>
<button type="button" class="btn primary sm" id="btnTryRun" data-i18n="btnSendReq"></button>
<span class="muted" id="tryMeta"></span>
</div>
<textarea id="tryBody"></textarea>
<div id="tryOutWrap" class="hidden">
<div class="try-out" id="tryOut"></div>
<audio id="tryAudio" controls class="hidden"></audio>
</div>
</div>
</div>
<div class="card">
<h2 data-i18n="schemaTitle"></h2>
<p data-i18n="schemaSub"></p>
<table>
<thead>
<tr><th data-i18n="thField"></th><th data-i18n="thType"></th><th data-i18n="thDesc"></th></tr>
</thead>
<tbody>
<tr><td>text</td><td>string (required)</td><td data-i18n="fText"></td></tr>
<tr><td>voice</td><td>string?</td><td data-i18n="fVoice"></td></tr>
<tr><td>preset</td><td>string?</td><td data-i18n="fPreset"></td></tr>
<tr><td>instruct</td><td>string?</td><td data-i18n="fInstruct"></td></tr>
<tr><td>speed</td><td>number (1.0)</td><td data-i18n="fSpeed"></td></tr>
<tr><td>preservePitch</td><td>boolean (true)</td><td data-i18n="fPreservePitch"></td></tr>
<tr><td>pitchSemitones</td><td>number (0.0)</td><td data-i18n="fPitch"></td></tr>
<tr><td>refAudioWavBase64</td><td>string?</td><td data-i18n="fRefAudio"></td></tr>
<tr><td>promptAudioWavBase64</td><td>string?</td><td data-i18n="fPromptAudio"></td></tr>
<tr><td>promptText</td><td>string?</td><td data-i18n="fPromptText"></td></tr>
<tr><td>steps / cfg / temperature</td><td>10 / 2.0 / 1.0</td><td data-i18n="fSampling"></td></tr>
<tr><td>seed</td><td>u64?</td><td data-i18n="fSeed"></td></tr>
<tr><td>autoChunk / chunkMaxUnits</td><td>true / 180</td><td data-i18n="fChunk"></td></tr>
</tbody>
</table>
<h3 data-i18n="curlTitle"></h3>
<div class="code-wrap">
<button type="button" class="copy-btn" data-copy="codeCurl"></button>
<pre id="codeCurl">curl -X POST http://127.0.0.1:8080/v1/tts \
-H 'Content-Type: application/json' \
-d '{
"text": "你好!这是通过 HTTP API 调用的 Apple Silicon MLX 1.2 倍速原音调语音。",
"preset": "podcast-male",
"speed": 1.2,
"preservePitch": true,
"seed": 42
}' \
--output speech.wav</pre>
</div>
<h3 data-i18n="streamCurlTitle"></h3>
<div class="code-wrap">
<button type="button" class="copy-btn" data-copy="codeStreamCurl"></button>
<pre id="codeStreamCurl"># Raw 48 kHz mono 16-bit signed little-endian PCM stream (audio/pcm)
curl -N -X POST http://127.0.0.1:8080/v1/tts/stream \
-H 'Content-Type: application/json' \
-d '{"text":"流式低延迟输出测试,首音延迟约 220 毫秒。","speed":1.2}' \
--output stream_48k_s16le.pcm</pre>
</div>
</div>
</section>
<section id="secCrate" class="hidden">
<div class="card">
<h2 data-i18n="crateTitle"></h2>
<p data-i18n="crateSub"></p>
<h3>1. Cargo.toml</h3>
<div class="code-wrap">
<button type="button" class="copy-btn" data-copy="codeCargo"></button>
<pre id="codeCargo">[dependencies]
voxcpm-rs-core = "0.1"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }</pre>
</div>
<h3 data-i18n="crateEx1"></h3>
<div class="code-wrap">
<button type="button" class="copy-btn" data-copy="codeRustBasic"></button>
<pre id="codeRustBasic">use voxcpm_rs_core::{
DEFAULT_QUEUE_CAPACITY, InferenceEngine, SynthesisRequest,
audio::write_wav_pcm16,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Pins MLX Metal GPU execution to a dedicated OS thread
let handle = InferenceEngine::spawn("8bit", DEFAULT_QUEUE_CAPACITY).await?;
let engine = handle.engine();
let req = SynthesisRequest::builder()
.text("你好!这是第三方 Rust 程序直接调用的 VoxCPM2 MLX 引擎。")
.speed(1.2)
.preserve_pitch(true) // Apple native AUNewTimePitch (iMovie-grade)
.seed(42)
.build()
.with_preset("podcast-male")?;
let (pcm, stats) = engine.synthesize(req).await?;
write_wav_pcm16("output.wav", &pcm, stats.sample_rate)?;
handle.shutdown().await;
Ok(())
}</pre>
</div>
<h3 data-i18n="crateEx2"></h3>
<div class="code-wrap">
<button type="button" class="copy-btn" data-copy="codeRustStream"></button>
<pre id="codeRustStream">use voxcpm_rs_core::{
DEFAULT_QUEUE_CAPACITY, InferenceEngine, StreamEvent,
SynthesisRequest, VoiceName, VoiceStore,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let handle = InferenceEngine::spawn("8bit", DEFAULT_QUEUE_CAPACITY).await?;
let engine = handle.engine();
// Reuse any voice cloned in WebUI or CLI (~/.voxcpm/voices)
let store = VoiceStore::open(VoiceStore::default_dir())?;
let voice = VoiceName::parse("tyr")?;
let req = SynthesisRequest::builder()
.text("低延迟流式合成,实时收到 48kHz PCM 音频块。")
.speed(1.2)
.build()
.with_saved_voice(&store, &voice)?;
let mut rx = engine.synthesize_stream(req, 16).await?;
while let Some(ev) = rx.recv().await {
match ev {
StreamEvent::Chunk(chunk) => {
// Feed chunk.samples (48 kHz mono f32) to CoreAudio / WebRTC / HTTP
println!("chunk #{}: {} samples", chunk.chunk_index, chunk.samples.len());
}
StreamEvent::Done(stats) => {
println!("done: {:.2}s audio, RTF={:.3}", stats.audio_duration_secs, stats.rtf);
}
StreamEvent::Error(e) => return Err(e.into()),
}
}
handle.shutdown().await;
Ok(())
}</pre>
</div>
</div>
</section>
<section id="secCli" class="hidden">
<div class="card">
<h2 data-i18n="cliTitle"></h2>
<p data-i18n="cliSub"></p>
<div class="code-wrap">
<button type="button" class="copy-btn" data-copy="codeCliRef"></button>
<pre id="codeCliRef"># 1. Start the Studio WebUI (/), interactive docs (/docs), and HTTP streaming API
voxcpm serve --bind 127.0.0.1:8080
# 2. Speak with real-time playback at 1.2x (Apple AUNewTimePitch Preserve Pitch ON by default)
voxcpm speak "你好世界,这是一点二倍速原音调测试。" --preset podcast-male -s 1.2 --play -o out.wav
# 3. Use a saved cloned voice from ~/.voxcpm/voices (shared with WebUI)
voxcpm voice list
voxcpm speak "用我自己克隆的声音朗读。" --voice tyr -s 1.2 --play
# 4. Save a new cloned voice from CLI (immediately shows up in WebUI too)
voxcpm voice save my_voice --prompt-audio sample.wav --prompt-text "录音里的原话。" --description "我的声音"
# 5. Direct one-shot cloning without saving
voxcpm speak "测试快速声音克隆。" --ref-audio sample.wav -o cloned.wav
# 6. Inspect built-in presets, voice details, or pre-download models
voxcpm presets
voxcpm voice show tyr
voxcpm download 8bit # or 4bit / bf16
voxcpm info</pre>
</div>
</div>
</section>
<section id="secArch" class="hidden">
<div class="card">
<h2 data-i18n="archTitle"></h2>
<p data-i18n="archSub"></p>
<div class="arch-flow">
<div class="arch-box">
<div class="arch-num">01 · TEXT</div>
<div class="arch-name" data-i18n="a1Title"></div>
<div class="arch-desc" data-i18n="a1Desc"></div>
</div>
<div class="arch-box">
<div class="arch-num">02 · BACKBONE</div>
<div class="arch-name" data-i18n="a2Title"></div>
<div class="arch-desc" data-i18n="a2Desc"></div>
</div>
<div class="arch-box">
<div class="arch-num">03 · DIFFUSION</div>
<div class="arch-name" data-i18n="a3Title"></div>
<div class="arch-desc" data-i18n="a3Desc"></div>
</div>
<div class="arch-box">
<div class="arch-num">04 · VOCODER</div>
<div class="arch-name" data-i18n="a4Title"></div>
<div class="arch-desc" data-i18n="a4Desc"></div>
</div>
<div class="arch-box">
<div class="arch-num">05 · TIME/PITCH</div>
<div class="arch-name" data-i18n="a5Title"></div>
<div class="arch-desc" data-i18n="a5Desc"></div>
</div>
</div>
<h3 data-i18n="archCratesTitle"></h3>
<div class="ep-list">
<div class="ep-row"><span class="method get">LIB</span><span class="ep-path">voxcpm-rs-core</span><span class="muted" data-i18n="cCore"></span></div>
<div class="ep-row"><span class="method post">FFI</span><span class="ep-path">voxcpm-au-timepitch</span><span class="muted" data-i18n="cAu"></span></div>
<div class="ep-row"><span class="method get">BIN</span><span class="ep-path">voxcpm-cli (voxcpm)</span><span class="muted" data-i18n="cCli"></span></div>
</div>
</div>
</section>
</div>
<div class="toast" id="toast"></div>
<script>
(() => {
'use strict';
const I18N = {
'zh-CN': {
backStudio: '返回语音工作台',
ready: '引擎在线',
offline: '服务未连接',
tabApi: 'HTTP API & 在线试调',
tabCrate: 'Rust Crate 接入',
tabCli: 'CLI 命令行',
tabArch: '设计思路与架构',
apiEndpointsTitle: 'HTTP 接口总览',
apiEndpointsSub: '所有接口均在本地运行(默认 http://127.0.0.1:8080),与 CLI 和 voxcpm-rs-core 共用同一份语音库与推理引擎。',
epHealth: '查看当前加载模型、采样率(48000 Hz)、版本与语音库目录',
epPresets: '列出全部内置双语声音设计预设(Voice Design Presets)',
epVoicesList: '列出 ~/.voxcpm/voices 中所有已保存的克隆声音',
epVoicesSave: '上传 WAV(Base64)保存新克隆声音,支持快速克隆或高保真逐字稿克隆',
epVoiceGet: '获取指定克隆声音的元数据',
epVoiceAudio: '下载或试听已保存声音的参考音频(ref)或提示音频(prompt)',
epVoiceDel: '删除指定的已保存克隆声音',
epChunk: '预览长文本按中英标点自动分段的结果',
epTts: '完整合成并返回 48 kHz 单声道 16-bit WAV(响应头附带 RTF / TTFA / 显存指标)',
epTtsStream: '低延迟流式合成,实时返回 48 kHz mono s16le 原始 PCM 数据流',
tryTitle: '在线试调(Try It Live)',
trySub: '直接向当前运行的本地服务发送请求,查看实时返回 JSON 或播放合成出的 WAV。',
btnSendReq: '▶ 发送请求',
schemaTitle: 'POST /v1/tts 与 /v1/tts/stream 请求参数',
schemaSub: '两个接口接收完全相同的 camelCase JSON 请求体(最大 20 MiB)。',
thField: '字段', thType: '类型 / 默认值', thDesc: '说明',
fText: '待合成文本(中/英/多语种混读,最长 32 KiB)',
fVoice: '使用 ~/.voxcpm/voices 中已保存的克隆声音 ID(如 "tyr")',
fPreset: '使用内置声音预设 ID(如 "podcast-male"、"news-anchor")',
fInstruct: '自然语言声音与语气描述(会拼接为 (instruct)text)',
fSpeed: '语速倍率(0.5 ~ 2.0,例如 1.2 表示 1.2 倍速)',
fPreservePitch: '保持原音调(默认 true,调用 Apple 原生 AUNewTimePitch,与 iMovie 同源)',
fPitch: '音调微调半音数(-6.0 ~ +6.0,默认 0.0)',
fRefAudio: '一次性快速克隆的参考 WAV(Base64,可带 data:audio/wav;base64, 前缀)',
fPromptAudio: '一次性高保真续写克隆的提示 WAV(需配合 promptText)',
fPromptText: 'promptAudioWavBase64 对应的精确逐字稿',
fSampling: 'CFM 扩散去噪步数 / CFG 引导强度 / 初始噪声温度',
fSeed: '可选随机种子(用于完全可复现的输出)',
fChunk: '是否按标点自动切分长文本 / 每段加权字符上限',
curlTitle: 'curl 示例:合成 WAV',
streamCurlTitle: 'curl 示例:流式 PCM 输出',
crateTitle: '在第三方 Rust 项目中使用 voxcpm-rs-core',
crateSub: '所有核心能力(模型下载、MLX 推理、流式 AudioVAE、语音库管理、Apple AUNewTimePitch 保调)均封装在 voxcpm-rs-core 中,且核心 crate 100% #![forbid(unsafe_code)]。',
crateEx1: '2. 批量合成 + 预设 + 1.2x 保调',
crateEx2: '3. 低延迟流式合成 + 复用克隆声音库',
cliTitle: 'CLI 命令行速查(voxcpm)',
cliSub: 'WebUI 里的全部功能(朗读、克隆、保存语音库、1.2x 保调)都对应完整的 CLI 命令。',
archTitle: '系统设计思路与流水线',
archSub: '围绕 Apple Silicon 统一内存与 Metal GPU 特性从零设计的纯 Rust 架构:',
a1Title: '双语分段 + CJK 分词',
a1Desc: '按中英标点智能切分长文本并复用 OpenBMB CJK 字符拆分规则,避免长句掉质量。',
a2Title: 'MiniCPM-4 MLX 主干',
a2Desc: '自动识别 8bit/4bit/bf16/混合精度 safetensors,预计算 LongRoPE,单 patch 单次 eval()。',
a3Title: 'FP32 CFM ODE + CFG-Zero*',
a3Desc: 'BF16 扩散估计器 + FP32 欧拉积分消除量化累积噪声,支持单分支快速路径。',
a4Title: 'AudioVAE V2 滑窗流式解码',
a4Desc: '16 kHz 编码参考音,48 kHz 原生流式滑窗解码(含因果前缀上下文),首音 ~220ms。',
a5Title: 'Apple AUNewTimePitch',
a5Desc: '直接调用 macOS AudioToolbox 原生相位锁定 + 瞬态保护引擎,与 iMovie 保持原音调同源。',
archCratesTitle: 'Workspace 模块划分',
cCore: '纯安全 Rust 核心库(模型、Tokenizer、VoiceStore、预设、Pinned MLX Actor)',
cAu: '极薄独立 FFI 封装,隔离 macOS AudioToolbox AUNewTimePitch / AUVarispeed',
cCli: '统一二进制:本地 CLI(speak / voice / presets / download / info)+ 内嵌 Studio WebUI 与 HTTP API(voxcpm serve)',
copy: '复制', copied: '已复制!',
},
en: {
backStudio: 'Back to Studio',
ready: 'Engine Online',
offline: 'Server Offline',
tabApi: 'HTTP API & Try It',
tabCrate: 'Rust Crate Usage',
tabCli: 'CLI Reference',
tabArch: 'Architecture',
apiEndpointsTitle: 'HTTP Endpoints',
apiEndpointsSub: 'All endpoints run locally (default http://127.0.0.1:8080) sharing the same MLX engine and ~/.voxcpm/voices library with the CLI and voxcpm-rs-core.',
epHealth: 'Returns active model ID, sample rate (48000 Hz), version, and voices directory',
epPresets: 'Lists all built-in bilingual Voice Design presets',
epVoicesList: 'Lists all saved cloned voice profiles in ~/.voxcpm/voices',
epVoicesSave: 'Saves a new cloned voice profile (Quick Reference or High-Fidelity Transcript)',
epVoiceGet: 'Returns metadata for one saved voice profile',
epVoiceAudio: 'Streams the stored reference (ref) or continuation (prompt) WAV audio',
epVoiceDel: 'Deletes a saved voice profile',
epChunk: 'Previews punctuation-aware long-text chunking',
epTts: 'Synthesizes a complete 48 kHz mono 16-bit WAV (with X-VoxCPM-* telemetry headers)',
epTtsStream: 'Streams low-latency 48 kHz mono s16le raw PCM chunks over HTTP',
tryTitle: 'Try It Live',
trySub: 'Send a live request to this local server and inspect the JSON response or play the generated WAV.',
btnSendReq: '▶ Send Request',
schemaTitle: 'POST /v1/tts & /v1/tts/stream Request Body',
schemaSub: 'Both endpoints accept the exact same camelCase JSON payload (up to 20 MiB).',
thField: 'Field', thType: 'Type / Default', thDesc: 'Description',
fText: 'Text to synthesize (Chinese, English, multilingual code-switching; max 32 KiB)',
fVoice: 'Saved cloned voice ID in ~/.voxcpm/voices (e.g. "tyr")',
fPreset: 'Built-in Voice Design preset ID (e.g. "podcast-male", "news-anchor")',
fInstruct: 'Natural-language voice & tone instruction (prepended as (instruct)text)',
fSpeed: 'Speaking speed multiplier (0.5 to 2.0, e.g. 1.2 for 1.2x)',
fPreservePitch: 'Preserve original vocal pitch (default true, powered by Apple AUNewTimePitch)',
fPitch: 'Optional pitch shift in semitones (-6.0 to +6.0, default 0.0)',
fRefAudio: 'One-shot Reference Clone WAV (Base64; optional data:audio/wav;base64, prefix)',
fPromptAudio: 'One-shot Ultimate Cloning continuation WAV (requires promptText)',
fPromptText: 'Exact verbatim transcript matching promptAudioWavBase64',
fSampling: 'CFM denoising steps / Classifier-Free Guidance scale / noise temperature',
fSeed: 'Optional RNG seed for reproducible output',
fChunk: 'Auto-split long text on punctuation / weighted chunk length threshold',
curlTitle: 'curl Example: Full WAV',
streamCurlTitle: 'curl Example: Streaming PCM',
crateTitle: 'Using voxcpm-rs-core in External Rust Applications',
crateSub: 'All core capabilities (HF Hub downloads, MLX inference, streaming AudioVAE, VoiceStore, presets, and Apple AUNewTimePitch) live inside voxcpm-rs-core (#![forbid(unsafe_code)]).',
crateEx1: '2. Batch Synthesis + Preset + 1.2x Preserve Pitch',
crateEx2: '3. Low-Latency Streaming + Saved Cloned Voices',
cliTitle: 'CLI Quick Reference (voxcpm)',
cliSub: 'Every Studio WebUI feature has 100% parity in the voxcpm CLI.',
archTitle: 'Design Philosophy & Audio Pipeline',
archSub: 'Built from scratch in Rust for Apple Silicon unified memory and Metal GPU execution:',
a1Title: 'Bilingual Chunker + Tokenizer',
a1Desc: 'Splits long text on Chinese/English punctuation and applies OpenBMB CJK char splitting.',
a2Title: 'MiniCPM-4 MLX Backbone',
a2Desc: 'Dynamic per-layer 8bit/4bit/bf16 dispatch, cached LongRoPE, single eval() per patch.',
a3Title: 'FP32 CFM ODE + CFG-Zero*',
a3Desc: 'BF16 estimator with FP32 Euler ODE state eliminates quantization drift and artifacts.',
a4Title: 'Streaming AudioVAE V2',
a4Desc: '16 kHz voice prompt encode, 48 kHz sliding-window causal decode (~220 ms TTFA).',
a5Title: 'Apple AUNewTimePitch',
a5Desc: 'Native macOS AudioToolbox peak-locked phase vocoder + transient preservation (same as iMovie).',
archCratesTitle: 'Workspace Crates',
cCore: '100% safe Rust core engine (MLX model, tokenizer, VoiceStore, presets, pinned actor)',
cAu: 'Thin isolated FFI wrapper around macOS AudioToolbox AUNewTimePitch & AUVarispeed',
cCli: 'Unified binary: local CLI (speak / voice / presets / download / info) + embedded Studio WebUI & HTTP API (voxcpm serve)',
copy: 'Copy', copied: 'Copied!',
},
};
let lang = localStorage.getItem('voxcpm_lang') || ((navigator.language || '').toLowerCase().startsWith('zh') ? 'zh-CN' : 'en');
const $ = (id) => document.getElementById(id);
const tr = () => I18N[lang] || I18N['zh-CN'];
function showToast(msg) {
const el = $('toast');
el.textContent = msg;
el.style.display = 'block';
clearTimeout(el._t);
el._t = setTimeout(() => { el.style.display = 'none'; }, 2000);
}
function applyLang(next) {
lang = next === 'en' ? 'en' : 'zh-CN';
localStorage.setItem('voxcpm_lang', lang);
const t = tr();
document.documentElement.lang = lang;
document.querySelectorAll('.lang-btn').forEach((b) => b.classList.toggle('active', b.dataset.lang === lang));
document.querySelectorAll('[data-i18n]').forEach((el) => {
const k = el.dataset.i18n;
if (typeof t[k] === 'string') el.textContent = t[k];
});
document.querySelectorAll('.copy-btn').forEach((b) => { b.textContent = t.copy; });
}
document.querySelectorAll('.lang-btn').forEach((b) => b.addEventListener('click', () => applyLang(b.dataset.lang)));
document.querySelectorAll('.sec-tab').forEach((b) => {
b.addEventListener('click', () => {
const target = b.dataset.sec;
document.querySelectorAll('.sec-tab').forEach((x) => x.classList.toggle('active', x.dataset.sec === target));
['api', 'crate', 'cli', 'arch'].forEach((id) => {
const cap = 'sec' + id.charAt(0).toUpperCase() + id.slice(1);
$(cap).classList.toggle('hidden', id !== target);
});
});
});
document.querySelectorAll('.copy-btn').forEach((b) => {
b.addEventListener('click', async () => {
const code = $(b.dataset.copy).textContent;
try { await navigator.clipboard.writeText(code); showToast(tr().copied); } catch (_) {}
});
});
const TRY_TEMPLATES = {
health: { method: 'GET', path: '/health', body: '' },
presets: { method: 'GET', path: '/v1/presets', body: '' },
voices: { method: 'GET', path: '/v1/voices', body: '' },
chunk: {
method: 'POST',
path: '/v1/chunk-preview',
body: JSON.stringify({ text: '第一句话在这里结束。Second sentence follows naturally! 第三句用来验证长文本分段。', chunkMaxUnits: 40 }, null, 2),
},
tts: {
method: 'POST',
path: '/v1/tts',
body: JSON.stringify({ text: '你好!这是从 /docs 在线试调接口发出的 1.2 倍速原音调语音。', preset: 'podcast-male', speed: 1.2, preservePitch: true, seed: 42 }, null, 2),
},
};
function syncTryTemplate() {
const cfg = TRY_TEMPLATES[$('tryPreset').value];
$('tryBody').value = cfg.body;
$('tryBody').classList.toggle('hidden', cfg.method === 'GET');
}
$('tryPreset').addEventListener('change', syncTryTemplate);
syncTryTemplate();
$('btnTryRun').addEventListener('click', async () => {
const cfg = TRY_TEMPLATES[$('tryPreset').value];
const btn = $('btnTryRun');
btn.disabled = true;
$('tryMeta').textContent = '...';
$('tryOutWrap').classList.remove('hidden');
$('tryAudio').classList.add('hidden');
const t0 = performance.now();
try {
const opts = { method: cfg.method };
if (cfg.method === 'POST') {
opts.headers = { 'Content-Type': 'application/json' };
opts.body = $('tryBody').value;
}
const resp = await fetch(cfg.path, opts);
const ms = Math.round(performance.now() - t0);
const ct = resp.headers.get('content-type') || '';
$('tryMeta').textContent = `HTTP ${resp.status} · ${ms}ms`;
if (ct.includes('audio/wav') && resp.ok) {
const blob = await resp.blob();
const url = URL.createObjectURL(blob);
$('tryAudio').src = url;
$('tryAudio').classList.remove('hidden');
$('tryOut').textContent = [
`Content-Type: ${ct}`,
`Size: ${(blob.size / 1024).toFixed(1)} KiB`,
`X-VoxCPM-Duration-Secs: ${resp.headers.get('x-voxcpm-duration-secs')}`,
`X-VoxCPM-RTF: ${resp.headers.get('x-voxcpm-rtf')}`,
`X-VoxCPM-Peak-Memory-MB: ${resp.headers.get('x-voxcpm-peak-memory-mb')}`,
].join('\n');
$('tryAudio').play().catch(() => {});
} else {
const text = await resp.text();
try { $('tryOut').textContent = JSON.stringify(JSON.parse(text), null, 2); }
catch (_) { $('tryOut').textContent = text; }
}
} catch (err) {
$('tryOut').textContent = String(err);
} finally {
btn.disabled = false;
}
});
applyLang(lang);
fetch('/health').then((r) => r.json()).then((h) => {
$('statusDot').className = 'dot ok';
$('statusText').textContent = `${tr().ready} · ${h.model}`;
}).catch(() => {
$('statusDot').className = 'dot err';
$('statusText').textContent = tr().offline;
});
})();
</script>
</body>
</html>