bin/audioupload in fonemas-0.4.3 vs bin/audioupload in fonemas-0.4.9
- old
+ new
@@ -1,15 +1,45 @@
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'rest_client'
+require 'mime/types'
+require 'tempfile'
+filename = ARGV[1]
+types = MIME::Types.type_for(filename)
+valido = false
+for i in types
+ if i.content_type.include? "wav" or i.content_type.include? "x-wav"
+ valido = true
+ end
+end
+
+t = Tempfile.new(filename)
+
+if !valido
+ puts "convirtiendo a wav antes de subir"
+ `ffmpeg -i "#{filename}" -vn -acodec pcm_s16le -ar 16000 -ac 1 -f wav "#{t.path}"`
+ filename = t.path
+end
+
+
+file = File.new(ARGV[1])
+
+puts "uploading..."
+
begin
RestClient.post('http://cluster.metaforas.cl/audios',
- "audio[audio_original]" => File.new(ARGV[1]),
+ "audio[audio_original]" => File.new(filename),
:api => ARGV[0])
rescue
RestClient.post('http://cluster.metaforas.cl:8000/audios',
- "audio[audio_original]" => File.new(ARGV[1]),
+ "audio[audio_original]" => File.new(filename),
:api => ARGV[0])
-end
+end
+
+
+t.close
+
+
+puts "ready"
\ No newline at end of file