Audio
Create a translation
Creates a translation from the supplied request.
Treść żądania
The multipart request body.
file
OpenAI.CreateTranslationRequest
wymagane
The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. The request must include enough format metadata for the file to be identified. We recommend an extension-bearing filename and an appropriate content type.
model
string | enum
wymagane
ID of the model to use. Only whisper-1 (which is powered by our open source Whisper V2 model) is currently available.
enum
prompt
string
An optional text to guide the model's style or continue a previous audio segment. The prompt should be in English.
response_format
enum
The format of the output, in one of these options: json, text, srt, verbose_json, or vtt.
temperature
OpenAI.CreateTranslationRequest
The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.
Odpowiedzi
The request has succeeded.
Treść
language
string
wymagane
The language of the output translation (always english).
duration
integer
wymagane
The duration of the input audio.
text
string
wymagane
The translated text.
segments
OpenAI.TranscriptionSegment[]
Segments of the translated text and their corresponding details.
Żądanie
curl https://api.openai.com/v1/audio/translations \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F file="@/path/to/file/german.m4a" \
-F model="whisper-1"
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
translation = client.audio.translations.create(
file=b"Example data",
model="whisper-1",
)
print(translation)
import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI();
async function main() {
const translation = await openai.audio.translations.create({
file: fs.createReadStream("speech.mp3"),
model: "whisper-1",
});
console.log(translation.text);
}
main();
using System;
using OpenAI.Audio;
string audioFilePath = "audio.mp3";
AudioClient client = new(
model: "whisper-1",
apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")
);
AudioTranscription transcription = client.TranscribeAudio(audioFilePath);
Console.WriteLine($"{transcription.Text}");
import fs from 'fs';
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});
const translation = await client.audio.translations.create({
file: fs.createReadStream('speech.mp3'),
model: 'whisper-1',
});
console.log(translation);
package main
import (
"bytes"
"context"
"fmt"
"io"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("My API Key"),
)
translation, err := client.Audio.Translations.New(context.TODO(), openai.AudioTranslationNewParams{
File: io.Reader(bytes.NewBuffer([]byte("Example data"))),
Model: openai.AudioModelWhisper1,
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v
", translation)
}
package com.openai.example;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.audio.AudioModel;
import com.openai.models.audio.translations.TranslationCreateParams;
import com.openai.models.audio.translations.TranslationCreateResponse;
import java.io.ByteArrayInputStream;
public final class Main {
private Main() {}
public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
TranslationCreateParams params = TranslationCreateParams.builder()
.file(new ByteArrayInputStream("Example data".getBytes()))
.model(AudioModel.WHISPER_1)
.build();
TranslationCreateResponse translation = client.audio().translations().create(params);
}
}
require "openai"
openai = OpenAI::Client.new(api_key: "My API Key")
translation = openai.audio.translations.create(file: StringIO.new("Example data"), model: :"whisper-1")
puts(translation)
Response
{
"text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?"
}