Class: OmniAI::Speak
- Inherits:
-
Object
- Object
- OmniAI::Speak
- 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::Speak
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', 'wb') do |file|
client.speak('Sally sells seashells by the seashore.', format: OmniAI::Speak::Format::WAV) do |chunk|
file << chunk
end
end
Defined Under Namespace
Modules: Format
Constant Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input, client:, model:, voice:, speed: nil, format: DEFAULT_FORMAT) ⇒ Speak
constructor
A new instance of Speak.
- #process! {|chunk| ... } ⇒ Tempfile
Constructor Details
#initialize(input, client:, model:, voice:, speed: nil, format: DEFAULT_FORMAT) ⇒ Speak
Returns a new instance of Speak.
77 78 79 80 81 82 83 84 |
# File 'lib/omniai/speak.rb', line 77 def initialize(input, client:, model:, voice:, speed: nil, format: DEFAULT_FORMAT) @input = input @client = client @model = model @voice = voice @speed = speed @format = format end |
Class Method Details
.process!(input, client:, model:, voice:, speed: nil, format: DEFAULT_FORMAT) {|chunk| ... } ⇒ Tempfile
61 62 63 |
# File 'lib/omniai/speak.rb', line 61 def self.process!(input, client:, model:, voice:, speed: nil, format: DEFAULT_FORMAT, &) new(input, client:, model:, voice:, speed:, format:).process!(&) end |
Instance Method Details
#process! {|chunk| ... } ⇒ Tempfile
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/omniai/speak.rb', line 91 def process!(&block) response = request! raise HTTPError, response.flush unless response.status.ok? if block stream!(response:, &block) else fetch!(response:) end end |