Voice data server for navigation voice changer app.
Revisión | 9685d51d1190cd90dadacdf5c4989d4cf78eb975 (tree) |
---|---|
Tiempo | 2013-10-20 00:40:06 |
Autor | HMML <hmml3939@gmai...> |
Commiter | HMML |
Fix preview generation for mixed rate/channel data.
@@ -38,14 +38,20 @@ class VoicePreview < Paperclip::Processor | ||
38 | 38 | end |
39 | 39 | end |
40 | 40 | end |
41 | - tfiles.empty? and return dst # give up | |
42 | - system(*['sox', tfiles.sort, dst_path].flatten) or raise "Failed to execute sox: #{$?}" | |
41 | + tfiles.empty? and raise "File missing." | |
42 | + tfiles.each do |tf| | |
43 | + `soxi -r "#{tf}"`.to_i == 44100 && `soxi -c "#{tf}"`.to_i == 1 and next | |
44 | + rtmp = "#{tmpdir}/rate-convert-tmp-#{$$}.ogg" | |
45 | + system('sox', tf, '-c', '1', '-r', '44100', rtmp) or raise "Failed on rate/channel conversion, sox fail (#{$?})" | |
46 | + FileUtils.mv rtmp, tf | |
47 | + end | |
48 | + system(*['sox', tfiles.sort, dst_path].flatten) or raise "Failed to concat, sox fail (#{$?})" | |
43 | 49 | rescue => e |
44 | - raise Paperclip::Error, "Error: Failed to generate preview ogg: #{e.message}" | |
50 | + Rails.logger.error "Error: Failed to generate preview voice: #{e.message}" | |
51 | + raise Paperclip::Error, "Error: Failed to generate preview voice: #{e.message}" | |
45 | 52 | ensure |
46 | 53 | FileUtils.remove_entry_secure tmpdir |
47 | 54 | end |
48 | - | |
49 | 55 | dst |
50 | 56 | end |
51 | 57 | end |