🎤 Voice API

用户认证系统

📧 新用户将自动注册,已有账户直接登录

🔑 使用已有的 API Key 直接登录

🎤 Voice API 用户管理

加载中...

-
账号等级
-
今日配额
-
总请求数
-

开发者接入文档

接入总览

生产 Base URL:https://voice.wmj.com.cn。所有 HTTP API 使用 Header X-API-Key 鉴权;浏览器 WebSocket 使用 URL 参数 ?api_key=

页面上方的 API Key 就是当前账号可用密钥。复制按钮会自动把当前 API Key 写入示例,方便直接发给开发者或 AI 生成代码。

TTS 文字转语音

POST /tts_to_audio 返回 WAV;/tts_to_ogg/tts_to_mp3/tts_to_adpcm 返回压缩格式;/tts_to_audio_stream 返回流式 PCM。

ASR 语音识别

POST /asr 上传音频文件;/asr/stream 上传 16kHz 单声道 Int16 PCM;/asr/funasr 适合长音频和高精度识别。

实时 WebSocket

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_high
女声-多多,亲和客服 prompt_duoduo
桃桃-温柔,助理/朗读 prompt_wenroutaotao
女声-温柔,中长文本 prompt_ref_audio_01
女声-英文,英文/中英混合 prompt_junjun
男声-优雅,播报/讲解 prompt_bobo
男声-坤坤,轻松互动 prompt_kunkun
男声-搞怪,角色化内容 prompt_ref_audio_02
自定义 atlantic custom_1765531319_atlantic
自定义 duanlaoshi,教学内容 custom_1772859966_duanlaoshi

curl 快速测试

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 中使用方言词汇和句式,并传 languagedialect 指定方言控制。

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:16000speaker 使用上方发音人 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 管理员:无限制