Class: RubyLLM::SpeechChunk

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#dataObject (readonly)

The raw audio bytes in this chunk.



10
11
12
# File 'lib/ruby_llm/speech_chunk.rb', line 10

def data
  @data
end

#formatObject (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_typeObject (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_attributesObject

: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_blobObject

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