Class: RubyLLM::Pollinations::AudioOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/pollinations/audio_output.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data: nil, mime_type: nil, model_id: nil, duration: nil) ⇒ AudioOutput

Returns a new instance of AudioOutput.



8
9
10
11
12
13
# File 'lib/ruby_llm/pollinations/audio_output.rb', line 8

def initialize(data: nil, mime_type: nil, model_id: nil, duration: nil)
  @data = data
  @mime_type = mime_type
  @model_id = model_id
  @duration = duration
end

Instance Attribute Details

#data ⇒ Object (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/ruby_llm/pollinations/audio_output.rb', line 6

def data
  @data
end

#duration ⇒ Object (readonly)

Returns the value of attribute duration.



6
7
8
# File 'lib/ruby_llm/pollinations/audio_output.rb', line 6

def duration
  @duration
end

#mime_type ⇒ Object (readonly)

Returns the value of attribute mime_type.



6
7
8
# File 'lib/ruby_llm/pollinations/audio_output.rb', line 6

def mime_type
  @mime_type
end

#model_id ⇒ Object (readonly)

Returns the value of attribute model_id.



6
7
8
# File 'lib/ruby_llm/pollinations/audio_output.rb', line 6

def model_id
  @model_id
end

Class Method Details

.speak(input, model: nil, voice: nil, provider: nil, assume_model_exists: false, context: nil, **options) ⇒ Object

rubocop:disable Metrics/ParameterLists



30
31
32
33
34
35
36
37
38
# File 'lib/ruby_llm/pollinations/audio_output.rb', line 30

def self.speak(input, model: nil, voice: nil, provider: nil, assume_model_exists: false, context: nil, **options) # rubocop:disable Metrics/ParameterLists
  config = context&.config || RubyLLM.config
  model ||= config.default_audio_model
  model, provider_instance = RubyLLM::Models.resolve(model, provider: provider,
                                                             assume_exists: assume_model_exists, config: config)
  model_id = model.id

  provider_instance.speak(input, model: model_id, voice: voice, **options)
end

Instance Method Details

#base64? ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/ruby_llm/pollinations/audio_output.rb', line 15

def base64?
  !@data.nil?
end

#save(path) ⇒ Object



25
26
27
28
# File 'lib/ruby_llm/pollinations/audio_output.rb', line 25

def save(path)
  File.binwrite(File.expand_path(path), to_blob)
  path
end

#to_blob ⇒ Object



19
20
21
22
23
# File 'lib/ruby_llm/pollinations/audio_output.rb', line 19

def to_blob
  return unless base64?

  Base64.decode64(@data)
end