音频
了解如何将音频转换为文本或将文本转换为音频。
相关指南: 语音转文本
创建语音
POST https://api.openai.com/v1/audio/speech
从输入文本生成音频。
请求正文
返回
音频文件内容。
示例请求
1
2
3
4
5
6
7
8
9
curl https://api.openai.com/v1/audio/speech \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "The quick brown fox jumped over the lazy dog.",
"voice": "alloy"
}' \
--output speech.mp3
创建转录
POST https://api.openai.com/v1/audio/transcriptions
将音频转录为输入语言。
示例请求
1
2
3
4
5
curl https://api.openai.com/v1/audio/transcriptions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F file="@/path/to/file/audio.mp3" \
-F model="whisper-1"
响应
1
2
3
{
"text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that."
}
创建翻译
POST https://api.openai.com/v1/audio/translations
将音频翻译成英文。
请求正文
返回
翻译后的文本。
示例请求
1
2
3
4
5
curl https://api.openai.com/v1/audio/translations \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F file="@/path/to/file/german.m4a" \
-F model="whisper-1"
响应
1
2
3
{
"text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?"
}
转录对象 (JSON)
转录对象 (Verbose JSON)
表示模型根据提供的输入返回的详细 json 转录响应。
OBJECT 转录对象 (Verbose JSON)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"task": "transcribe",
"language": "english",
"duration": 8.470000267028809,
"text": "The beach was a popular spot on a hot summer day. People were swimming in the ocean, building sandcastles, and playing beach volleyball.",
"segments": [
{
"id": 0,
"seek": 0,
"start": 0.0,
"end": 3.319999933242798,
"text": " The beach was a popular spot on a hot summer day.",
"tokens": [
50364, 440, 7534, 390, 257, 3743, 4008, 322, 257, 2368, 4266, 786, 13, 50530
],
"temperature": 0.0,
"avg_logprob": -0.2860786020755768,
"compression_ratio": 1.2363636493682861,
"no_speech_prob": 0.00985979475080967
},
...
]
}