Sha256: 3487b08b46cdf969ff59d7801fd43ea6158ee114a13019ca8d65d93adf47c2f2

Contents?: true

Size: 625 Bytes

Versions: 3

Compression:

Stored size: 625 Bytes

Contents

require "coreaudio"

dev = CoreAudio.default_input_device
buf = dev.input_buffer(1024)

wav = CoreAudio::AudioFile.new("sample.wav", :write, :format => :wav,
                               :rate => dev.nominal_rate,
                               :channel => dev.input_stream.channels)

samples = 0
th = Thread.start do
  loop do
    w = buf.read(4096)
    samples += w.size / dev.input_stream.channels
    wav.write(w)
  end
end

buf.start;
$stdout.print "RECORDING..."
$stdout.flush
sleep 5;
buf.stop
$stdout.puts "done."
th.kill.join

wav.close

puts "#{samples} samples read."
puts "#{buf.dropped_frame} frame dropped."

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coreaudio-0.0.3 examples/record_to_wave.rb
coreaudio-0.0.2 examples/record_to_wave.rb
coreaudio-0.0.1 examples/record_to_wave.rb