https://github.com/bbc/audio_waveform-ruby
Ruby gem that provides access to audio waveform data files generated by audiowaveform
https://github.com/bbc/audio_waveform-ruby
Last synced: 5 months ago
JSON representation
Ruby gem that provides access to audio waveform data files generated by audiowaveform
- Host: GitHub
- URL: https://github.com/bbc/audio_waveform-ruby
- Owner: bbc
- License: apache-2.0
- Created: 2013-10-14T12:51:28.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-03-01T17:26:22.000Z (almost 2 years ago)
- Last Synced: 2025-07-28T12:09:26.835Z (6 months ago)
- Language: Ruby
- Homepage: https://waveform.prototyping.bbc.co.uk
- Size: 45.9 KB
- Stars: 84
- Watchers: 20
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- License: COPYING
Awesome Lists containing this project
README
# audio_waveform-ruby
[](http://rubygems.org/gems/audio_waveform-ruby) [](https://travis-ci.org/bbc/audio_waveform-ruby)
The audio_waveform-ruby gem provides a Ruby API for access to audio waveform data
files generated by the [audiowaveform](https://github.com/bbc/audiowaveform) program.
Refer to the [audiowaveform](https://github.com/bbc/audiowaveform) documentation for more information and [this page](https://github.com/bbc/audiowaveform/blob/master/doc/DataFormat.md) for file format details.
## Installation
To install:
$ gem install audio_waveform-ruby
or, if using bundler, add this line to your application's Gemfile:
```ruby
gem 'audio_waveform-ruby', :require => 'audio_waveform'
```
or, to use the latest code from the GitHub repository:
```ruby
gem 'audio_waveform-ruby', :require => 'audio_waveform',
:git => 'https://github.com/bbc/audio_waveform-ruby.git'
```
and run
$ bundle install
## Usage
To use this Gem in your program, add:
```ruby
require 'audio_waveform'
```
Then, to load and use data from an existing waveform data file:
```ruby
waveform = AudioWaveform::WaveformDataFile.new(filename: "test.dat")
puts waveform.sample_rate # Returns audio sample rate, in Hz
puts waveform.bits # Returns resolution of waveform data points
puts waveform.samples_per_pixel # Returns waveform zoom level, in samples per pixel
puts waveform.size # Returns number of waveform data points
(0...waveform.size).each do |i|
puts waveform.min_sample(i) # Returns waveform minimum at index i
puts waveform.max_sample(i) # Returns waveform maximum at index i
end
```
To generate a binary representation of a waveform data file:
```ruby
waveform = AudioWaveform::WaveformDataFile.new(filename: "test.dat")
data = waveform.to_binary
```
To save waveform data as a file in binary format:
```ruby
waveform = AudioWaveform::WaveformDataFile.new(filename: "test.dat")
waveform.save_as_binary("output.dat")
```
To generate a JSON representation of a waveform data file:
```ruby
waveform = AudioWaveform::WaveformDataFile.new(filename: "test.dat")
waveform.to_json
```
To save waveform data as a file in JSON format:
```ruby
waveform = AudioWaveform::WaveformDataFile.new(filename: "test.dat")
waveform.save_as_json("output.json")
```
To create a new waveform data file:
```ruby
waveform = AudioWaveform::WaveformDataFile.new(
sample_rate: 44100,
samples_per_pixel: 512,
bits: 8
)
waveform.append(-10, 10)
.append(-11, 11)
.append(-3, 3)
# etc
```
## License
See COPYING for details.
## Contributing
If you have a feature request or want to report a bug, we'd be happy to hear from you. Please either raise an [issue](https://github.com/bbcrd/audio_waveform-ruby/issues), or fork the project and send us a pull request.
## Authors
This software was written by [Chris Needham](https://github.com/chrisn), chris.needham at bbc.co.uk.
## Copyright
Copyright 2020 British Broadcasting Corporation