API文档(api-reference)
音频(Audio)

音频Audio

了解如何将音频转换为文本。

相关指南:语音转文本

创建转录 Create transcription Beta

post https://api.openai.com/v1/audio/transcriptions (opens in a new tab)

将音频转录为输入语言。

请求正文

file 是字符串类型的必填项,表示要转录的音频文件,格式为 mp3mp4mpegmpgam4awavwebm 之一。

model 是字符串类型的必填项,表示要使用的模型的ID。目前只有 whisper-1 可用。

prompt 是字符串类型的可选项,用于指导模型的风格或继续以前的音频片段。提示应与音频语言匹配。

response_format 是字符串类型的可选项。默认为 json。表示转录输出的格式,可选项为 jsontextsrtverbose_jsonvtt中的一种。

temperature 是数字类型的可选项。默认为 0。取值范围在 0 到 1 之间。更高的值,如 0.8,会使输出更加随机化,而更低的值,如 0.2,则会使其更加集中和确定性。如果设置为 0,则模型将使用 对数概率 (opens in a new tab) 自动增加温度(temperature),直到触发某些阈值。

language 是字符串类型的可选项,表示输入音频的语言。以 ISO-639-1 (opens in a new tab) 格式提供输入语言将改善准确性和延迟。

请求示例(Python方式)

 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"

请求参数(Parameters)

{
 "file": "audio.mp3",
 "model": "whisper-1"
}

响应体 (Response)

{
 "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."
}

新建音频翻译 Create translation Beta

post https://api.openai.com/v1/audio/translations (opens in a new tab)

将音频翻译成英语。

请求体

file 字符串类型,必填项。要翻译的音频文件,格式可以是 mp3、mp4、mpeg、mpga、m4a、wav 或 webm 之一。

model 字符串类型,必填项。要使用的模型 ID。目前只有 whisper-1 可用。

prompt 字符串类型,可选。一个可选的文本,用于指导模型的风格或继续前面的音频片段。提示应为英语。

response_format 字符串类型,可选。默认是 json。转录输出的格式,可以是 json、文本、srt、verbose_json 或 vtt 中的一种。

temperature 数字类型,可选。默认是 0。采样温度(temperature),介于 0 和 1 之间。较高的值如 0.8 将使输出更加随机,而较低的值如 0.2 将使其更加聚焦和确定性。如果设置为 0,则模型将使用对数概率 (opens in a new tab)自动增加温度(temperature),直到达到某些阈值。

请求示例(Python方式)

 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"

请求参数(Parameters)

{
 "file": "german.m4a",
 "model": "whisper-1"
}

响应体 (Response)

{
 "text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?"
}