google_speech 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ M2U2ZDQwNGFhYzhmNjIxZjkzYmRmYjM4ZTI1ZDE3MzY3MzVjYWUxMw==
5
+ data.tar.gz: !binary |-
6
+ NGZmNWZlOTEyOTI4MzNkMDRmZTYzNjJhZmNlYTYyMWU1NDllNmQ4Ng==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NjdhNTE3NDZhMjQ3ZjE5MTg0YmZhMDM4MGJmNzRjY2RjNDVlY2VkNDk1ZDA1
10
+ OTBhYzA2NTU4MTgyN2JlNWZlMzI1NmI2NTk0ZmNjMGM2NTk3YjdkMTk0NzVh
11
+ Yzg3NTUxNWZhNDcwYmI2MTdkNmYxZDUzMmQ5OGFiOGI5ZjdlNWI=
12
+ data.tar.gz: !binary |-
13
+ ZGUyYzgzNmMzOWQ1ZGQwMGJiMDgzYjNiYzM4YTJhMTEzOGM3NTlhYmFkMGJm
14
+ MzJjZmZmMTcxYjdiNzg4YTk0NDNiNGYzYTlmZmExZTllZGFkYjA5ZTExOTY2
15
+ MTUxYzdkOWQ1NGViZDYxM2RjODMwYzZiYzNmZDNjYjFhYzI3M2M=
@@ -13,6 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.description = %q{This is a gem to call the google speech api.}
14
14
  gem.summary = %q{This is a gem to call the google speech api.}
15
15
  gem.homepage = "https://github.com/PRX/google_speech"
16
+ gem.license = "MIT"
16
17
 
17
18
  gem.files = `git ls-files`.split($/)
18
19
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -29,18 +29,31 @@ module GoogleSpeech
29
29
  result = chunk.to_hash
30
30
  transcript = transcribe_data(chunk.data)
31
31
  next unless transcript
32
- hypothesis = transcript['hypotheses'].first || Hash.new("")
33
- result[:text] = hypothesis['utterance']
34
- result[:confidence] = hypothesis['confidence']
35
- @results << result
32
+
33
+ result = result.merge(extract_result(transcript))
36
34
 
37
35
  logger.debug "#{result[:start_time]}: #{(result[:confidence].to_f * 100).to_i}%: #{result[:text]}"
38
36
 
37
+ @results << result
38
+
39
39
  sleep(options[:request_pause].to_i)
40
40
  }
41
41
  @results
42
42
  end
43
43
 
44
+ def extract_result(transcripts)
45
+ results = transcripts.map{|t| result_from_transcript(t)}.compact
46
+ {
47
+ :text => results.collect {|t| t[:text] }.join(' '),
48
+ :confidence => results.inject(0.0) {|s, t| s + t[:confidence].to_f } / results.size
49
+ }
50
+ end
51
+
52
+ def result_from_transcript(transcript)
53
+ hyp = transcript['hypotheses'].first
54
+ hyp ? { :text => hyp['utterance'], :confidence => hyp['confidence'] } : nil
55
+ end
56
+
44
57
  def pfilter
45
58
  options[:profanity_filter] ? '1' : '0'
46
59
  end
@@ -68,9 +81,12 @@ module GoogleSpeech
68
81
  connection = Excon.new(url)
69
82
  response = connection.request(params)
70
83
  # puts "response: #{response.inspect}\n\n"
84
+ # puts "response.body: #{response.body}\n\n"
71
85
  if response.status.to_s.start_with?('2')
72
- result = JSON.parse(response.body)
73
- # puts "results: #{result.inspect}\n\n"
86
+ if (response.body && response.body.size > 0)
87
+ result = response.body.split("\n").collect{|b| JSON.parse(b)}
88
+ # puts "results #{result.count}: #{result.inspect}\n\n"
89
+ end
74
90
  else
75
91
  sleep(1)
76
92
  retry_count += 1
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module GoogleSpeech
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_speech
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
5
- prerelease:
4
+ version: 0.1.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Andrew Kuklewicz
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-18 00:00:00.000000000 Z
11
+ date: 2013-11-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: excon
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: minitest
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -84,34 +77,28 @@ files:
84
77
  - spec/test.wav
85
78
  - spec/transcriber_spec.rb
86
79
  homepage: https://github.com/PRX/google_speech
87
- licenses: []
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
88
83
  post_install_message:
89
84
  rdoc_options: []
90
85
  require_paths:
91
86
  - lib
92
87
  required_ruby_version: !ruby/object:Gem::Requirement
93
- none: false
94
88
  requirements:
95
89
  - - ! '>='
96
90
  - !ruby/object:Gem::Version
97
91
  version: '0'
98
- segments:
99
- - 0
100
- hash: 1407648211186855661
101
92
  required_rubygems_version: !ruby/object:Gem::Requirement
102
- none: false
103
93
  requirements:
104
94
  - - ! '>='
105
95
  - !ruby/object:Gem::Version
106
96
  version: '0'
107
- segments:
108
- - 0
109
- hash: 1407648211186855661
110
97
  requirements: []
111
98
  rubyforge_project:
112
- rubygems_version: 1.8.23
99
+ rubygems_version: 2.0.6
113
100
  signing_key:
114
- specification_version: 3
101
+ specification_version: 4
115
102
  summary: This is a gem to call the google speech api.
116
103
  test_files:
117
104
  - spec/spec_helper.rb