Audio Playback
A command line and Ruby tool for playing audio files
Under the hood the portaudio and libsndfile libraries are used, enabling the gem to be cross-platform on any systems where these libraries are available
Installation
These packages must be installed first:
Both libraries are available in Homebrew, APT, Yum as well as many other package managers. For those who wish to compile themselves or need more information about those packages, follow the links above for more information
Once those libraries are installed, install the gem itself using
gem install audio-playback
Or if you're using Bundler, add this to your Gemfile
gem "audio-playback"
Usage
Command line
playback [filename] [options]
options:
-
-lLatency in seconds. Defaults to use the default latency for the selected output device -
-bBuffer size in bytes. Defaults to 4096 -
-cOutput audio to the given channel(s). Eg-c 0,1will direct audio to channels 0 and 1. Defaults to use channels 0 and 1 on the selected device -
-dDuration. Will stop after the given amount of time. Eg-d 56stops after 56 seconds of playback -
-eEnd position. Will stop at the given absolute time, irregardless of seek. Eg-e 56stops at 56 seconds.-s 01:09:30 -e 01:10:00stops at 1 hour 10 minutes after 30 seconds of playback -
-oOutput device id or name. Defaults to the system default -
-sSeek to given time position. Eg-s 56seeks to 56 seconds and-s 01:10:00seeks to 1 hour 10 min. -
-vor--verboseVerbose -
--loopLoop playback continuously -
--list-devicesList the available audio output devices
example:
playback test/media/1-stereo-44100.wav -v -c 1
With Ruby
require "audio-playback"
# Prompt the user to select an audio output
@output = AudioPlayback::Device::Output.gets
options = {
:channels => [0,1],
:latency => 1,
:output_device => @output
}
@playback = AudioPlayback.play("test/media/1-stereo-44100.wav", options)
# Play in the foreground
@playback.blockoptions:
-
:buffer_sizeBuffer size in bytes. Defaults to 4096 -
:channelor:channelsOutput audio to the given channel(s). Eg:channels => [0,1]will direct the audio to channels 0 and 1. Defaults to use channels 0 and 1 on the selected device -
:latencyLatency in seconds. Defaults to use the default latency for the selected output device -
:loggerLogger object -
:output_deviceOutput device id or name
More Examples
More Ruby code examples:
- List devices
- Select a file and play
- Play multiple files in one stream simultaneously
- Play multiple files in one stream sequentially
- Play multiple files in multiple streams
- Looping playback
License
Licensed under Apache 2.0, See the file LICENSE
Copyright (c) 2015-2017 Ari Russo