Class: Ragdoll::AudioContent

Inherits:
Content
  • Object
show all
Defined in:
app/models/ragdoll/audio_content.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Content

#character_count, #embedding_count, search_content, #word_count

Class Method Details

.statsObject



121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/models/ragdoll/audio_content.rb', line 121

def self.stats
  {
    total_audio_contents: count,
    by_model: group(:embedding_model).count,
    total_embeddings: joins(:embeddings).count,
    with_audio: with_audio.count,
    with_transcripts: with_transcripts.count,
    total_duration: sum(:duration),
    average_duration: average(:duration),
    average_audio_size: joins(:audio_attachment).average("active_storage_blobs.byte_size")
  }
end

Instance Method Details

#audio_attached?Boolean

Audio file technical properties (stored in content metadata - raw file data)

Returns:

  • (Boolean)


40
41
42
# File 'app/models/ragdoll/audio_content.rb', line 40

def audio_attached?
  data.present?
end

#audio_content_typeObject



52
53
54
# File 'app/models/ragdoll/audio_content.rb', line 52

def audio_content_type
  .dig("content_type")
end

#audio_content_type=(value) ⇒ Object



56
57
58
# File 'app/models/ragdoll/audio_content.rb', line 56

def audio_content_type=(value)
  self. = .merge("content_type" => value)
end

#audio_dataObject

Audio file data accessor



31
32
33
# File 'app/models/ragdoll/audio_content.rb', line 31

def audio_data
  data
end

#audio_data=(value) ⇒ Object



35
36
37
# File 'app/models/ragdoll/audio_content.rb', line 35

def audio_data=(value)
  self.data = value
end

#audio_filenameObject



60
61
62
# File 'app/models/ragdoll/audio_content.rb', line 60

def audio_filename
  .dig("filename")
end

#audio_filename=(value) ⇒ Object



64
65
66
# File 'app/models/ragdoll/audio_content.rb', line 64

def audio_filename=(value)
  self. = .merge("filename" => value)
end

#audio_sizeObject



44
45
46
# File 'app/models/ragdoll/audio_content.rb', line 44

def audio_size
  .dig("file_size") || 0
end

#audio_size=(value) ⇒ Object



48
49
50
# File 'app/models/ragdoll/audio_content.rb', line 48

def audio_size=(value)
  self. = .merge("file_size" => value)
end

#bitrateObject



77
78
79
# File 'app/models/ragdoll/audio_content.rb', line 77

def bitrate
  .dig("bitrate")
end

#bitrate=(value) ⇒ Object



81
82
83
# File 'app/models/ragdoll/audio_content.rb', line 81

def bitrate=(value)
  self. = .merge("bitrate" => value)
end

#channelsObject



85
86
87
# File 'app/models/ragdoll/audio_content.rb', line 85

def channels
  .dig("channels")
end

#channels=(value) ⇒ Object



89
90
91
# File 'app/models/ragdoll/audio_content.rb', line 89

def channels=(value)
  self. = .merge("channels" => value)
end

#codecObject

Audio format and technical details



69
70
71
# File 'app/models/ragdoll/audio_content.rb', line 69

def codec
  .dig("codec")
end

#codec=(value) ⇒ Object



73
74
75
# File 'app/models/ragdoll/audio_content.rb', line 73

def codec=(value)
  self. = .merge("codec" => value)
end

#content_for_embeddingObject

Override content for embedding to use transcript



102
103
104
# File 'app/models/ragdoll/audio_content.rb', line 102

def content_for_embedding
  transcript.presence || "Audio content without transcript"
end

#duration_formattedObject



93
94
95
96
97
98
99
# File 'app/models/ragdoll/audio_content.rb', line 93

def duration_formatted
  return "Unknown" unless duration

  minutes = (duration / 60).floor
  seconds = (duration % 60).round
  "#{minutes}:#{seconds.to_s.rjust(2, '0')}"
end

#generate_embeddings!Object



106
107
108
109
110
111
112
113
114
# File 'app/models/ragdoll/audio_content.rb', line 106

def generate_embeddings!
  return unless should_generate_embeddings?

  embedding_content = content_for_embedding
  return if embedding_content.blank?

  # Generate embeddings using the base class method
  super
end

#should_generate_embeddings?Boolean

Override should_generate_embeddings to check for transcript

Returns:

  • (Boolean)


117
118
119
# File 'app/models/ragdoll/audio_content.rb', line 117

def should_generate_embeddings?
  content_for_embedding.present? && embeddings.empty?
end

#transcriptObject

Audio content accessors - content field stores transcript for embedding



22
23
24
# File 'app/models/ragdoll/audio_content.rb', line 22

def transcript
  content
end

#transcript=(value) ⇒ Object



26
27
28
# File 'app/models/ragdoll/audio_content.rb', line 26

def transcript=(value)
  self.content = value
end