跳轉到主要內容

請求主體

同步請求逾時: 這個非聊天端點會等待路由到的模型完成處理。大型輸入、長音訊或大量批次可能超過常見的 30s 用戶端預設逾時,因此請將 HTTP 用戶端逾時設定為至少 120s
file
file
必填
要轉錄的音訊檔案。支援格式:flac、mp3、mp4、mpeg、mpga、m4a、ogg、wav、webm。
model
string
預設值:"whisper-1"
要使用的模型。目前僅支援 whisper-1
language
string
音訊的語言,採用 ISO-639-1 格式(例如:enzhja)。
prompt
string
可選文字,用於引導模型的風格或延續前一段內容。
response_format
string
預設值:"json"
輸出格式:jsontextsrtverbose_jsonvtt
temperature
number
預設值:"0"
取樣溫度(0 到 1)。
timestamp_granularities
array
時間戳記粒度:word 和/或 segment。需要 verbose_json

回應

text
string
轉錄後的文字。
對於 verbose_json
task
string
一律為 transcribe
language
string
偵測到的語言。
duration
number
音訊時長(秒)。
segments
array
含時間戳記的轉錄片段。
words
array
詞級時間戳記(若有請求)。
curl -X POST "https://api.tokenlab.sh/v1/audio/transcriptions" \
  -H "Authorization: Bearer sk-your-api-key" \
  -F file="@audio.mp3" \
  -F model="whisper-1" \
  -F language="en"
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://api.tokenlab.sh/v1"
)

with open("audio.mp3", "rb") as audio_file:
    response = client.audio.transcriptions.create(
        model="whisper-1",
        file=audio_file,
        language="en"
    )

print(response.text)
import OpenAI from 'openai';
import fs from 'fs';

const client = new OpenAI({
  apiKey: 'sk-your-api-key',
  baseURL: 'https://api.tokenlab.sh/v1'
});

const response = await client.audio.transcriptions.create({
  model: 'whisper-1',
  file: fs.createReadStream('audio.mp3'),
  language: 'en'
});

console.log(response.text);
<?php
$ch = curl_init('https://api.tokenlab.sh/v1/audio/transcriptions');

$file = new CURLFile('audio.mp3', 'audio/mpeg', 'audio.mp3');

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer sk-your-api-key'
    ],
    CURLOPT_POSTFIELDS => [
        'file' => $file,
        'model' => 'whisper-1',
        'language' => 'en'
    ]
]);

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);
echo $data['text'];
{
  "text": "Hello, this is a test of the transcription API."
}
{
  "task": "transcribe",
  "language": "english",
  "duration": 5.5,
  "text": "Hello, this is a test of the transcription API.",
  "segments": [
    {
      "id": 0,
      "start": 0.0,
      "end": 2.5,
      "text": "Hello, this is a test",
      "tokens": [...]
    }
  ]
}

翻譯

若要將音訊翻譯為英文,請使用 translations endpoint:
response = client.audio.translations.create(
    model="whisper-1",
    file=audio_file
)