- 文档
- 接口能力
- 语音合成与识别
接口能力 · AUDIO
语音合成与语音识别 API
Model Flux 语音接口:用 melotts-zh 调 /v1/audio/speech 合成中文语音,用 whisper-1 调 /v1/audio/transcriptions 把音频转成文字,附 curl 与 Python 示例。
TL;DR · 一句话答案
文字转语音调用 POST /v1/audio/speech,模型 melotts-zh,响应体直接是音频文件;语音转文字调用 POST /v1/audio/transcriptions,模型 whisper-1,用 multipart 上传音频。
文字转语音#
curl
Bash / Zsh
curl -sS https://modelflux.cn/v1/audio/speech \
-H "Authorization: Bearer $MODEL_FLUX_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"melotts-zh","input":"欢迎使用 Model Flux。","voice":"default"}' \
-o speech.mp3Python
Python
import os
from openai import OpenAI
client = OpenAI(base_url="https://modelflux.cn/v1", api_key=os.environ["MODEL_FLUX_KEY"])
with client.audio.speech.with_streaming_response.create(
model="melotts-zh", voice="default", input="欢迎使用 Model Flux。"
) as resp:
resp.stream_to_file("speech.mp3")OpenAI SDK 要求必须传 voice。可用音色和输出格式见模型广场里该模型的详情。响应是二进制音频,用 -o 保存成文件,不要直接打印到终端。
语音转文字#
curl
Bash / Zsh
curl -sS https://modelflux.cn/v1/audio/transcriptions \
-H "Authorization: Bearer $MODEL_FLUX_KEY" \
-F model=whisper-1 \
-F file=@meeting.mp3 \
-F language=zhPython
Python
with open("meeting.mp3", "rb") as f:
text = client.audio.transcriptions.create(model="whisper-1", file=f, language="zh")
print(text.text)JSON响应示例
{ "text": "今天的会议主要讨论三件事……" }使用建议#
- 长音频先切成几分钟一段再上传,减少超时,失败了也只需要重传一小段。
- 指定
language能提高中文识别的准确率。 - TTS 的单次输入不宜太长,长文章按段落分批合成后再拼接。
计费#
内容有误或缺失?发邮件到 tiantuowl@163.com示例中的 Key 与模型 ID 均为占位值