Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lsegal/easy_audio

EasyAudio is a simplified Ruby wrapper for the portaudio library.
https://github.com/lsegal/easy_audio

Last synced: 2 months ago
JSON representation

EasyAudio is a simplified Ruby wrapper for the portaudio library.

Awesome Lists containing this project

README

        

# EasyAudio

[![Gem Version](https://badge.fury.io/rb/easy_audio.svg)](http://badge.fury.io/rb/easy_audio)

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

## Installing

```sh
$ 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][brew].

## Usage

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

```ruby
require 'easy_audio'

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

Play a custom waveform (a cosine wave):

```ruby
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:

```ruby
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:

```ruby
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][docs].

## License

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

[portaudio]: http://portaudio.com
[brew]: http://brew.sh
[docs]: http://rubydoc.info/gems/easy_audio/frames