Project

easy_audio

0.01
No commit activity in last 3 years
No release in over 3 years
EasyAudio allows you to play or record from your sound card.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

EasyAudio

Gem Version

EasyAudio is a simplified wrapper for the portaudio library, which allows to you play or record audio directly from your sound card.

Installing

$ gem install easy_audio

Note: if you are on a Linux or Windows machine you will need to manually install portaudio to a location in your library paths. The gem will attempt to install this automatically on OS X through Homebrew.

Usage

Here's how you can easily play a sine wave at 440hz:

require 'easy_audio'

EasyAudio.easy_open(&EasyAudio::Waveforms::SINE)
sleep 2 # play for 2 seconds

Play a custom waveform (a cosine wave):

require 'easy_audio'

EasyAudio.easy_open { Math.cos(Math::PI * 2 * step) }
sleep 1

Here's a triangle wave that increases its frequency over 3 seconds:

require 'easy_audio'

stream = EasyAudio.easy_open(freq: 220, &EasyAudio::Waveforms::TRIANGLE)
Thread.new { loop { stream.frequency += 50; sleep 0.2 } }
sleep 3

Record audio from your microphone and play it back a second later:

require 'easy_audio'

EasyAudio.easy_open(in: true, out: true, latency: 1.0) { current_sample }
sleep 10 # for 10 seconds

Documentation

See the API documentation on rubydoc.info.

License

EasyAudio is copyright © 2014 by Loren Segal and licensed under the BSD license. See the LICENSE file for more information.