class RubyLLM::Transcription::Segment
A timed piece of a transcript: an entry of Transcription#segments or Transcription#words, or the TranscriptionChunk#segment a stream completed. Readers cover what providers share; [] and to_h reach the rest under the provider’s own field names.
transcription.segments.each do |segment| puts "#{segment.speaker} at #{segment.start}s: #{segment.text}" end
Public Instance Methods
Source
# File lib/ruby_llm/transcription/segment.rb, line 56 def ==(other) other.respond_to?(:to_h) && to_h == other.to_h.transform_keys(&:to_s) end
Returns true for a Segment or Hash holding the same fields.
Source
# File lib/ruby_llm/transcription/segment.rb, line 38 def [](key) @attributes[key.to_s] end
Returns the provider’s field named key, a String or Symbol.
Source
# File lib/ruby_llm/transcription/segment.rb, line 35 def end = self['end']
When the text ends, in seconds from the start of the audio.
Source
# File lib/ruby_llm/transcription/segment.rb, line 43 def fetch(key, ...) @attributes.fetch(key.to_s, ...) end
Returns the provider’s field named key the way Hash#fetch does.
Source
# File lib/ruby_llm/transcription/segment.rb, line 48 def key?(key) = @attributes.key?(key.to_s)
Returns true when the provider sent a field named key.
Source
# File lib/ruby_llm/transcription/segment.rb, line 29 def speaker = self['speaker'] || self['speaker_id']
The speaker label, or nil on models that do not separate speakers.
Source
# File lib/ruby_llm/transcription/segment.rb, line 32 def start = self['start']
When the text starts, in seconds from the start of the audio.
Source
# File lib/ruby_llm/transcription/segment.rb, line 26 def text = self['text'] || self['word'] || self['transcript']
The spoken text, or nil when the provider reports none.
Source
# File lib/ruby_llm/transcription/segment.rb, line 52 def to_h = @attributes.dup
Returns the provider’s fields as a Hash with String keys.