Class: OpenAI::Resources::Audio::Translations

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/resources/audio/translations.rb,
sig/openai/resources/audio/translations.rbs

Overview

Turn audio into text or text into audio.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Translations

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Translations.

Parameters:



68
69
70
# File 'lib/openai/resources/audio/translations.rb', line 68

def initialize(client:)
  @client = client
end

Instance Method Details

#create(file:, model:, prompt: nil, response_format: nil, temperature: nil, request_options: {}) ⇒ OpenAI::Models::Audio::Translation, OpenAI::Models::Audio::TranslationVerbose

Translates audio into English.

String, StringIO, and pathless IO inputs are sent with generic upload metadata. Use OpenAI::FilePart when you need to override the filename or content type.

Parameters:

  • file (Pathname, StringIO, IO, String, OpenAI::FilePart)

    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.

    String, StringIO, and pathless IO inputs are sent with generic upload metadata. Use OpenAI::FilePart when you need to override the filename or content type.

  • model (String, Symbol, OpenAI::Models::AudioModel)

    ID of the model to use. Only whisper-1 (which is powered by our open source Whisper V2 model) is currently available.

  • 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 (Symbol, OpenAI::Models::Audio::TranslationCreateParams::ResponseFormat)

    The format of the output, in one of these options: json, text, srt, verbose_json, or vtt.

  • temperature (Float)

    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.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/openai/resources/audio/translations.rb', line 52

def create(params)
  parsed, options = OpenAI::Audio::TranslationCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "audio/translations",
    headers: {"content-type" => "multipart/form-data"},
    body: parsed,
    model: OpenAI::Models::Audio::TranslationCreateResponse,
    security: {bearer_auth: true},
    options: options
  )
end