#!/usr/bin/env ruby require "coreaudio" wav = CoreAudio::AudioFile.new("sample.wav", :read) m4a = CoreAudio::AudioFile.new("sample.m4a", :write, :format => :m4a, :rate => wav.rate, :channel => wav.channel) loop do buf = wav.read(1024) break if buf.empty? m4a.write(buf) end wav.close m4a.close