Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Openai Openai python Translations Create

From Leeroopedia
Knowledge Sources
Domains Audio, Translation
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for translating non-English audio to English text provided by the OpenAI Python SDK.

Description

The Translations resource provides a create() method that translates audio from any supported language into English text. Currently only the Whisper model (whisper-1) supports translation. Output formats include JSON, text, SRT, verbose JSON, and VTT.

Usage

Call client.audio.translations.create() with a non-English audio file.

Code Reference

Source Location

  • Repository: openai-python
  • File: src/openai/resources/audio/translations.py
  • Lines: L100-169 (sync), L243-312 (async)

Signature

class Translations(SyncAPIResource):
    def create(
        self,
        *,
        file: FileTypes,
        model: Union[str, AudioModel],
        prompt: str | NotGiven = NOT_GIVEN,
        response_format: Literal["json", "text", "srt", "verbose_json", "vtt"] | NotGiven = NOT_GIVEN,
        temperature: float | NotGiven = NOT_GIVEN,
    ) -> Translation | TranslationVerbose | str:
        """
        Translates audio into English text.

        Args:
            file: Audio file to translate.
            model: Model ID (currently "whisper-1").
            prompt: Optional guide prompt in English.
            response_format: Output format.
            temperature: Sampling temperature.
        """

Import

from openai import OpenAI
# Access via client.audio.translations.create()

I/O Contract

Inputs

Name Type Required Description
file FileTypes Yes Non-English audio file
model Union[str, AudioModel] Yes Model (currently "whisper-1")
prompt str No Guide prompt in English for context
response_format str No Output format (json, text, srt, verbose_json, vtt)
temperature float No Sampling temperature

Outputs

Name Type Description
translation (json) Translation Object with .text field (English)
translation (verbose_json) TranslationVerbose Object with .text and timing info
translation (text/srt/vtt) str English text in requested format

Usage Examples

Basic Translation

from openai import OpenAI

client = OpenAI()
translation = client.audio.translations.create(
    model="whisper-1",
    file=open("german_speech.mp3", "rb"),
)
print(translation.text)  # English translation

SRT Subtitles

srt_content = client.audio.translations.create(
    model="whisper-1",
    file=open("japanese_audio.mp3", "rb"),
    response_format="srt",
)
with open("subtitles.srt", "w") as f:
    f.write(srt_content)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment