Sha256: c11da6b43f3cd872e36b97bc52fb279e7d4c6ad54bb1cd03517f4a152843ef40

Contents?: true

Size: 626 Bytes

Versions: 9

Compression:

Stored size: 626 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,
                               :channels => 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

9 entries across 9 versions & 1 rubygems

Version Path
coreaudio-0.0.12 examples/record_to_wave.rb
coreaudio-0.0.11 examples/record_to_wave.rb
coreaudio-0.0.10 examples/record_to_wave.rb
coreaudio-0.0.9 examples/record_to_wave.rb
coreaudio-0.0.8 examples/record_to_wave.rb
coreaudio-0.0.7 examples/record_to_wave.rb
coreaudio-0.0.6 examples/record_to_wave.rb
coreaudio-0.0.5 examples/record_to_wave.rb
coreaudio-0.0.4 examples/record_to_wave.rb