Class: OmniAI::Transcribe

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/transcribe.rb,
lib/omniai/transcribe/transcription.rb

Overview

An abstract class that provides a consistent interface for processing transcribe requests.

Usage:

class OmniAI::OpenAI::Transcribe < OmniAI::Transcribe
  module Model
    WHISPER_1 = "whisper-1"
  end

  protected

  # @return [Hash]
  def payload
    raise NotImplementedError, "#{self.class.name}#payload undefined"
  end

  # @return [String]
  def path
    raise NotImplementedError, "#{self.class.name}#path undefined"
  end
end

File.open('audio.wav', 'rb') do |file|
  client.transcribe(file, model: "...", format: :json)
end

Defined Under Namespace

Modules: Format, Language Classes: Transcription

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, client:, model:, language: nil, prompt: nil, temperature: nil, format: nil) ⇒ Transcribe

Returns a new instance of Transcribe.

Parameters:

  • io (String, Pathname, IO)

    required

  • client (OmniAI::Client)

    the client

  • model (String)

    required

  • language (String, nil) (defaults to: nil)

    optional

  • prompt (String, nil) (defaults to: nil)

    optional

  • temperature (Float, nil) (defaults to: nil)

    optional

  • format (String, nil) (defaults to: nil)

    optional



109
110
111
112
113
114
115
116
117
# File 'lib/omniai/transcribe.rb', line 109

def initialize(io, client:, model:, language: nil, prompt: nil, temperature: nil, format: nil)
  @io = io
  @client = client
  @model = model
  @language = language
  @prompt = prompt
  @temperature = temperature
  @format = format || Format::JSON
end

Class Method Details

.process!Object



98
99
100
# File 'lib/omniai/transcribe.rb', line 98

def self.process!(...)
  new(...).process!
end

Instance Method Details

#process!OmniAI::Transcribe::Transcription



122
123
124
125
126
127
128
129
# File 'lib/omniai/transcribe.rb', line 122

def process!
  response = request!
  raise HTTPError, response.flush unless response.status.ok?

  data = json? || verbose_json? ? response.parse : String(response.body)

  Transcription.parse(model: @model, format: @format, data:)
end