Class: Ragdoll::AudioContent
- Inherits:
-
Content
- Object
- ActiveRecord::Base
- Content
- Ragdoll::AudioContent
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
.stats ⇒ Object
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)
40
41
42
|
# File 'app/models/ragdoll/audio_content.rb', line 40
def audio_attached?
data.present?
end
|
#audio_content_type ⇒ Object
52
53
54
|
# File 'app/models/ragdoll/audio_content.rb', line 52
def audio_content_type
metadata.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.metadata = metadata.merge("content_type" => value)
end
|
#audio_data ⇒ Object
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_filename ⇒ Object
60
61
62
|
# File 'app/models/ragdoll/audio_content.rb', line 60
def audio_filename
metadata.dig("filename")
end
|
#audio_filename=(value) ⇒ Object
64
65
66
|
# File 'app/models/ragdoll/audio_content.rb', line 64
def audio_filename=(value)
self.metadata = metadata.merge("filename" => value)
end
|
#audio_size ⇒ Object
44
45
46
|
# File 'app/models/ragdoll/audio_content.rb', line 44
def audio_size
metadata.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.metadata = metadata.merge("file_size" => value)
end
|
#bitrate ⇒ Object
77
78
79
|
# File 'app/models/ragdoll/audio_content.rb', line 77
def bitrate
metadata.dig("bitrate")
end
|
#bitrate=(value) ⇒ Object
81
82
83
|
# File 'app/models/ragdoll/audio_content.rb', line 81
def bitrate=(value)
self.metadata = metadata.merge("bitrate" => value)
end
|
#channels ⇒ Object
85
86
87
|
# File 'app/models/ragdoll/audio_content.rb', line 85
def channels
metadata.dig("channels")
end
|
#channels=(value) ⇒ Object
89
90
91
|
# File 'app/models/ragdoll/audio_content.rb', line 89
def channels=(value)
self.metadata = metadata.merge("channels" => value)
end
|
#codec ⇒ Object
Audio format and technical details
69
70
71
|
# File 'app/models/ragdoll/audio_content.rb', line 69
def codec
metadata.dig("codec")
end
|
#codec=(value) ⇒ Object
73
74
75
|
# File 'app/models/ragdoll/audio_content.rb', line 73
def codec=(value)
self.metadata = metadata.merge("codec" => value)
end
|
#content_for_embedding ⇒ Object
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
|
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?
super
end
|
#should_generate_embeddings? ⇒ Boolean
Override should_generate_embeddings to check for transcript
117
118
119
|
# File 'app/models/ragdoll/audio_content.rb', line 117
def should_generate_embeddings?
content_for_embedding.present? && embeddings.empty?
end
|
#transcript ⇒ Object
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
|