class AudioPlayback::File
An audio file
Attributes
num_channels[R]
path[R]
sample_rate[R]
size[R]
Public Class Methods
new(file_or_path)
click to toggle source
@param [::File, String] file_or_path
# File lib/audio-playback/file.rb, line 9 def initialize(file_or_path) @path = file_or_path.kind_of?(::File) ? file_or_path.path : file_or_path @file = RubyAudio::Sound.open(@path) @size = ::File.size(@path) @num_channels = @file.info.channels @sample_rate = @file.info.samplerate end
Public Instance Methods
read(options = {})
click to toggle source
@param [Hash] options @option options [IO] :logger @return [Array<Array<Float>>, Array<Float>] File
data
# File lib/audio-playback/file.rb, line 20 def read(options = {}) if logger = options[:logger] logger.puts("Reading audio file #{@path}") end buffer = RubyAudio::Buffer.float(@size, @num_channels) begin @file.seek(0) @file.read(buffer, @size) data = buffer.to_a rescue RubyAudio::Error end logger.puts("Finished reading audio file #{@path}") if logger data end