Class: RubyLLM::TranscriptionChunk
- Inherits:
-
Object
- Object
- RubyLLM::TranscriptionChunk
- Includes:
- Support::Inspectable
- Defined in:
- lib/ruby_llm/transcription_chunk.rb
Overview
A TranscriptionChunk is one event from a streaming transcription. RubyLLM.transcribe yields these to its block as the provider transcribes the audio, then returns the final Transcription.
RubyLLM.transcribe("meeting.wav", model: "gpt-4o-transcribe") do |chunk|
print chunk.delta if chunk.delta?
end
Constant Summary collapse
- DELTA =
Text deltas, arriving as the model transcribes.
'transcript.text.delta'- PARTIAL =
A tentative transcript that may change before its segment completes.
'transcript.text.partial'- SEGMENT =
A completed segment, on models that return timed or diarized segments.
'transcript.text.segment'- DONE =
The final event, carrying the complete transcript.
'transcript.text.done'
Constants included from Support::Inspectable
Support::Inspectable::TRUNCATE_AT
Instance Attribute Summary collapse
-
#delta ⇒ Object
readonly
The text added by this event, or
nilfor events that add no text. -
#raw ⇒ Object
readonly
The parsed provider event, for fields RubyLLM does not normalize.
-
#segment ⇒ Object
readonly
The segment this event completed as a Hash, or
nil. -
#text ⇒ Object
readonly
The transcript for a partial event or the complete final transcript.
-
#type ⇒ Object
readonly
The normalized event type, such as "transcript.text.delta".
Instance Method Summary collapse
-
#delta? ⇒ Boolean
Whether this event carries a text delta.
-
#done? ⇒ Boolean
Whether this is the final event of the transcription.
-
#initialize(type:, delta: nil, text: nil, segment: nil, raw: nil) ⇒ TranscriptionChunk
constructor
:nodoc:.
-
#inspect_attributes ⇒ Object
:nodoc:.
-
#partial? ⇒ Boolean
Whether this is a tentative transcript, replacing the previous partial.
-
#segment? ⇒ Boolean
Whether this event completed a segment.
Methods included from Support::Inspectable
#full_inspect, #inspect, #pretty_print
Constructor Details
#initialize(type:, delta: nil, text: nil, segment: nil, raw: nil) ⇒ TranscriptionChunk
:nodoc:
44 45 46 47 48 49 50 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 44 def initialize(type:, delta: nil, text: nil, segment: nil, raw: nil) # :nodoc: @type = type @delta = delta @text = text @segment = segment @raw = raw end |
Instance Attribute Details
#delta ⇒ Object (readonly)
The text added by this event, or nil for events that add no text.
32 33 34 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 32 def delta @delta end |
#raw ⇒ Object (readonly)
The parsed provider event, for fields RubyLLM does not normalize.
42 43 44 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 42 def raw @raw end |
#segment ⇒ Object (readonly)
The segment this event completed as a Hash, or nil. Diarization
models label each segment with a speaker.
39 40 41 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 39 def segment @segment end |
#text ⇒ Object (readonly)
The transcript for a partial event or the complete final transcript.
35 36 37 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 35 def text @text end |
#type ⇒ Object (readonly)
The normalized event type, such as "transcript.text.delta".
29 30 31 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 29 def type @type end |
Instance Method Details
#delta? ⇒ Boolean
Whether this event carries a text delta.
53 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 53 def delta? = !delta.nil? |
#done? ⇒ Boolean
Whether this is the final event of the transcription.
62 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 62 def done? = type == DONE |
#inspect_attributes ⇒ Object
:nodoc:
64 65 66 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 64 def inspect_attributes # :nodoc: { type: type, delta: delta, text: text, segment: segment } end |
#partial? ⇒ Boolean
Whether this is a tentative transcript, replacing the previous partial.
56 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 56 def partial? = type == PARTIAL |
#segment? ⇒ Boolean
Whether this event completed a segment.
59 |
# File 'lib/ruby_llm/transcription_chunk.rb', line 59 def segment? = !segment.nil? |