Introduction
Introduction Statistics Contact Development Disclaimer Help
Add audio_raw_to_speech, basics of gCloud Speech API - warvox - VoIP based ward…
Log
Files
Refs
README
---
commit 49da42535f1e1495e42047d6b74981fdb935d712
parent f8d63a649b497a9fa9c647c0ca552ae085abdcc1
Author: HD Moore <[email protected]>
Date: Fri, 29 Apr 2016 12:24:34 -0500
Add audio_raw_to_speech, basics of gCloud Speech API
Diffstat:
A bin/audio_raw_to_speech.rb | 76 +++++++++++++++++++++++++++++…
M bin/verify_install.rb | 8 ++++++++
M config/warvox.conf | 8 ++++++++
M lib/warvox/audio/raw.rb | 12 ++++++++++++
M lib/warvox/config.rb | 8 ++++++++
5 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/bin/audio_raw_to_speech.rb b/bin/audio_raw_to_speech.rb
@@ -0,0 +1,76 @@
+#!/usr/bin/env ruby
+###################
+
+#
+# Load the library path
+#
+base = __FILE__
+while File.symlink?(base)
+ base = File.expand_path(File.readlink(base), File.dirname(base))
+end
+$:.unshift(File.join(File.expand_path(File.dirname(base)), '..', 'lib'))
+
+require 'warvox'
+
+require 'uri'
+require 'net/http'
+require 'json'
+
+def usage
+ $stderr.puts "Usage: #{$0} <input.raw> <output.json>"
+ exit
+end
+
+#
+# Script
+#
+
+inp = ARGV.shift
+out = ARGV.shift
+
+if (inp and inp == "-h") or not inp
+ usage()
+end
+
+raw = WarVOX::Audio::Raw.from_file(inp)
+res = nil
+flac = raw.to_flac
+akey = WarVOX::Config.gcloud_key
+
+if ! akey
+ $stderr.puts "Error: A gcloud API key needs to be configured"
+ exit(1)
+end
+
+uri = URI('https://speech.googleapis.com/v1/speech:recognize?key=' + akey)
+req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' =>'application/jso…
+
+loop do
+ req.body =
+ {
+ "initialRequest" => {
+ "encoding" => "FLAC",
+ "sampleRate" => 16000,
+ },
+ "audioRequest" => {
+ "content" => [flac].pack("m*").gsub(/\s+/, '')
+ }
+ }.to_json
+
+
+ http = Net::HTTP.new(uri.hostname, uri.port)
+ http.use_ssl = true
+ res = http.request(req)
+
+ break if res.code.to_s == "200"
+ $stderr.puts "Retrying due to #{res.code} #{res.message}..."
+ sleep(1)
+end
+
+if out
+ ::File.open(out, "wb") do |fd|
+ fd.write(res.body)
+ end
+else
+ $stdout.write(res.body)
+end
diff --git a/bin/verify_install.rb b/bin/verify_install.rb
@@ -56,6 +56,14 @@ end
puts "[*] The LAME binary appears to be available"
+if(not WarVOX::Config.tool_path('sox'))
+ puts "[*] ERROR: The 'sox binary could not be installed"
+ puts "[*] $ sudo apt-get install sox"
+ exit
+end
+puts "[*] The SOX binary appears to be available"
+
+
puts " "
puts "[*] Congratulations! You are almost ready to run WarVOX"
puts " "
diff --git a/config/warvox.conf b/config/warvox.conf
@@ -8,8 +8,10 @@
tools:
gnuplot: gnuplot
lame: lame
+ sox: sox
iaxrecord: "%BASE%/bin/iaxrecord.rb"
+
#
# Maximum processing jobs, normally this is set to your processor core count,
# but you can limit it further here. Keep in mind that each analysis job also
@@ -32,3 +34,9 @@ classifiers: "%BASE%/config/classifiers"
# Configure the signature directory
#
signatures: "%BASE%/config/signatures"
+
+#
+# Configure cloud integrations
+#
+apis:
+ gcloud: "%BASE%/config/gcloud.key"
diff --git a/lib/warvox/audio/raw.rb b/lib/warvox/audio/raw.rb
@@ -1,3 +1,5 @@
+require 'open3'
+
module WarVOX
module Audio
class Raw
@@ -72,6 +74,16 @@ class Raw
raw
end
+ def to_flac
+ sox = WarVOX::Config.tool_path('sox')
+ if ! sox
+ raise RuntimeError, "The sox binary could not be find, make sure it is i…
+ end
+
+ o, s = Open3.capture2("#{sox} -t raw -b 16 -e signed-integer -r 8000 - -t …
+ o
+ end
+
def to_flow(opts={})
lo_lim = (opts[:lo_lim] || 100).to_i
diff --git a/lib/warvox/config.rb b/lib/warvox/config.rb
@@ -49,6 +49,14 @@ module Config
end
+ def self.gcloud_key
+ info = YAML.load_file(WarVOX::Conf)
+ return nil if not info
+ return nil if not info['apis']
+ return nil if not info['apis']['gcloud']
+ ::File.read(File.expand_path(info['apis']['gcloud'].gsub('%BASE%', WarVOX:…
+ end
+
def self.signatures_path
info = YAML.load_file(WarVOX::Conf)
return nil if not info
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.