google_speech 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDVkYmNiZGJiNGY2Y2Y2NmY2YjAwZThhNGMwMGY5MzM4MzE5MTAzMQ==
4
+ M2I5ODY4NzA3Mzg1OTcyZjJlYWJlNjc2ZjdhMDc4ZjcyYzcxOTkwYQ==
5
5
  data.tar.gz: !binary |-
6
- YWIwYzg5YTM0YmYwNjcwMThjYWNlMTExZjQ1NWM1ODcwYmNjZjljYQ==
6
+ YTkyYWY0NTExNjRmZDZjY2VmYjdjYTZjMGZlZDJjY2QyMzEyOWRjMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzZlMzVkNzFkZTNmODc1ZTdhYTJlYTA0ZWExOGFiMDliNWJhYmRmZDhiY2Rj
10
- ODgwODJkN2UyY2VmZmZjNTJiY2Y4YjFhYzAxY2ZkYmQ1ZmI1YjMyNWQ1MDNi
11
- OWQ2ODVjNjQwYWQ5ODY3YTMxYTg4YjlhYjY2YmVlMDEwMmUwODM=
9
+ NDQ0NThhNzhkMjg3YjExNTk5ZmRkNmRjMDc1YTMwMjcxYTg0N2FlZWE5YjVi
10
+ OWNlN2U4ZWM1NWJmN2QyZTgwMTJiMDgzYmQwZTlmMDBhMmNlMDdlMmZiZTFj
11
+ NmE3OTc1MThjZmVkNzEyYmUxYTg1NTQ5OTgyN2UyMzI5Mzg4MTA=
12
12
  data.tar.gz: !binary |-
13
- ZDIwMWY5OWNjNmE3ZDIxYmIxOWRlMjBlYWIwMDk3YTdkZjkwMDU3ZDA3MmU3
14
- ZDQ2NWZkMDhkZTViZjRhYTBiMWFiMDYxZDk2ZWZkMWU1ZTAxZjg4ZTg0YjMy
15
- MDhhZDk2YWRmOGEzOTdkOTI0YzRmMDFjMDYxZjZiZWIyYjJhNjg=
13
+ YjU5ODViY2QwNjJjZjVlMGQzNmI4ZDJmYmUxMmEyNTY1NDViYWU3MjdkZDlh
14
+ ZjM4M2NkZDk4NDNiZTZlOTc5YTBjMmY0OGYyOTU3Mzk3Y2VhOGRhMGYwNWY4
15
+ ODVjOTI0ZGE5OGRhM2Q4ODQ3ODU0NDhmMzI3ZDkwMTVlNjI4ZDI=
data/bin/google_speech CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'google_speech'
4
4
 
5
+ GoogleSpeech.logger = Logger.new(STDOUT)
6
+
5
7
  if ARGV[0].nil? || !File.exist?(ARGV[0])
6
8
  STDERR.puts "usage: #{$0} input.wav"
7
9
  exit(1)
data/lib/google_speech.rb CHANGED
@@ -1,8 +1,18 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  require 'rubygems'
4
+ require 'logger'
4
5
 
5
6
  module GoogleSpeech
7
+
8
+ def self.logger
9
+ @_logger ||= Logger.new(STDOUT)
10
+ end
11
+
12
+ def self.logger=(l)
13
+ @_logger = l
14
+ end
15
+
6
16
  end
7
17
 
8
18
  require 'google_speech/version'
@@ -29,7 +29,7 @@ module GoogleSpeech
29
29
  end
30
30
 
31
31
  def logger
32
- GoogleSpeech::Utility.logger
32
+ GoogleSpeech.logger
33
33
  end
34
34
 
35
35
  end
@@ -24,7 +24,7 @@ module GoogleSpeech
24
24
  end
25
25
 
26
26
  def logger
27
- GoogleSpeech::Utility.logger
27
+ GoogleSpeech.logger
28
28
  end
29
29
 
30
30
  end
@@ -12,9 +12,9 @@ module GoogleSpeech
12
12
  :language => 'en-US',
13
13
  :chunk_duration => 5,
14
14
  :overlap => 1,
15
- :max_results => 2,
15
+ :max_results => 1,
16
16
  :request_pause => 1,
17
- :profanity_filter => false
17
+ :profanity_filter => true
18
18
  }
19
19
 
20
20
  def initialize(original_file, options=nil)
@@ -64,9 +64,6 @@ module GoogleSpeech
64
64
 
65
65
  def transcribe_data(data)
66
66
  params = {
67
- :scheme => 'https',
68
- :host => 'www.google.com',
69
- :port => 443,
70
67
  :path => "/speech-api/v1/recognize",
71
68
  :query => "xjerr=1&client=google_speech&lang=#{options[:language]}&maxresults=#{options[:max_results].to_i}&pfilter=#{pfilter}",
72
69
  :body => data,
@@ -80,28 +77,37 @@ module GoogleSpeech
80
77
  retry_max = options[:retry_max] ? [options[:retry_max].to_i, 1].max : 3
81
78
  retry_count = 0
82
79
  result = nil
83
- url = "#{params[:scheme]}://#{params[:host]}:#{params[:port]}#{params[:path]}"
80
+ url = "https://www.google.com:443#{params[:path]}"
84
81
  while(!result && retry_count < retry_max)
85
- connection = Excon.new(url)
86
- response = connection.request(params)
87
- # puts "response: #{response.inspect}\n\n"
88
- # puts "response.body: #{response.body}\n\n"
89
- if response.status.to_s.start_with?('2')
90
- if (response.body && response.body.size > 0)
91
- result = response.body.split("\n").collect{|b| JSON.parse(b)}
92
- # puts "results #{result.count}: #{result.inspect}\n\n"
82
+ retry_count += 1
83
+
84
+ begin
85
+ connection = Excon.new(url)
86
+ response = connection.request(params)
87
+ # puts "response: #{response.inspect}\n\n"
88
+ # puts "response.body: #{response.body}\n\n"
89
+ if response.status.to_s.start_with?('2')
90
+ result = []
91
+ if (response.body && response.body.size > 0)
92
+ result = response.body.split("\n").collect{|b| JSON.parse(b)} rescue []
93
+ end
94
+ else
95
+ logger.error "transcribe_data response unsuccessful, status: #{response.status}, response: #{response.inspect}"
96
+ sleep(1)
93
97
  end
94
- else
98
+ rescue StandardError => err
99
+ #need to do something to retry this - use new a13g func for this.
100
+ logger.error "transcribe_data retrycount(#{retry_count}): error: #{err.message}"
95
101
  sleep(1)
96
- retry_count += 1
97
102
  end
103
+
98
104
  end
99
105
 
100
- result
106
+ result || []
101
107
  end
102
108
 
103
109
  def logger
104
- GoogleSpeech::Utility.logger
110
+ GoogleSpeech.logger
105
111
  end
106
112
 
107
113
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'tempfile'
4
4
  require 'open3'
5
- require 'logger'
6
5
 
7
6
  module GoogleSpeech
8
7
 
@@ -83,11 +82,7 @@ module GoogleSpeech
83
82
  end
84
83
 
85
84
  def logger
86
- @logger ||= Logger.new(STDOUT)
87
- end
88
-
89
- def logger=(l)
90
- @logger = l
85
+ GoogleSpeech.logger
91
86
  end
92
87
 
93
88
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module GoogleSpeech
4
- VERSION = "0.1.6"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_speech
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kuklewicz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-15 00:00:00.000000000 Z
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon