Skip to content

Instantly share code, notes, and snippets.

@coderberry
Created April 20, 2009 22:30
Show Gist options
  • Select an option

  • Save coderberry/98807 to your computer and use it in GitHub Desktop.

Select an option

Save coderberry/98807 to your computer and use it in GitHub Desktop.
require 'sox_encoder'
module Paperclip
class Audio < Processor
attr_accessor :convert_options
def initialize file, options = {}, attachment = nil
super
@file = file
@convert_options = options[:convert_options]
@format = "mp3"
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
end
def make
puts "MADE IT HERE!!!!!!"
src = @file
dst = Tempfile.new([@basename, @format].compact.join("."))
dst.binmode
begin
se = SoxEncoder.new
se.input_file = src.path
se.output_file = dst.path
if se.convert
dst
else
raise PaperclipError, "The file #{@basename} appears to be an invalid format and cannot convert"
end
rescue
raise PaperclipError, "There was an error processing the audio for #{@basename}"
end
dst
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment