Skip to content

Simple SoX wrapper for CarrierWave uploader that allows audio file conversion and watermarking

License

Notifications You must be signed in to change notification settings

fluidmobile/carrierwave-audio

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CarrierWave::Audio

Simple SoX wrapper for CarrierWave uploader that allows audio file conversion and watermarking

Installation

Add this line to your application's Gemfile:

gem 'carrierwave-audio'

And then execute:

$ bundle

Or install it yourself as:

$ gem install carrierwave-audio

Usage

Include CarrierWave::Audio into your CarrierWave uploader class:

class AudioUploader < CarrierWave::Uploader::Base
  include CarrierWave::Audio
end

This gem provides two new processors for uploading audio files, convert and watermark.

Convert

If you'd like to convert from your initially uploaded file-type to a different one, use convert like so:

  version :mp3 do
    process :convert => [{output_format: :mp3}]

    def full_filename(for_file)
      "#{super.chomp(File.extname(super))}.mp3"
    end
  end

process :convert accepts a hash with one or two parameters:

  process :convert => [{output_format:, output_options:}]

output_format - Accepts a symbol. The only currently available option is the default, :mp3.

output_options - Optional. Sox options for the output file (see ruby-sox and the SoX documentation). Defaults to:

  {
    type: output_format.to_s,
    rate: 44100,
    channels: 2,
    compression: 128
  }

Watermark

If you'd like to add a watermark over the top of your file, use watermark like so:

  version :watermarked do
    process :watermark => [{
      output_format: :mp3,
      watermark_file: "#{Rails.root}/db/watermark.mp3"
    }]

    def full_filename(for_file)
      "#{super.chomp(File.extname(super))}.mp3"
    end
  end

process :watermark accepts a hash with up to three parameters:

  process :watermark => [{watermark_file:, output_format:, output_options:}]

watermark_file - REQUIRED. Path to where your watermarked file is stored.

VERY IMPORTANT: The watermarked file must be a 44.1k, 2-channel mp3. It needs to be a long file. It'll be truncated to fit the length of your uploaded file.

output_format - Accepts a symbol. The only currently available option is the default, :mp3.

output_options - Optional. Sox options for the output file (see ruby-sox and the SoX documentation). Defaults to:

  {
    type: output_format.to_s,
    rate: 44100,
    channels: 2,
    compression: 128
  }

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Simple SoX wrapper for CarrierWave uploader that allows audio file conversion and watermarking

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%