Read and write .wav sound files in pure Ruby

For Example

Let’s say you have these three Wave files:

This program will concatenate them into one file called one_two_three.wav:

require "wavefile"
include WaveFile    # To avoid prefixing classes with "WaveFile::"

FILES_TO_APPEND = ["one.wav", "two.wav", "three.wav"]
OUTPUT_FORMAT =, :pcm_16, 44100)"one_two_three.wav", OUTPUT_FORMAT) do |writer|
  FILES_TO_APPEND.each do |file_name| do |buffer|

Intrigued? Check out more examples.

Don’t have any idea what this code means? Check out the Getting Started guide.


First, install the WaveFile gem from

gem install wavefile

...and include it in your Ruby program:

require "wavefile"

...or Gemfile:

gem "wavefile"

Note: It’s recommended that you use a Ruby version manager such as rvm or rbenv. But if using the system Ruby that comes pre-installed on MacOS, you should used sudo gem install wavefile. Otherwise you might run into a file permission error.

Who Made This?

Joel Strait did.