Class: Ragdoll::AudioToTextService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ragdoll/audio_to_text_service.rb

Defined Under Namespace

Classes: TranscriptionError

Constant Summary collapse

DEFAULT_OPTIONS =
{
  model: "whisper-1",
  provider: :openai,
  temperature: 0.0,
  language: nil # Auto-detect
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ AudioToTextService

Returns a new instance of AudioToTextService.



20
21
22
23
# File 'app/services/ragdoll/audio_to_text_service.rb', line 20

def initialize(**options)
  @options = DEFAULT_OPTIONS.merge(options)
  configure_transcription_service
end

Class Method Details

.transcribe(file_path, **options) ⇒ Object



16
17
18
# File 'app/services/ragdoll/audio_to_text_service.rb', line 16

def self.transcribe(file_path, **options)
  new(**options).transcribe(file_path)
end

Instance Method Details

#supported_formatsObject



45
46
47
# File 'app/services/ragdoll/audio_to_text_service.rb', line 45

def supported_formats
  %w[.mp3 .wav .m4a .flac .ogg .aac .wma .mp4 .mov .avi .webm]
end

#transcribe(file_path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/services/ragdoll/audio_to_text_service.rb', line 25

def transcribe(file_path)
  return "" unless File.exist?(file_path)
  return "" unless audio_file?(file_path)

  begin
    # Use RubyLLM for transcription
    # Note: This is a placeholder implementation
    # Real implementation would depend on the transcription service available

    if transcription_available?
      perform_transcription(file_path)
    else
      generate_fallback_transcript(file_path)
    end
  rescue StandardError => e
    puts "Warning: Audio transcription failed (#{e.message}), using fallback"
    generate_fallback_transcript(file_path)
  end
end