语音转文本 / 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
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| file | string | 必需 | 音频文件。需要转录的音频流或文件路径,支持 mp3、mp4、mpeg、mpga、m4a、wav、webm 等格式。 |
| model | string | 必需 | 转录模型 ID。在 Whisper 接口中,这里通常固定填写 whisper-1。 |
| prompt | string | 可选 | 引导文本。用于指导模型风格、纠正特定词汇或承接上一段音频内容的文本,应与音频语言匹配。 |
| language | string | 可选 | 音频语言。以 ISO-639-1 格式(如 "zh", "en")提供输入语言,能显著提高转录的准确性和响应延迟。 |
| response_format | string | 可选 | 输出文本格式。默认为 json,也可指定为 text、srt、verbose_json 或 vtt 等字幕格式。 |
| temperature | number | 可选 | 采样温度。介于 0 到 1 之间。数值越高输出越随机,越低则越集中确定;设为 0 时模型会自动调整。 |
请求示例 (JSON)
{
"model": "string",
"file": "string",
"prompt": "string",
"response_format": "string",
"temperature": 0,
"language": "string"
}返回响应
200 成功
Content-Type: application/json
响应参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| text | string | 必需 | 输出的文本 |
响应示例
{
"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"))