跳转到内容
exoticrouter.com ↗

语音

两个采用 OpenAI 语音格式的接口:一个把文本读出来,另一个把说的话写下来。

POST https://api.exoticrouter.com/v1/audio/speech

cURL
curl https://api.exoticrouter.com/v1/audio/speech \
-H "Authorization: Bearer $EXOTIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini-tts",
"voice": "alloy",
"input": "The sky is blue because air scatters blue light the most."
}' \
-o speech.mp3
Python
with client.audio.speech.with_streaming_response.create(
model="openai/gpt-4o-mini-tts",
voice="alloy",
input="The sky is blue because air scatters blue light the most.",
) as response:
response.stream_to_file("speech.mp3")
TypeScript
import fs from "node:fs";
const speech = await client.audio.speech.create({
model: "openai/gpt-4o-mini-tts",
voice: "alloy",
input: "The sky is blue because air scatters blue light the most.",
});
fs.writeFileSync("speech.mp3", Buffer.from(await speech.arrayBuffer()));
  • model 必须是语音合成模型,也就是模型列表里 formats 包含 speech 的模型。
  • 返回的就是音频本身,边生成边发送,并带有相应的内容类型(MP3 是 audio/mpeg)。请求体的其余部分(比如 voice 和输出格式)会传给模型。

POST https://api.exoticrouter.com/v1/audio/transcriptions

以表单的形式发送录音,并附上模型。

cURL
curl https://api.exoticrouter.com/v1/audio/transcriptions \
-H "Authorization: Bearer $EXOTIC_API_KEY" \
-F model="openai/gpt-4o-mini-transcribe" \
-F file="@meeting.mp3"
Python
transcript = client.audio.transcriptions.create(
model="openai/gpt-4o-mini-transcribe",
file=open("meeting.mp3", "rb"),
)
print(transcript.text)
TypeScript
import fs from "node:fs";
const transcript = await client.audio.transcriptions.create({
model: "openai/gpt-4o-mini-transcribe",
file: fs.createReadStream("meeting.mp3"),
});
console.log(transcript.text);
{ "text": "Right, shall we start? First on the list is the launch date." }
  • model 必须是转写模型,也就是 formats 包含 transcriptions 的模型。
  • 文件和表单里的其他部分会原样传给模型。如果指定了其他 response_format(纯文本或字幕),返回内容就是相应的格式。
  • 整个请求(包括录音)最大 32 MiB。
  • 语音合成按 input 的字符数计价:对语音合成模型来说,input_per_mtok 是每百万字符的美元价格。
  • 转写在模型提供 token 统计时按 token 计价,否则按录音时长(以秒计)计价。
  • 如果模型有 per_request 费用,每次请求会加收一次。

完整说明见计费。