Class: RubyLLM::SpeechChunk
- Inherits:
-
Object
- Object
- RubyLLM::SpeechChunk
- Includes:
- RubyLLM::Support::Inspectable
- Defined in:
- lib/ruby_llm/speech_chunk.rb
Overview
A piece of generated audio, yielded by RubyLLM.speak as it arrives. Chunks are consecutive bytes of one recording, not separate audio files.
Constant Summary
Constants included from RubyLLM::Support::Inspectable
RubyLLM::Support::Inspectable::TRUNCATE_AT
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The raw audio bytes in this chunk.
-
#format ⇒ Object
readonly
The audio format name, such as "mp3" or "pcm".
-
#mime_type ⇒ Object
readonly
The MIME type of the audio, such as "audio/mpeg".
Instance Method Summary collapse
-
#initialize(data:, format:, mime_type: nil) ⇒ SpeechChunk
constructor
:nodoc:.
-
#inspect_attributes ⇒ Object
:nodoc:.
-
#to_blob ⇒ Object
Returns the raw audio bytes.
Methods included from RubyLLM::Support::Inspectable
#full_inspect, #inspect, #pretty_print
Constructor Details
#initialize(data:, format:, mime_type: nil) ⇒ SpeechChunk
:nodoc:
18 19 20 21 22 |
# File 'lib/ruby_llm/speech_chunk.rb', line 18 def initialize(data:, format:, mime_type: nil) # :nodoc: @data = data.b @format = format.to_s @mime_type = mime_type || Speech::MIME_TYPES.fetch(@format, "audio/#{@format}") end |
Instance Attribute Details
#data ⇒ Object (readonly)
The raw audio bytes in this chunk.
10 11 12 |
# File 'lib/ruby_llm/speech_chunk.rb', line 10 def data @data end |
#format ⇒ Object (readonly)
The audio format name, such as "mp3" or "pcm".
13 14 15 |
# File 'lib/ruby_llm/speech_chunk.rb', line 13 def format @format end |
#mime_type ⇒ Object (readonly)
The MIME type of the audio, such as "audio/mpeg".
16 17 18 |
# File 'lib/ruby_llm/speech_chunk.rb', line 16 def mime_type @mime_type end |
Instance Method Details
#inspect_attributes ⇒ Object
:nodoc:
29 30 31 |
# File 'lib/ruby_llm/speech_chunk.rb', line 29 def inspect_attributes # :nodoc: { format: format, data: "#{data.bytesize} bytes" } end |
#to_blob ⇒ Object
Returns the raw audio bytes. Alias for #data.
25 26 27 |
# File 'lib/ruby_llm/speech_chunk.rb', line 25 def to_blob data end |