RubyDSP | Documentation
🚧 Status: This project is currently in early development. It is hopefully functional, but API changes are expected. There is no warranty.
RubyDSP is an audio processing and DSP Ruby gem. Ultimately, it aims to be librosa-wannabe for Ruby. It uses C++ under the hood, utilizing miniaudio and Rice
- Fast: Basically all of the code is written in C++. While not extremely optimized currently, it still absolutely shreds native Ruby.
- Format Agnostic Loading: Automatically decodes standard audio formats (WAV, MP3, FLAC) via
miniaudio. - Zero-Dependency Native Build: No need to install
ffmpegorlibsndfileon your system. - YARD Support: Includes pure-Ruby stubs (in
stubs, duh) for IDE autocomplete and inline documentation.
Add this line to your application's Gemfile:
gem 'ruby_dsp'And then execute:
$ bundle installOr install it yourself directly via:
$ gem install ruby_dsp(Note: Installing this gem requires a modern C++ compiler, as it builds the native extensions directly on your machine upon installation. It requires Ruby 3.0+).
Here is a quick look at what you can do with a loaded AudioTrack:
require 'ruby_dsp'
# Load an audio file
track = RubyDSP::AudioTrack.new("raw_vocals.wav")
puts track
# => ['raw_vocals.wav', 12.450s duration, 2 channel(s), 48000Hz sample rate]
# Do stuff!
track.to_mono! # Averages channels into mono
track.resample!(44100) # Linearly resamples to target rate
track.trim_silence!(-60.0) # Strips leading/trailing silence below -60dB
# Analysis & Math
puts "Peak Amp: #{track.peak_amp}"
puts "Overall RMS: #{track.rms}"
puts "Overall ZCR: #{track.zcr}"
# You can also get framed analysis for time-series data:
# framed_rms_data = track.framed_rms(2048, 512) also works
framed_rms_data = track.framed_rms(frame_length: 2048, hop_length: 512)
# Save the results
track.save_track("processed_vocals.wav")If you want to clone the repo and work on C++ guts, start with:
- Clone the repo and run
bundle installto grab the development dependencies. - Run
rake test— this will automatically compile the C++extconf.rband run the Minitest suite. - Run
rake doc:generate ; rake doc:server— this will compile the YARD stubs into HTML and boot a live-reloading local web server athttp://localhost:8808so you can read the docs!
The gem is available as open source under the terms of the MIT License.