Skip to content

语音转文本 / gpt-4o-transcribe

POST  v1/audio/transcriptions

官方文档:https://platform.openai.com/docs/api-reference/audio/createTranscription

请求参数

Authorization

在 Header 添加参数 Authorization,其值为在 Bearer 之后拼接 Token。

Authorization: Bearer ******************

Body 参数

Content-Type: application/json

参数名类型必填说明
filestring必需音频文件。需要转录的音频流或文件路径,支持 mp3mp4mpegmpgam4awavwebm 等格式。
modelstring必需转录模型 ID。在 Whisper 接口中,这里通常固定填写 whisper-1
promptstring可选引导文本。用于指导模型风格、纠正特定词汇或承接上一段音频内容的文本,应与音频语言匹配。
languagestring可选音频语言。以 ISO-639-1 格式(如 "zh", "en")提供输入语言,能显著提高转录的准确性和响应延迟。
response_formatstring可选输出文本格式。默认为 json,也可指定为 textsrtverbose_jsonvtt 等字幕格式。
temperaturenumber可选采样温度。介于 0 到 1 之间。数值越高输出越随机,越低则越集中确定;设为 0 时模型会自动调整。

请求示例 (JSON)

{
    "model": "string",
    "file": "string",
    "prompt": "string",
    "response_format": "string",
    "temperature": 0,
    "language": "string"
}

返回响应

200 成功

Content-Type: application/json

响应参数

参数名类型必填说明
textstring必需输出的文本

响应示例

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

示例代码

python
import http.client
import json

conn = http.client.HTTPSConnection("nxaiapp.com")
payload = json.dumps({
   "model": "string",
   "file": "string",
   "prompt": "string",
   "response_format": "string",
   "temperature": 0,
   "language": "string"
})
headers = {
   'Authorization': 'Bearer <token>',
   'Content-Type': 'application/json'
}
conn.request("POST", "/v1/audio/transcriptions", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))