Skip to content

WaveFile::Reader doesn't work with pipe IO #36

@DimitriosLisenko

Description

@DimitriosLisenko

Hello!

I was trying to use this gem to record a wav file to STDOUT and then feed it to WaveFile::Reader to analyze in realtime. If I recall correctly, it was something along the lines of

IO.popen("rec -c 1 -t wav - 2>/dev/null") do |stdout|
  WaveFile::Reader.new(stdout) do |reader|
    # do stuff
  end
end

However, this results in the following exception:

.../wavefile-1.1.1/lib/wavefile/chunk_readers/riff_reader.rb:31:in `pos': Illegal seek (Errno::ESPIPE)
	from .../wavefile-1.1.1/lib/wavefile/chunk_readers/riff_reader.rb:31:in `read_until_data_chunk'
	from .../wavefile-1.1.1/lib/wavefile/chunk_readers/riff_reader.rb:10:in `initialize'
	from .../wavefile-1.1.1/lib/wavefile/reader.rb:45:in `new'
	from .../wavefile-1.1.1/lib/wavefile/reader.rb:45:in `initialize'
	...

which is because it's trying to seek on the IO, which is an invalid operation on a pipe.

I did also try record to a file instead of STDOUT and calling WaveFile::Reader on that, but because the file size kept increasing, that also resulted in something going wrong (I think because WaveFile::Reader#read_until_data_chunk tries to read until the end of the file). Also that means that the file keeps growing while the recording is ongoing, which is not ideal.

I ended up calling IO.popen("rec -c 1 -t s32 - 2>/dev/null") which outputs the audio amplitudes as signed 32-bit integers, and analyzing that directly.

The reason I'm opening this ticket is because I'm wondering whether analyzing an audio recording in realtime is an aim of this project, and if so, whether it's a planned feature or something that can be done now and I just missed something?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions