Skip to Content Skip to Search

class ActiveStorage::Analyzer::AudioAnalyzer

Active Storage Audio Analyzer

Extracts duration (seconds), bit_rate (bits/s), sample_rate (hertz) and tags (internal metadata) from an audio blob.

Example:

ActiveStorage::Analyzer::AudioAnalyzer.new(blob).metadata
# => { duration: 5.0, bit_rate: 320340, sample_rate: 44100, tags: { encoder: "Lavc57.64", ... } }

This analyzer requires the FFmpeg system library, which is not provided by Rails.

Inherits From

Public class methods

Source code GitHub
# File activestorage/lib/active_storage/analyzer/audio_analyzer.rb, line 15
def self.accept?(blob)
  blob.audio?
end

Public instance methods

Source code GitHub
# File activestorage/lib/active_storage/analyzer/audio_analyzer.rb, line 19
def metadata
  { duration: duration, bit_rate: bit_rate, sample_rate: sample_rate, tags: tags }.compact
end

Definition files