Ruby FFI bindings for libvorbis and libvorbisenc. Provides Vorbis audio codec encoding functionality.
libvorbis and libvorbisenc must be installed on your system.
macOS:
brew install libvorbisDebian / Ubuntu:
sudo apt-get install libvorbis-devFedora / RHEL:
sudo dnf install libvorbis-develAdd to your Gemfile:
gem "vorbis-ruby"Or install directly:
gem install vorbis-rubyrequire "vorbis"
File.open("output.ogg", "wb") do |f|
encoder = Vorbis::Encoder.new(
channels: 2,
rate: 44100,
quality: 0.4,
comments: { "ARTIST" => "Test", "TITLE" => "Hello" }
)
encoder.write_headers { |data| f.write(data) }
# PCM data as per-channel float arrays (-1.0 to 1.0)
samples = [Array.new(1024, 0.0), Array.new(1024, 0.0)]
encoder.encode(samples) { |data| f.write(data) }
encoder.finish { |data| f.write(data) }
encoder.close
endHigh-level encoder that manages all Vorbis resources internally.
initialize(channels:, rate:, quality: 0.4, comments: {})— Create encoder with VBR quality (-0.1 to 1.0)write_headers { |data| }— Yield OGG header pagesencode(samples) { |data| }— Encode PCM samples (array of per-channel float arrays) and yield OGG pagesfinish { |data| }— Signal end-of-stream and yield remaining OGG pagesclose— Release all resources
Low-level wrapper for vorbis_info.
encode_init_vbr(channels:, rate:, quality:)— Set up VBR encodingencode_init(channels:, rate:, nominal_bitrate:, max_bitrate: -1, min_bitrate: -1)— Set up CBR/ABR encodingchannels,rate,bitrate_nominal— Accessorsclear— Release resources
Low-level wrapper for vorbis_comment.
add_tag(tag, value)— Add a comment tagquery(tag, index = 0)— Query a tag valuequery_count(tag)— Count tags with a given namevendor— Get the vendor stringclear— Release resources
Low-level wrapper for vorbis_dsp_state.
headerout(comment)— Generate 3 header packetsanalysis_buffer(samples)— Get per-channel write bufferswrote(samples)— Notify samples written (0 for EOS)clear— Release resources
Low-level wrapper for vorbis_block.
blockout— Extract a block from DSP stateanalysis_and_addblock— Analyze block and add to bitrate managementflush_packet— Flush a packet from bitrate managementclear— Release resources
The gem is available as open source under the terms of the MIT License.