Audio API

Chuyển giọng nói thành văn bản

Chuyển đổi âm thanh thành văn bản kèm dấu thời gian, phát hiện ngôn ngữ và phân đoạn người nói, theo nhiều định dạng đầu ra.

POSThttps://api.oxyy.ai/v1/audio/transcriptionschuyển ngữ bằng ngôn ngữ nguồn
POSThttps://api.oxyy.ai/v1/audio/translationschuyển ngữ sang tiếng Anh

Các tham số

Tham sốLoạiBắt buộcMô tả
mô hìnhstringBắt buộcID mô hình chuyển đổi giọng nói thành văn bản, e.g. scribe_v2, whisper-large-v3-turbo.
tệptệpRequired*Tệp âm thanh dưới dạng multipart/form-data. Các định dạng hỗ trợ: mp3, mp4, mpeg, mpga, m4a, wav, webm, ogg, flac.
file_urlstringRequired*URL công khai để tải về thay vì tải lên. Tối đa 25 MB; các địa chỉ riêng tư và loopback sẽ bị từ chối.
file_base64stringRequired*Âm thanh Base64, có hoặc không có tiền tố data:.
response_formatstringKhông bắt buộcMột trong:jsontextverbose_jsonsrtvttdiarized_json Mặc định json
languagestringKhông bắt buộcMã ISO-639-1 (en, ja, bn). Bỏ trống để tự động phát hiện.
promptstringKhông bắt buộcGợi ý từ vựng hoặc phong cách — tên, biệt ngữ, chính tả dự kiến.
temperaturenumberKhông bắt buộcNhiệt độ lấy mẫu, từ 0 đến 1.
timestamp_granularitiesarrayKhông bắt buộcYêu cầu verbose_json. Một trong:wordsegment
diarizebooleanKhông bắt buộcGắn nhãn người nói, trên các model hỗ trợ tính năng này.
num_speakersintegerKhông bắt buộcGợi ý để phân tách người nói.
*Chính xác một trong file, file_url hoặc file_base64 là bắt buộc. /v1/audio/translations nhận các tham số giống nhau và trả về văn bản tiếng Anh. Không phải mô hình phiên âm nào cũng có thể dịch; mô hình không hỗ trợ sẽ trả về 400 nói rõ điều đó.

Ví dụ mã

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["OXYY_API_KEY"],
    base_url="https://api.oxyy.ai/v1"
)

# Supported containers: mp3, mp4, mpeg, mpga, m4a, wav, webm, ogg, flac
with open("interview.mp3", "rb") as audio_file:
    response = client.audio.transcriptions.create(
        model="scribe_v2",
        file=audio_file,
        response_format="verbose_json",
        timestamp_granularities=["segment"],
        language="en",
    )

print(response.text)
for seg in response.segments:
    print(f"{seg.start:.1f}s-{seg.end:.1f}s: {seg.text}")
import fs from 'fs';
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.OXYY_API_KEY,
  baseURL: 'https://api.oxyy.ai/v1'
});

const response = await client.audio.transcriptions.create({
  model: 'scribe_v2',
  file: fs.createReadStream('interview.mp3'),
  response_format: 'verbose_json',
  language: 'en',
});

console.log(response.text);
# multipart upload
curl https://api.oxyy.ai/v1/audio/transcriptions \
  -H "Authorization: Bearer $OXYY_API_KEY" \
  -F "model=scribe_v2" \
  -F "file=@interview.mp3" \
  -F "response_format=verbose_json" \
  -F "language=en"

# …or JSON with a hosted URL instead of an upload
curl https://api.oxyy.ai/v1/audio/transcriptions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OXYY_API_KEY" \
  -d '{"model": "scribe_v2", "file_url": "https://example.com/interview.mp3"}'
# Same inputs as /transcriptions; the transcript comes back in English.
curl https://api.oxyy.ai/v1/audio/translations \
  -H "Authorization: Bearer $OXYY_API_KEY" \
  -F "model=whisper-large-v3-turbo" \
  -F "file=@bengali-interview.mp3" \
  -F "response_format=json"

Phản hồi mẫu (verbose_json)

Phản hồi
{
  "task": "transcribe",
  "language": "en",
  "duration": 5.42,
  "text": "Hello, this is a transcription test.",
  "segments": [
    { "id": 0, "start": 0.0, "end": 2.1, "text": "Hello, this is" },
    { "id": 1, "start": 2.1, "end": 5.42, "text": "a transcription test." }
  ]
}

verbose_json được yêu cầu từ nhà cung cấp đúng như đã gửi. Ngoại lệ duy nhất là các định dạng dạng văn bản: text, srt và vtt được kết xuất ở đây từ một kết quả được tính giờ, vì vậy chúng hoạt động trên mọi nhà cung cấp.

Các model có sẵn