Noizu.OpenAI.Api.Audio (Noizu Labs: OpenAI v0.1.3)

Noizu.OpenAI.Api.Audio is a module that provides functionality for transcribing and translating audio using OpenAI's API.

This module offers two main functions:

  1. transcribe/3 - Transcribes the given audio file using a specified prompt and options.
  2. translate/3 - Translates the given audio file using a specified prompt and options.

usage

Usage

{:ok, transcript} = Noizu.OpenAI.Api.Audio.transcribe(audio, prompt, options)
{:ok, translation} = Noizu.OpenAI.Api.Audio.translate(audio, prompt, options)

Link to this section Summary

Functions

Transcribes audio using the specified model.

Translates audio using the specified model.

Link to this section Types

Link to this type

transcribe_options()

@type transcribe_options() ::
  %{
    optional(:model) =>
      Noizu.OpenAI.model_option(transcribe_supported_models()),
    optional(:response_format) => Noizu.OpenAI.response_format_option(),
    optional(:prompt) => String.t(),
    optional(:temperature) => Noizu.OpenAI.temperature_option(),
    optional(:language) => Noizu.OpenAI.language_option(),
    optional(:stream) => Noizu.OpenAI.stream_option()
  }
  | Keyword.t()
Link to this type

transcribe_response()

@type transcribe_response() :: map()
Link to this type

transcribe_supported_models()

@type transcribe_supported_models() :: :"whisper-1" | atom()
Link to this type

translate_audio_options()

@type translate_audio_options() ::
  %{
    optional(:model) =>
      Noizu.OpenAI.model_option(translate_audio_supported_models()),
    optional(:response_format) => Noizu.OpenAI.response_format_option(),
    optional(:prompt) => String.t(),
    optional(:temperature) => Noizu.OpenAI.temperature_option(),
    optional(:stream) => Noizu.OpenAI.stream_option()
  }
  | Keyword.t()
Link to this type

translate_audio_response()

@type translate_audio_response() :: map()
Link to this type

translate_audio_supported_models()

@type translate_audio_supported_models() :: :"whisper-1" | atom()

Link to this section Functions

Link to this function

transcribe(audio, prompt, options \\ nil)

@spec transcribe(
  audio :: String.t(),
  prompt :: String.t(),
  options :: transcribe_options()
) ::
  {:ok, transcribe_response()} | {:error, term()}

Transcribes audio using the specified model.

parameters

Parameters

  • audio: The URL of the audio file to transcribe
  • prompt: The prompt or instruction for the transcription
  • options: A map or keyword list of options, such as model, response_format, temperature, language, and stream

returns

Returns

Returns a tuple {:ok, response} on successful transcription, where response is a map containing the transcription result. Returns {:error, term} on failure, where term contains error details.

example

Example

audio_url = "https://your_audio_url_here"
prompt = "Transcribe this audio."
{:ok, response} = Noizu.OpenAI.transcribe(audio_url, prompt)
Link to this function

translate(audio, prompt, options \\ nil)

@spec translate(
  audio :: String.t(),
  prompt :: String.t(),
  options :: translate_audio_options()
) ::
  {:ok, translate_audio_response()} | {:error, term()}

Translates audio using the specified model.

parameters

Parameters

  • audio: The URL of the audio file to translate
  • prompt: The prompt or instruction for the translation
  • options: A map or keyword list of options, such as model, response_format, temperature, and stream

returns

Returns

Returns a tuple {:ok, response} on successful translation, where response is a map containing the translation result. Returns {:error, term} on failure, where term contains error details.

example

Example

audio_url = "https://your_audio_url_here"
prompt = "Translate this audio to English."
{:ok, response} = Noizu.OpenAI.translate_audio(audio_url, prompt)