Module: Awaaz::Properties

Included in:
Awaaz
Defined in:
lib/awaaz/properties.rb

Overview

Properties of audio

Instance Method Summary collapse

Instance Method Details

#duration(samples, sample_rate) ⇒ Float

Note:

The duration is computed as:

samples_count / sample_rate

Calculates the duration (in seconds) of an audio signal given the number of samples and the sample rate.

Examples:

samples = Numo::DFloat.new(44100) # 1 second of audio at 44.1 kHz
Awaaz.duration(samples, 44100)
# => 1.0

Parameters:

  • samples (Numo::NArray, Array, Object)

    The audio samples. This can be a Numo::NArray, Array, or any object that responds to ‘.shape` and returns a size array.

  • sample_rate (Integer, Float)

    The sampling rate (in Hz) of the audio signal.

Returns:

  • (Float)

    The duration of the audio signal in seconds. Returns ‘0.0` if either the number of samples or the sample rate is non-positive.

See Also:



30
31
32
33
34
35
# File 'lib/awaaz/properties.rb', line 30

def duration(samples, sample_rate)
  samples_count = samples.shape.max
  return 0.0 if samples_count <= 0 || sample_rate <= 0

  samples_count / sample_rate.to_f
end