加载中...
-
开发者接入文档
接入总览
生产 Base URL:https://voice.wmj.com.cn。所有 HTTP API 使用 Header X-API-Key 鉴权;浏览器 WebSocket 使用 URL 参数 ?api_key=。
页面上方的 API Key 就是当前账号可用密钥。复制按钮会自动把当前 API Key 写入示例,方便直接发给开发者或 AI 生成代码。
POST /tts_to_audio 返回 WAV;/tts_to_ogg、/tts_to_mp3、/tts_to_adpcm 返回压缩格式;/tts_to_audio_stream 返回流式 PCM。
POST /asr 上传音频文件;/asr/stream 上传 16kHz 单声道 Int16 PCM;/asr/funasr 适合长音频和高精度识别。
wss://voice.wmj.com.cn/ws/tts/stream/web 支持 TTS PCM/OPUS/ADPCM 流式播放;/ws/asr/web 支持 ASR 流式识别。浏览器 URL 携带 api_key。
发音人 speaker ID
开发时请把下面的 speaker ID 原样传入请求体的 speaker 字段。默认推荐女声:prompt_female_high;默认推荐男声:prompt_bobo。
prompt_female_highprompt_duoduoprompt_wenroutaotaoprompt_ref_audio_01prompt_junjunprompt_boboprompt_kunkunprompt_ref_audio_02custom_1765531319_atlanticcustom_1772859966_duanlaoshicurl 快速测试
curl -X POST "https://voice.wmj.com.cn/tts_to_audio" \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"你好,欢迎使用 Voice API。","speaker":"prompt_female_high","speed":1.0,"num_step":2}' \
--output reply.wav
curl -X POST "https://voice.wmj.com.cn/asr" \
-H "X-API-Key: YOUR_API_KEY" \
-F "audio=@recording.wav"
curl -H "X-API-Key: YOUR_API_KEY" \
"https://voice.wmj.com.cn/get_speakers"
VoxCPM 多语言 TTS
需要多语言或中文方言时,使用 engine:"voxcpm" 和 model:"VoxCPM2";推荐 num_step:4 做低延迟默认值。多语种可直接输入目标语言文本;中文方言需要在 text 中使用方言词汇和句式,并传 language 或 dialect 指定方言控制。
VoxCPM2 支持 30 语种:阿拉伯语、缅甸语、中文、丹麦语、荷兰语、英语、芬兰语、法语、德语、希腊语、希伯来语、印地语、印尼语、意大利语、日语、高棉语、韩语、老挝语、马来语、挪威语、波兰语、葡萄牙语、俄语、西班牙语、斯瓦希里语、瑞典语、塔加洛语、泰语、土耳其语、越南语。中文方言:四川话、粤语、吴语、东北话、河南话、陕西话、山东话、天津话、闽南话。
curl -X POST "https://voice.wmj.com.cn/tts_to_audio" \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text":"Hello, welcome to our multilingual voice service.",
"engine":"voxcpm",
"model":"VoxCPM2",
"quality":"fast",
"num_step":4,
"voice_description":"A clear, natural, warm female voice.",
"sample_rate":24000,
"retry_badcase":false,
"retry_badcase_ratio_threshold":5.0,
"use_prompt_cache":true
}' \
--output voxcpm.wav
OPUS WebSocket 流式播放
适合实时播报、嵌入式设备、对讲或低带宽场景。浏览器连接 wss://voice.wmj.com.cn/ws/tts/stream/web?api_key=YOUR_API_KEY;服务端或设备也可连接 wss://voice.wmj.com.cn/ws/tts/stream 并在握手 Header 中传 X-API-Key。
连接成功后发送一次 JSON 请求,设置 format:"opus"。服务端先返回 JSON 状态消息,随后连续返回二进制 OPUS 音频分片,最后返回 {"type":"tts","state":"stop"}。客户端应按收到顺序解码播放二进制分片,不要把二进制分片当 JSON 解析。
// WebSocket URL
wss://voice.wmj.com.cn/ws/tts/stream/web?api_key=YOUR_API_KEY
// 请求 JSON
{
"type": "tts_request",
"session_id": "client_001_1710000000000",
"text": "欢迎使用实时 OPUS 流式语音播放。",
"speaker": "prompt_female_high",
"speed": 1.0,
"num_step": 2,
"format": "opus",
"sample_rate": 16000,
"number_mode": "value"
}
// 服务端文本消息
{"type":"tts","state":"start","session_id":"client_001_1710000000000"}
{"type":"tts","state":"stop","session_id":"client_001_1710000000000"}
// 服务端二进制消息
BinaryMessage = OPUS encoded audio chunk
参数说明:format 可选 opus/pcm/adpcm;OPUS 推荐 sample_rate:16000;speaker 使用上方发音人 ID;worker_id 可选,只有后台节点测试或灰度时才指定。
JavaScript 示例
const API_KEY = 'YOUR_API_KEY';
async function textToSpeech(text) {
const response = await fetch('https://voice.wmj.com.cn/tts_to_audio', {
method: 'POST',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
text,
speaker: 'prompt_female_high',
speed: 1.0,
num_step: 2
})
});
if (!response.ok) throw new Error(await response.text());
return await response.blob();
}
Python 示例
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://voice.wmj.com.cn"
resp = requests.post(
f"{BASE_URL}/tts_to_audio",
headers={"X-API-Key": API_KEY},
json={
"text": "你好,欢迎使用 Voice API。",
"speaker": "prompt_female_high",
"speed": 1.0,
"num_step": 2,
},
timeout=60,
)
resp.raise_for_status()
open("reply.wav", "wb").write(resp.content)
账户等级说明
- Normal 普通用户:可使用 GPU 计算节点,每日限制 1000 次请求
- Pro Pro 用户:可使用 GPU 计算节点,更高每日配额
- Admin 管理员:无限制