跳转到主要内容
POST
/
v1
/
audio
/
translations
Python (OpenAI SDK)
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["COMETAPI_KEY"],
    base_url="https://api.cometapi.com/v1"
)

audio_file = open("audio.mp3", "rb")
translation = client.audio.translations.create(
    model="whisper-1",
    file=audio_file
)
print(translation.text)
{
  "text": "Hello, welcome to CometAPI."
}
使用此端点将语音音频翻译为英文文本。它适用于多语言支持队列、媒体审核,以及需要将其他语言音频统一转成英文转录文本的工作流。

首次请求

发送一个受支持的音频文件,并提供 modelfile。建议先使用一个较短的样本,以便验证上传处理、语言检测和输出解析。

读取响应

默认响应包含翻译后的英文 text。如果你请求了不同的响应格式,请根据该格式解析响应。

后续步骤

  • 当你需要原始语言的文本时,请使用 创建转录
  • 当你需要根据文本生成音频时,请使用 创建语音

授权

Authorization
string
header
必填

Bearer token authentication. Use your CometAPI key.

请求体

multipart/form-data
file
file
必填

The audio file to translate. Supported formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm.

model
string
默认值:whisper-1
必填

The audio translation model to use. Choose a current speech model from the Models page.

prompt
string

Optional text to guide the model's style or continue a previous audio segment. The prompt should be in English.

response_format
enum<string>
默认值:json

The output format for the translation.

可用选项:
json,
text,
srt,
verbose_json,
vtt
temperature
number
默认值:0

Sampling temperature between 0 and 1. Higher values produce more random output; lower values are more focused. When set to 0, the model auto-adjusts temperature using log probability.

必填范围: 0 <= x <= 1

响应

200 - application/json

The translation result in English.

text
string
必填

The translated text in English.