Class: Awaaz::Decoders::WavefileDecoder

Inherits:
BaseDecoder show all
Includes:
Utils::ViaShell
Defined in:
lib/awaaz/decoders/wavefile_decoder.rb

Overview

The WavefileDecoder is responsible for decoding ‘.wav` audio files into raw PCM data that can be processed by the Awaaz audio pipeline.

This decoder supports multiple decoding strategies:

  1. Soundread — a Ruby-level ‘.wav` file reader.

  2. **Shell-based decoding** — for raw audio extraction.

The decoder will choose a decoding method based on availability of decoders and the configured options.

See Also:

Since:

  • 0.1.0

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDecoder

#available_options, #initialize, load, set_available_options

Constructor Details

This class inherits a constructor from Awaaz::Decoders::BaseDecoder

Class Method Details

.default_available_optionsObject

Sets the available decoding options for this decoder. Defaults to the base options plus the ‘:soundread` option.

Since:

  • 0.1.0



27
# File 'lib/awaaz/decoders/wavefile_decoder.rb', line 27

set_available_options default_available_options + [:soundread]

Instance Method Details

#loadArray<(Numo::NArray, Integer, Integer)>

Note:

The decoding method is chosen dynamically:

  • If there are no available decoders, or if ‘:soundread` is enabled, it will use the BaseDecoder#soundread method.

  • Otherwise, it will use shell based decoding.

Loads and decodes a ‘.wav` file into raw PCM data.

Returns:

  • (Array<(Numo::NArray, Integer, Integer)>)

    Returns an array containing:

    • samples: A [Numo::NArray] of decoded audio samples

    • sample_rate: Integer sample rate (Hz)

    • channels: Integer number of audio channels

Raises:

  • (AgumentError)

    if the file does not have a ‘.wav` extension.

Since:

  • 0.1.0



46
47
48
49
50
51
52
53
54
# File 'lib/awaaz/decoders/wavefile_decoder.rb', line 46

def load
  output_data = if no_decoders? || soundread?
                  soundread
                else
                  shell_load sox_options: { raw: true }
                end

  process(*output_data)
end