Class: OmniAI::Speak

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/speak.rb

Overview

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

Usage:

class OmniAI::OpenAI::Speak < OmniAI::Speakw
  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

client.transcribe(File.open("..."), model: "...", format: :json)

Defined Under Namespace

Modules: Format

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, client:, model:, voice:, speed: nil, format: nil) ⇒ Speak

Returns a new instance of Speak.

Parameters:

  • client (OmniAI::Client)

    required

  • input (String)

    required

  • model (String)

    required

  • voice (String)

    required

  • speed (Float) (defaults to: nil)

    optional

  • format (String) (defaults to: nil)

    optional (default “aac”):

    • “aac”

    • “mp3”

    • “flac”

    • “opus”

    • “pcm”

    • “wav”



71
72
73
74
75
76
77
78
# File 'lib/omniai/speak.rb', line 71

def initialize(input, client:, model:, voice:, speed: nil, format: nil)
  @input = input
  @client = client
  @model = model
  @voice = voice
  @speed = speed
  @format = format
end

Class Method Details

.process!(input, client:, model:, voice:, speed: nil, format: nil) {|chunk| ... } ⇒ Tempfile

Parameters:

  • client (OmniAI::Client)

    required

  • input (String)

    required

  • model (String)

    required

  • voice (String)

    required

  • speed (Float) (defaults to: nil)

    optional

  • format (String) (defaults to: nil)

    optional (default “aac”):

    • “aac”

    • “mp3”

    • “flac”

    • “opus”

    • “pcm”

    • “wav”

Yields:

  • (chunk)

Returns:

  • (Tempfile)

Raises:



55
56
57
# File 'lib/omniai/speak.rb', line 55

def self.process!(input, client:, model:, voice:, speed: nil, format: nil, &)
  new(input, client:, model:, voice:, speed:, format:).process!(&)
end

Instance Method Details

#process! {|chunk| ... } ⇒ Tempfile

Yields:

  • (chunk)

Returns:

  • (Tempfile)

Raises:



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/omniai/speak.rb', line 85

def process!(&block)
  response = request!

  raise HTTPError, response.flush unless response.status.ok?

  if block
    stream!(response:, &block)
  else
    fetch!(response:)
  end
end