Class: RubyLLM::Transcription

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

Overview

Represents a transcription of audio content.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, model:, **attributes) ⇒ Transcription

Returns a new instance of Transcription.



8
9
10
11
12
13
14
15
16
# File 'lib/ruby_llm/transcription.rb', line 8

def initialize(text:, model:, **attributes)
  @text = text
  @model = model
  @language = attributes[:language]
  @duration = attributes[:duration]
  @segments = attributes[:segments]
  @input_tokens = attributes[:input_tokens]
  @output_tokens = attributes[:output_tokens]
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#input_tokensObject (readonly)

Returns the value of attribute input_tokens.



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

def input_tokens
  @input_tokens
end

#languageObject (readonly)

Returns the value of attribute language.



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

def language
  @language
end

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

#output_tokensObject (readonly)

Returns the value of attribute output_tokens.



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

def output_tokens
  @output_tokens
end

#segmentsObject (readonly)

Returns the value of attribute segments.



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

def segments
  @segments
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.transcribe(audio_file, **kwargs) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_llm/transcription.rb', line 18

def self.transcribe(audio_file, **kwargs)
  model = kwargs.delete(:model)
  language = kwargs.delete(:language)
  provider = kwargs.delete(:provider)
  assume_model_exists = kwargs.delete(:assume_model_exists) { false }
  context = kwargs.delete(:context)
  options = kwargs

  config = context&.config || RubyLLM.config
  model ||= config.default_transcription_model
  model, provider_instance = Models.resolve(model, provider: provider, assume_exists: assume_model_exists,
                                                   config: config)
  model_id = model.id

  provider_instance.transcribe(audio_file, model: model_id, language:, **options)
end