语音合成 / 识别
语音合成(TTS)
POST /v1/audio/speech
将文本转换为语音,返回音频二进制流。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | ✅ | TTS 模型,如 tts-1(标准)、tts-1-hd(高清) |
input | string | ✅ | 要合成的文本(最大 4096 字符) |
voice | string | ✅ | 音色,见下方可选值 |
response_format | string | — | 音频格式:mp3(默认)、opus、aac、flac、wav、pcm |
speed | number | — | 语速,范围 0.25–4.0(默认 1.0) |
可用音色
| 音色名 | 风格描述 |
|---|---|
alloy | 中性、均衡 |
echo | 磁性、沉稳 |
fable | 温暖、叙事感 |
onyx | 深沉、权威 |
nova | 活泼、友好 |
shimmer | 柔和、清澈 |
示例
bash
curl https://api.idreame.com/v1/audio/speech \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxxxx" \
-d '{
"model": "tts-1",
"input": "欢迎使用 iDreame 算力平台,您的 AI 能力一站式入口。",
"voice": "nova"
}' \
--output welcome.mp3python
from pathlib import Path
from openai import OpenAI
client = OpenAI(
base_url="https://api.idreame.com/v1",
api_key="sk-xxxxxxxx",
)
response = client.audio.speech.create(
model="tts-1",
voice="nova",
input="欢迎使用 iDreame 算力平台,您的 AI 能力一站式入口。",
)
Path("welcome.mp3").write_bytes(response.content)语音识别(STT)
POST /v1/audio/transcriptions
将音频文件转换为文字(语音转录)。使用 multipart/form-data 格式上传文件。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
file | file | ✅ | 音频文件(支持 mp3、mp4、mpeg、mpga、m4a、wav、webm,最大 25MB) |
model | string | ✅ | 识别模型,如 whisper-1 |
language | string | — | 指定语言代码(如 zh、en),不填则自动检测 |
prompt | string | — | 可选的提示词,用于引导识别风格或纠正专有名词 |
response_format | string | — | 输出格式:json(默认)、text、srt、vtt、verbose_json |
temperature | number | — | 采样温度 0–1 |
示例
bash
curl https://api.idreame.com/v1/audio/transcriptions \
-H "Authorization: Bearer sk-xxxxxxxx" \
-F "file=@recording.mp3" \
-F "model=whisper-1" \
-F "language=zh"python
from openai import OpenAI
client = OpenAI(
base_url="https://api.idreame.com/v1",
api_key="sk-xxxxxxxx",
)
with open("recording.mp3", "rb") as audio_file:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file,
language="zh",
)
print(transcript.text)响应示例
json
{
"text": "欢迎使用 iDreame 算力平台。"
}字幕输出
设置 response_format=srt 可直接输出 SRT 格式字幕文件:
bash
curl https://api.idreame.com/v1/audio/transcriptions \
-H "Authorization: Bearer sk-xxxxxxxx" \
-F "file=@video_audio.mp3" \
-F "model=whisper-1" \
-F "response_format=srt"输出:
1
00:00:00,000 --> 00:00:02,500
欢迎使用 iDreame 算力平台。
2
00:00:02,800 --> 00:00:05,200
您的 AI 能力一站式入口。