Created
April 20, 2009 22:30
-
-
Save coderberry/98807 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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