Audio Translation
A full list of models can be viewed on the Models page or retrieved dynamically via API endpoints: https://openai.bothub.chat/v1/models and https://bothub.chat/api/v2/replicate/v1/models
The audio translation API allows you to convert speech from audio files into text in English. Unlike standard transcription, where the result is returned in the language of the original recording, translation always returns text in English, regardless of the source audio's language.
This capability is especially useful when processing interviews, calls, podcasts, video recordings, and other multilingual content. For example, you can automatically get English subtitles for videos or translate voice messages for further analysis.
The whisper-1 model is used for audio translation. It is built on OpenAI's Whisper and supports a large number of languages, and also handles noisy speech and long recordings well.
Supported Formats
The API supports mp3, mp4, mpeg, mpga, m4a, wav, and webm formats.
Basic Example
- JS
- Python
- Go
- cURL
import OpenAI from "openai";
import fs from "fs";
const openai = new OpenAI({
apiKey: "<your_access_token>",
baseURL: "https://openai.bothub.chat/v1",
});
async function main() {
const translation = await openai.audio.translations.create({
file: fs.createReadStream("/path/to/audio.mp3"),
model: "whisper-1",
});
console.log(translation.text);
}
main();
from openai import OpenAI
client = OpenAI(
api_key="<your_access_token>",
base_url="https://openai.bothub.chat/v1",
)
audio_file = open("/path/to/audio.mp3", "rb")
translation = client.audio.translations.create(
model="whisper-1",
file=audio_file,
)
print(translation.text)
package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("<your_access_token>"),
option.WithBaseURL("https://openai.bothub.chat/v1"),
)
file, err := os.Open("/path/to/audio.mp3")
if err != nil {
panic(err)
}
defer file.Close()
translation, err := client.Audio.Translations.New(context.Background(), openai.AudioTranslationNewParams{
Model: openai.AudioModelWhisper1,
File: openai.File(file, "audio.mp3", "audio/mpeg"),
})
if err != nil {
panic(err)
}
fmt.Println(translation.Text)
}
curl https://openai.bothub.chat/v1/audio/translations \
-H "Authorization: Bearer <your_access_token>" \
-H "Content-Type: multipart/form-data" \
-F file="@/path/to/audio.mp3" \
-F model="whisper-1"
Advanced JSON Response
In addition to a standard text response, the API supports the verbose_json format. It allows you to obtain additional information about the translation result, including text segments, timestamps, and service metadata.
To use the advanced response format, pass the parameter response_format: "verbose_json".
- JS
- Python
- Go
- cURL
const translation = await openai.audio.translations.create({
file: fs.createReadStream("/path/to/audio.mp3"),
model: "whisper-1",
response_format: "verbose_json",
});
console.log(translation.text);
console.log(translation.segments);
translation = client.audio.translations.create(
model="whisper-1",
file=audio_file,
response_format="verbose_json",
)
print(translation.text)
print(translation.segments)
translation, err := client.Audio.Translations.New(context.Background(), openai.AudioTranslationNewParams{
Model: openai.AudioModelWhisper1,
File: openai.File(file, "audio.mp3", "audio/mpeg"),
ResponseFormat: openai.AudioTranslationNewParamsResponseFormatVerboseJSON,
})
if err != nil {
panic(err)
}
fmt.Println(translation.Text)
fmt.Println(translation.Segments)
curl https://openai.bothub.chat/v1/audio/translations \
-H "Authorization: Bearer <your_access_token>" \
-H "Content-Type: multipart/form-data" \
-F file="@/path/to/audio.mp3" \
-F model="whisper-1" \
-F response_format="verbose_json"
Main Parameters
| Parameter | Type | Description |
|---|---|---|
file | file | Audio file for translation |
model | string | Translation model (whisper-1) |
prompt | string | Additional context to improve quality |
response_format | string | Response format (json, text, verbose_json, srt, vtt) |
temperature | number | Randomness/variability level of generation |
Recommendations
For more accurate results, it is recommended to use recordings with high-quality audio and minimal background noise. If you are working with long audio files, it is better to split them into several parts. Use the verbose_json format to work with timecodes and text segments.