Class: ActiveStorage::Audio::Analyzer
- Inherits:
-
ActiveStorage::Analyzer
- Object
- ActiveStorage::Analyzer
- ActiveStorage::Audio::Analyzer
- Defined in:
- lib/active_storage/audio/analyzer.rb
Overview
Uses ‘ffprobe` to quickly find information about the track file, such as duration, bitrate, sample rate, and its codec.
Class Method Summary collapse
-
.accept?(blob) ⇒ Boolean
Tests whether the given ‘blob` is an audio file.
Instance Method Summary collapse
-
#bit_rate ⇒ Float
Bit rate of this audio file, e.g.
-
#channel_layout ⇒ String
Layout of channels.
-
#channels ⇒ Integer
Number of audio channels (1 for mono, 2 for stereo).
-
#codec ⇒ String
Codec used to encode this audio file.
-
#duration ⇒ Float
Duration of this audio file in seconds.
-
#metadata ⇒ Hash
Metadata to add to the blob.
-
#sample_rate ⇒ Float
Sample rate of this audio file, e.g.
Class Method Details
.accept?(blob) ⇒ Boolean
Tests whether the given ‘blob` is an audio file. If so, this file will be analyzed by the `Audio::Analyzer`.
13 14 15 |
# File 'lib/active_storage/audio/analyzer.rb', line 13 def self.accept?(blob) blob.audio? end |
Instance Method Details
#bit_rate ⇒ Float
Bit rate of this audio file, e.g. ‘16.0`
41 42 43 |
# File 'lib/active_storage/audio/analyzer.rb', line 41 def bit_rate stream['bit_rate'].to_f end |
#channel_layout ⇒ String
Layout of channels.
69 70 71 |
# File 'lib/active_storage/audio/analyzer.rb', line 69 def channel_layout stream['channel_layout'] end |
#channels ⇒ Integer
Number of audio channels (1 for mono, 2 for stereo)
62 63 64 |
# File 'lib/active_storage/audio/analyzer.rb', line 62 def channels stream['channels'].to_i end |
#codec ⇒ String
Codec used to encode this audio file.
55 56 57 |
# File 'lib/active_storage/audio/analyzer.rb', line 55 def codec stream['codec'] end |
#duration ⇒ Float
Duration of this audio file in seconds.
34 35 36 |
# File 'lib/active_storage/audio/analyzer.rb', line 34 def duration stream['duration'].to_f end |
#metadata ⇒ Hash
Metadata to add to the blob. Any empty values are omitted.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_storage/audio/analyzer.rb', line 20 def { duration: duration, bit_rate: bit_rate, sample_rate: sample_rate, codec: codec, channels: channels, channel_layout: channel_layout }.compact end |
#sample_rate ⇒ Float
Sample rate of this audio file, e.g. ‘44.1`
48 49 50 |
# File 'lib/active_storage/audio/analyzer.rb', line 48 def sample_rate stream['sample_rate'].to_i end |