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 +8 -8
- data/bin/google_speech +2 -0
- data/lib/google_speech.rb +10 -0
- data/lib/google_speech/chunk.rb +1 -1
- data/lib/google_speech/chunk_factory.rb +1 -1
- data/lib/google_speech/transcriber.rb +24 -18
- data/lib/google_speech/utility.rb +1 -6
- data/lib/google_speech/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2I5ODY4NzA3Mzg1OTcyZjJlYWJlNjc2ZjdhMDc4ZjcyYzcxOTkwYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTkyYWY0NTExNjRmZDZjY2VmYjdjYTZjMGZlZDJjY2QyMzEyOWRjMw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDQ0NThhNzhkMjg3YjExNTk5ZmRkNmRjMDc1YTMwMjcxYTg0N2FlZWE5YjVi
|
10
|
+
OWNlN2U4ZWM1NWJmN2QyZTgwMTJiMDgzYmQwZTlmMDBhMmNlMDdlMmZiZTFj
|
11
|
+
NmE3OTc1MThjZmVkNzEyYmUxYTg1NTQ5OTgyN2UyMzI5Mzg4MTA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjU5ODViY2QwNjJjZjVlMGQzNmI4ZDJmYmUxMmEyNTY1NDViYWU3MjdkZDlh
|
14
|
+
ZjM4M2NkZDk4NDNiZTZlOTc5YTBjMmY0OGYyOTU3Mzk3Y2VhOGRhMGYwNWY4
|
15
|
+
ODVjOTI0ZGE5OGRhM2Q4ODQ3ODU0NDhmMzI3ZDkwMTVlNjI4ZDI=
|
data/bin/google_speech
CHANGED
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'
|
data/lib/google_speech/chunk.rb
CHANGED
@@ -12,9 +12,9 @@ module GoogleSpeech
|
|
12
12
|
:language => 'en-US',
|
13
13
|
:chunk_duration => 5,
|
14
14
|
:overlap => 1,
|
15
|
-
:max_results =>
|
15
|
+
:max_results => 1,
|
16
16
|
:request_pause => 1,
|
17
|
-
:profanity_filter =>
|
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 = "
|
80
|
+
url = "https://www.google.com:443#{params[:path]}"
|
84
81
|
while(!result && retry_count < retry_max)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
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
|
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
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
def logger=(l)
|
90
|
-
@logger = l
|
85
|
+
GoogleSpeech.logger
|
91
86
|
end
|
92
87
|
|
93
88
|
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.
|
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
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|