Learn R Programming

openaiRtools (version 0.2.2)

create_translation: Translate Audio to English Text (Convenience Function)

Description

Shortcut that creates an OpenAI client from the OPENAI_API_KEY environment variable and calls client$audio$translations$create(). Always produces English output regardless of source language.

Usage

create_translation(file, model = "whisper-1", ...)

Value

A list with $text containing the English translation (for default JSON format), or a character string for response_format = "text".

Arguments

file

Character. Required. Path to the local audio file. Supported: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm (max 25 MB).

model

Character. Whisper model. Default: "whisper-1".

...

Additional parameters passed to AudioTranslationsClient$create(), such as prompt, response_format, temperature.

Examples

Run this code
if (FALSE) {
Sys.setenv(OPENAI_API_KEY = "sk-xxxxxx")

# Translate a Chinese audio file to English
result <- create_translation("chinese_speech.mp3")
cat(result$text) # Output is always in English
}

Run the code above in your browser using DataLab