google-cloud-speech 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +0 -2
- data/README.md +4 -2
- data/lib/google-cloud-speech.rb +6 -2
- data/lib/google/cloud/speech.rb +37 -23
- data/lib/google/cloud/speech/audio.rb +73 -44
- data/lib/google/cloud/speech/credentials.rb +2 -2
- data/lib/google/cloud/speech/operation.rb +262 -0
- data/lib/google/cloud/speech/project.rb +186 -83
- data/lib/google/cloud/speech/result.rb +14 -8
- data/lib/google/cloud/speech/service.rb +12 -6
- data/lib/google/cloud/speech/stream.rb +128 -131
- data/lib/google/cloud/speech/{v1beta1.rb → v1.rb} +2 -3
- data/lib/google/cloud/speech/v1/cloud_speech_pb.rb +116 -0
- data/lib/google/cloud/speech/{v1beta1 → v1}/cloud_speech_services_pb.rb +11 -11
- data/lib/google/cloud/speech/{v1beta1/doc/google/cloud/speech/v1beta1 → v1/doc/google/cloud/speech/v1}/cloud_speech.rb +157 -161
- data/lib/google/cloud/speech/{v1beta1 → v1}/doc/google/protobuf/any.rb +0 -0
- data/lib/google/cloud/speech/{v1beta1 → v1}/doc/google/rpc/status.rb +0 -0
- data/lib/google/cloud/speech/{v1beta1 → v1}/speech_client.rb +71 -58
- data/lib/google/cloud/speech/{v1beta1 → v1}/speech_client_config.json +8 -8
- data/lib/google/cloud/speech/version.rb +1 -1
- metadata +13 -13
- data/lib/google/cloud/speech/job.rb +0 -159
- data/lib/google/cloud/speech/v1beta1/cloud_speech_pb.rb +0 -116
File without changes
|
File without changes
|
@@ -14,7 +14,7 @@
|
|
14
14
|
#
|
15
15
|
# EDITING INSTRUCTIONS
|
16
16
|
# This file was generated from the file
|
17
|
-
# https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/
|
17
|
+
# https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1/cloud_speech.proto,
|
18
18
|
# and updates to that file get reflected here through a refresh process.
|
19
19
|
# For the short term, the refresh process will only be runnable by Google
|
20
20
|
# engineers.
|
@@ -29,16 +29,16 @@ require "google/gax"
|
|
29
29
|
require "google/gax/operation"
|
30
30
|
require "google/longrunning/operations_client"
|
31
31
|
|
32
|
-
require "google/cloud/speech/
|
32
|
+
require "google/cloud/speech/v1/cloud_speech_pb"
|
33
33
|
|
34
34
|
module Google
|
35
35
|
module Cloud
|
36
36
|
module Speech
|
37
|
-
module
|
37
|
+
module V1
|
38
38
|
# Service that implements Google Cloud Speech API.
|
39
39
|
#
|
40
40
|
# @!attribute [r] speech_stub
|
41
|
-
# @return [Google::Cloud::Speech::
|
41
|
+
# @return [Google::Cloud::Speech::V1::Speech::Stub]
|
42
42
|
class SpeechClient
|
43
43
|
attr_reader :speech_stub
|
44
44
|
|
@@ -64,6 +64,12 @@ module Google
|
|
64
64
|
# A Channel object through which to make calls.
|
65
65
|
# @param chan_creds [Grpc::ChannelCredentials]
|
66
66
|
# A ChannelCredentials for the setting up the RPC client.
|
67
|
+
# @param updater_proc [Proc]
|
68
|
+
# A function that transforms the metadata for requests, e.g., to give
|
69
|
+
# OAuth credentials.
|
70
|
+
# @param scopes [Array<String>]
|
71
|
+
# The OAuth scopes for this service. This parameter is ignored if
|
72
|
+
# an updater_proc is supplied.
|
67
73
|
# @param client_config[Hash]
|
68
74
|
# A Hash for call options for each method. See
|
69
75
|
# Google::Gax#construct_settings for the structure of
|
@@ -76,6 +82,7 @@ module Google
|
|
76
82
|
port: DEFAULT_SERVICE_PORT,
|
77
83
|
channel: nil,
|
78
84
|
chan_creds: nil,
|
85
|
+
updater_proc: nil,
|
79
86
|
scopes: ALL_SCOPES,
|
80
87
|
client_config: {},
|
81
88
|
timeout: DEFAULT_TIMEOUT,
|
@@ -87,13 +94,14 @@ module Google
|
|
87
94
|
# the gRPC module only when it's required.
|
88
95
|
# See https://github.com/googleapis/toolkit/issues/446
|
89
96
|
require "google/gax/grpc"
|
90
|
-
require "google/cloud/speech/
|
97
|
+
require "google/cloud/speech/v1/cloud_speech_services_pb"
|
91
98
|
|
92
99
|
@operations_client = Google::Longrunning::OperationsClient.new(
|
93
100
|
service_path: service_path,
|
94
101
|
port: port,
|
95
102
|
channel: channel,
|
96
103
|
chan_creds: chan_creds,
|
104
|
+
updater_proc: updater_proc,
|
97
105
|
scopes: scopes,
|
98
106
|
client_config: client_config,
|
99
107
|
timeout: timeout,
|
@@ -119,7 +127,7 @@ module Google
|
|
119
127
|
)
|
120
128
|
defaults = client_config_file.open do |f|
|
121
129
|
Google::Gax.construct_settings(
|
122
|
-
"google.cloud.speech.
|
130
|
+
"google.cloud.speech.v1.Speech",
|
123
131
|
JSON.parse(f.read),
|
124
132
|
client_config,
|
125
133
|
Google::Gax::Grpc::STATUS_CODE_NAMES,
|
@@ -133,17 +141,18 @@ module Google
|
|
133
141
|
port,
|
134
142
|
chan_creds: chan_creds,
|
135
143
|
channel: channel,
|
144
|
+
updater_proc: updater_proc,
|
136
145
|
scopes: scopes,
|
137
|
-
&Google::Cloud::Speech::
|
146
|
+
&Google::Cloud::Speech::V1::Speech::Stub.method(:new)
|
138
147
|
)
|
139
148
|
|
140
|
-
@
|
141
|
-
@speech_stub.method(:
|
142
|
-
defaults["
|
149
|
+
@recognize = Google::Gax.create_api_call(
|
150
|
+
@speech_stub.method(:recognize),
|
151
|
+
defaults["recognize"]
|
143
152
|
)
|
144
|
-
@
|
145
|
-
@speech_stub.method(:
|
146
|
-
defaults["
|
153
|
+
@long_running_recognize = Google::Gax.create_api_call(
|
154
|
+
@speech_stub.method(:long_running_recognize),
|
155
|
+
defaults["long_running_recognize"]
|
147
156
|
)
|
148
157
|
@streaming_recognize = Google::Gax.create_api_call(
|
149
158
|
@speech_stub.method(:streaming_recognize),
|
@@ -153,84 +162,88 @@ module Google
|
|
153
162
|
|
154
163
|
# Service calls
|
155
164
|
|
156
|
-
#
|
165
|
+
# Performs synchronous speech recognition: receive results after all audio
|
157
166
|
# has been sent and processed.
|
158
167
|
#
|
159
|
-
# @param config [Google::Cloud::Speech::
|
160
|
-
#
|
161
|
-
#
|
162
|
-
# @param audio [Google::Cloud::Speech::
|
163
|
-
#
|
168
|
+
# @param config [Google::Cloud::Speech::V1::RecognitionConfig]
|
169
|
+
# *Required* Provides information to the recognizer that specifies how to
|
170
|
+
# process the request.
|
171
|
+
# @param audio [Google::Cloud::Speech::V1::RecognitionAudio]
|
172
|
+
# *Required* The audio data to be recognized.
|
164
173
|
# @param options [Google::Gax::CallOptions]
|
165
174
|
# Overrides the default settings for this call, e.g, timeout,
|
166
175
|
# retries, etc.
|
167
|
-
# @return [Google::Cloud::Speech::
|
176
|
+
# @return [Google::Cloud::Speech::V1::RecognizeResponse]
|
168
177
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
169
178
|
# @example
|
170
|
-
# require "google/cloud/speech/
|
179
|
+
# require "google/cloud/speech/v1"
|
171
180
|
#
|
172
|
-
# AudioEncoding = Google::Cloud::Speech::
|
173
|
-
# RecognitionAudio = Google::Cloud::Speech::
|
174
|
-
# RecognitionConfig = Google::Cloud::Speech::
|
175
|
-
# SpeechClient = Google::Cloud::Speech::
|
181
|
+
# AudioEncoding = Google::Cloud::Speech::V1::RecognitionConfig::AudioEncoding
|
182
|
+
# RecognitionAudio = Google::Cloud::Speech::V1::RecognitionAudio
|
183
|
+
# RecognitionConfig = Google::Cloud::Speech::V1::RecognitionConfig
|
184
|
+
# SpeechClient = Google::Cloud::Speech::V1::SpeechClient
|
176
185
|
#
|
177
186
|
# speech_client = SpeechClient.new
|
178
187
|
# encoding = AudioEncoding::FLAC
|
179
|
-
#
|
188
|
+
# sample_rate_hertz = 44100
|
189
|
+
# language_code = "en-US"
|
180
190
|
# config = RecognitionConfig.new
|
181
191
|
# config.encoding = encoding
|
182
|
-
# config.
|
192
|
+
# config.sample_rate_hertz = sample_rate_hertz
|
193
|
+
# config.language_code = language_code
|
183
194
|
# uri = "gs://bucket_name/file_name.flac"
|
184
195
|
# audio = RecognitionAudio.new
|
185
196
|
# audio.uri = uri
|
186
|
-
# response = speech_client.
|
197
|
+
# response = speech_client.recognize(config, audio)
|
187
198
|
|
188
|
-
def
|
199
|
+
def recognize \
|
189
200
|
config,
|
190
201
|
audio,
|
191
202
|
options: nil
|
192
|
-
req = Google::Cloud::Speech::
|
203
|
+
req = Google::Cloud::Speech::V1::RecognizeRequest.new({
|
193
204
|
config: config,
|
194
205
|
audio: audio
|
195
206
|
}.delete_if { |_, v| v.nil? })
|
196
|
-
@
|
207
|
+
@recognize.call(req, options)
|
197
208
|
end
|
198
209
|
|
199
|
-
#
|
210
|
+
# Performs asynchronous speech recognition: receive results via the
|
200
211
|
# google.longrunning.Operations interface. Returns either an
|
201
212
|
# +Operation.error+ or an +Operation.response+ which contains
|
202
|
-
#
|
213
|
+
# a +LongRunningRecognizeResponse+ message.
|
203
214
|
#
|
204
|
-
# @param config [Google::Cloud::Speech::
|
205
|
-
#
|
206
|
-
#
|
207
|
-
# @param audio [Google::Cloud::Speech::
|
208
|
-
#
|
215
|
+
# @param config [Google::Cloud::Speech::V1::RecognitionConfig]
|
216
|
+
# *Required* Provides information to the recognizer that specifies how to
|
217
|
+
# process the request.
|
218
|
+
# @param audio [Google::Cloud::Speech::V1::RecognitionAudio]
|
219
|
+
# *Required* The audio data to be recognized.
|
209
220
|
# @param options [Google::Gax::CallOptions]
|
210
221
|
# Overrides the default settings for this call, e.g, timeout,
|
211
222
|
# retries, etc.
|
212
223
|
# @return [Google::Gax::Operation]
|
213
224
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
214
225
|
# @example
|
215
|
-
# require "google/cloud/speech/
|
226
|
+
# require "google/cloud/speech/v1"
|
216
227
|
#
|
217
|
-
# AudioEncoding = Google::Cloud::Speech::
|
218
|
-
# RecognitionAudio = Google::Cloud::Speech::
|
219
|
-
# RecognitionConfig = Google::Cloud::Speech::
|
220
|
-
# SpeechClient = Google::Cloud::Speech::
|
228
|
+
# AudioEncoding = Google::Cloud::Speech::V1::RecognitionConfig::AudioEncoding
|
229
|
+
# RecognitionAudio = Google::Cloud::Speech::V1::RecognitionAudio
|
230
|
+
# RecognitionConfig = Google::Cloud::Speech::V1::RecognitionConfig
|
231
|
+
# SpeechClient = Google::Cloud::Speech::V1::SpeechClient
|
221
232
|
#
|
222
233
|
# speech_client = SpeechClient.new
|
223
234
|
# encoding = AudioEncoding::FLAC
|
224
|
-
#
|
235
|
+
# sample_rate_hertz = 44100
|
236
|
+
# language_code = "en-US"
|
225
237
|
# config = RecognitionConfig.new
|
226
238
|
# config.encoding = encoding
|
227
|
-
# config.
|
239
|
+
# config.sample_rate_hertz = sample_rate_hertz
|
240
|
+
# config.language_code = language_code
|
228
241
|
# uri = "gs://bucket_name/file_name.flac"
|
229
242
|
# audio = RecognitionAudio.new
|
230
243
|
# audio.uri = uri
|
231
244
|
#
|
232
245
|
# # Register a callback during the method call.
|
233
|
-
# operation = speech_client.
|
246
|
+
# operation = speech_client.long_running_recognize(config, audio) do |op|
|
234
247
|
# raise op.results.message if op.error?
|
235
248
|
# op_results = op.results
|
236
249
|
# # Process the results.
|
@@ -256,35 +269,35 @@ module Google
|
|
256
269
|
# # completion.
|
257
270
|
# operation.wait_until_done!
|
258
271
|
|
259
|
-
def
|
272
|
+
def long_running_recognize \
|
260
273
|
config,
|
261
274
|
audio,
|
262
275
|
options: nil
|
263
|
-
req = Google::Cloud::Speech::
|
276
|
+
req = Google::Cloud::Speech::V1::LongRunningRecognizeRequest.new({
|
264
277
|
config: config,
|
265
278
|
audio: audio
|
266
279
|
}.delete_if { |_, v| v.nil? })
|
267
280
|
operation = Google::Gax::Operation.new(
|
268
|
-
@
|
281
|
+
@long_running_recognize.call(req, options),
|
269
282
|
@operations_client,
|
270
|
-
Google::Cloud::Speech::
|
271
|
-
Google::Cloud::Speech::
|
283
|
+
Google::Cloud::Speech::V1::LongRunningRecognizeResponse,
|
284
|
+
Google::Cloud::Speech::V1::LongRunningRecognizeMetadata,
|
272
285
|
call_options: options
|
273
286
|
)
|
274
287
|
operation.on_done { |operation| yield(operation) } if block_given?
|
275
288
|
operation
|
276
289
|
end
|
277
290
|
|
278
|
-
#
|
291
|
+
# Performs bidirectional streaming speech recognition: receive results while
|
279
292
|
# sending audio. This method is only available via the gRPC API (not REST).
|
280
293
|
#
|
281
|
-
# @param reqs [Enumerable<Google::Cloud::Speech::
|
294
|
+
# @param reqs [Enumerable<Google::Cloud::Speech::V1::StreamingRecognizeRequest>]
|
282
295
|
# The input requests.
|
283
296
|
# @param options [Google::Gax::CallOptions]
|
284
297
|
# Overrides the default settings for this call, e.g, timeout,
|
285
298
|
# retries, etc.
|
286
|
-
# @return [Enumerable<Google::Cloud::Speech::
|
287
|
-
# An enumerable of Google::Cloud::Speech::
|
299
|
+
# @return [Enumerable<Google::Cloud::Speech::V1::StreamingRecognizeResponse>]
|
300
|
+
# An enumerable of Google::Cloud::Speech::V1::StreamingRecognizeResponse instances.
|
288
301
|
#
|
289
302
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
290
303
|
#
|
@@ -294,10 +307,10 @@ module Google
|
|
294
307
|
# This method interface might change in the future.
|
295
308
|
#
|
296
309
|
# @example
|
297
|
-
# require "google/cloud/speech/
|
310
|
+
# require "google/cloud/speech/v1"
|
298
311
|
#
|
299
|
-
# SpeechClient = Google::Cloud::Speech::
|
300
|
-
# StreamingRecognizeRequest = Google::Cloud::Speech::
|
312
|
+
# SpeechClient = Google::Cloud::Speech::V1::SpeechClient
|
313
|
+
# StreamingRecognizeRequest = Google::Cloud::Speech::V1::StreamingRecognizeRequest
|
301
314
|
#
|
302
315
|
# speech_client = SpeechClient.new
|
303
316
|
# request = StreamingRecognizeRequest.new
|
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"interfaces": {
|
3
|
-
"google.cloud.speech.
|
3
|
+
"google.cloud.speech.v1.Speech": {
|
4
4
|
"retry_codes": {
|
5
5
|
"idempotent": [
|
6
6
|
"DEADLINE_EXCEEDED",
|
@@ -15,26 +15,26 @@
|
|
15
15
|
"initial_retry_delay_millis": 100,
|
16
16
|
"retry_delay_multiplier": 1.3,
|
17
17
|
"max_retry_delay_millis": 60000,
|
18
|
-
"initial_rpc_timeout_millis":
|
18
|
+
"initial_rpc_timeout_millis": 190000,
|
19
19
|
"rpc_timeout_multiplier": 1.0,
|
20
|
-
"max_rpc_timeout_millis":
|
20
|
+
"max_rpc_timeout_millis": 190000,
|
21
21
|
"total_timeout_millis": 600000
|
22
22
|
}
|
23
23
|
},
|
24
24
|
"methods": {
|
25
|
-
"
|
26
|
-
"timeout_millis":
|
25
|
+
"Recognize": {
|
26
|
+
"timeout_millis": 190000,
|
27
27
|
"retry_codes_name": "idempotent",
|
28
28
|
"retry_params_name": "default"
|
29
29
|
},
|
30
|
-
"
|
30
|
+
"LongRunningRecognize": {
|
31
31
|
"timeout_millis": 60000,
|
32
|
-
"retry_codes_name": "
|
32
|
+
"retry_codes_name": "non_idempotent",
|
33
33
|
"retry_params_name": "default"
|
34
34
|
},
|
35
35
|
"StreamingRecognize": {
|
36
36
|
"timeout_millis": 190000,
|
37
|
-
"retry_codes_name": "
|
37
|
+
"retry_codes_name": "idempotent",
|
38
38
|
"retry_params_name": "default"
|
39
39
|
}
|
40
40
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-speech
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-04-
|
12
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0.8.
|
34
|
+
version: 0.8.2
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 0.8.
|
41
|
+
version: 0.8.2
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: minitest
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,19 +180,19 @@ files:
|
|
180
180
|
- lib/google/cloud/speech.rb
|
181
181
|
- lib/google/cloud/speech/audio.rb
|
182
182
|
- lib/google/cloud/speech/credentials.rb
|
183
|
-
- lib/google/cloud/speech/
|
183
|
+
- lib/google/cloud/speech/operation.rb
|
184
184
|
- lib/google/cloud/speech/project.rb
|
185
185
|
- lib/google/cloud/speech/result.rb
|
186
186
|
- lib/google/cloud/speech/service.rb
|
187
187
|
- lib/google/cloud/speech/stream.rb
|
188
|
-
- lib/google/cloud/speech/
|
189
|
-
- lib/google/cloud/speech/
|
190
|
-
- lib/google/cloud/speech/
|
191
|
-
- lib/google/cloud/speech/
|
192
|
-
- lib/google/cloud/speech/
|
193
|
-
- lib/google/cloud/speech/
|
194
|
-
- lib/google/cloud/speech/
|
195
|
-
- lib/google/cloud/speech/
|
188
|
+
- lib/google/cloud/speech/v1.rb
|
189
|
+
- lib/google/cloud/speech/v1/cloud_speech_pb.rb
|
190
|
+
- lib/google/cloud/speech/v1/cloud_speech_services_pb.rb
|
191
|
+
- lib/google/cloud/speech/v1/doc/google/cloud/speech/v1/cloud_speech.rb
|
192
|
+
- lib/google/cloud/speech/v1/doc/google/protobuf/any.rb
|
193
|
+
- lib/google/cloud/speech/v1/doc/google/rpc/status.rb
|
194
|
+
- lib/google/cloud/speech/v1/speech_client.rb
|
195
|
+
- lib/google/cloud/speech/v1/speech_client_config.json
|
196
196
|
- lib/google/cloud/speech/version.rb
|
197
197
|
homepage: http://googlecloudplatform.github.io/google-cloud-ruby/
|
198
198
|
licenses:
|
@@ -1,159 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google Inc. All rights reserved.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
|
16
|
-
require "google/cloud/speech/v1beta1"
|
17
|
-
|
18
|
-
module Google
|
19
|
-
module Cloud
|
20
|
-
module Speech
|
21
|
-
##
|
22
|
-
# # Job
|
23
|
-
#
|
24
|
-
# A resource represents the long-running, asynchronous processing of a
|
25
|
-
# speech-recognition operation. The job can be refreshed to retrieve
|
26
|
-
# recognition results once the audio data has been processed.
|
27
|
-
#
|
28
|
-
# See {Project#recognize_job} and {Audio#recognize_job}.
|
29
|
-
#
|
30
|
-
# @see https://cloud.google.com/speech/docs/basics#async-responses
|
31
|
-
# Asynchronous Speech API Responses
|
32
|
-
# @see https://cloud.google.com/speech/reference/rpc/google.longrunning#google.longrunning.Operations
|
33
|
-
# Long-running Operation
|
34
|
-
#
|
35
|
-
# @example
|
36
|
-
# require "google/cloud/speech"
|
37
|
-
#
|
38
|
-
# speech = Google::Cloud::Speech.new
|
39
|
-
#
|
40
|
-
# job = speech.recognize_job "path/to/audio.raw",
|
41
|
-
# encoding: :raw, sample_rate: 16000
|
42
|
-
#
|
43
|
-
# job.done? #=> false
|
44
|
-
# job.reload! # API call
|
45
|
-
# job.done? #=> true
|
46
|
-
# results = job.results
|
47
|
-
#
|
48
|
-
class Job
|
49
|
-
##
|
50
|
-
# @private The Google::Gax::Operation gRPC object.
|
51
|
-
attr_accessor :grpc
|
52
|
-
|
53
|
-
##
|
54
|
-
# @private Creates a new Job instance.
|
55
|
-
def initialize
|
56
|
-
@grpc = nil
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
# A speech recognition result corresponding to a portion of the audio.
|
61
|
-
#
|
62
|
-
# @return [Array<Result>] The transcribed text of audio recognized. If
|
63
|
-
# the job is not done this will return `nil`.
|
64
|
-
#
|
65
|
-
# @example
|
66
|
-
# require "google/cloud/speech"
|
67
|
-
#
|
68
|
-
# speech = Google::Cloud::Speech.new
|
69
|
-
#
|
70
|
-
# job = speech.recognize_job "path/to/audio.raw",
|
71
|
-
# encoding: :raw, sample_rate: 16000
|
72
|
-
#
|
73
|
-
# job.done? #=> true
|
74
|
-
# results = job.results
|
75
|
-
#
|
76
|
-
def results
|
77
|
-
return nil unless @grpc.response?
|
78
|
-
@grpc.response.results.map do |result_grpc|
|
79
|
-
Result.from_grpc result_grpc
|
80
|
-
end
|
81
|
-
# TODO: Ensure we are raising the proper error
|
82
|
-
# TODO: Ensure GRPC behavior here, is an error already raised?
|
83
|
-
# raise @grpc.error
|
84
|
-
end
|
85
|
-
|
86
|
-
##
|
87
|
-
# Checks if the speech-recognition processing of the audio data is
|
88
|
-
# complete.
|
89
|
-
#
|
90
|
-
# @return [boolean] `true` when complete, `false` otherwise.
|
91
|
-
#
|
92
|
-
# @example
|
93
|
-
# require "google/cloud/speech"
|
94
|
-
#
|
95
|
-
# speech = Google::Cloud::Speech.new
|
96
|
-
#
|
97
|
-
# job = speech.recognize_job "path/to/audio.raw",
|
98
|
-
# encoding: :raw, sample_rate: 16000
|
99
|
-
#
|
100
|
-
# job.done? #=> false
|
101
|
-
#
|
102
|
-
def done?
|
103
|
-
@grpc.done?
|
104
|
-
end
|
105
|
-
|
106
|
-
##
|
107
|
-
# Reloads the job with current data from the long-running, asynchronous
|
108
|
-
# processing of a speech-recognition operation.
|
109
|
-
#
|
110
|
-
# @example
|
111
|
-
# require "google/cloud/speech"
|
112
|
-
#
|
113
|
-
# speech = Google::Cloud::Speech.new
|
114
|
-
#
|
115
|
-
# job = speech.recognize_job "path/to/audio.raw",
|
116
|
-
# encoding: :raw, sample_rate: 16000
|
117
|
-
#
|
118
|
-
# job.done? #=> false
|
119
|
-
# job.reload! # API call
|
120
|
-
# job.done? #=> true
|
121
|
-
#
|
122
|
-
def reload!
|
123
|
-
@grpc.reload!
|
124
|
-
self
|
125
|
-
end
|
126
|
-
alias_method :refresh!, :reload!
|
127
|
-
|
128
|
-
##
|
129
|
-
# Reloads the job until the operation is complete. The delay between
|
130
|
-
# reloads will incrementally increase.
|
131
|
-
#
|
132
|
-
# @example
|
133
|
-
# require "google/cloud/speech"
|
134
|
-
#
|
135
|
-
# speech = Google::Cloud::Speech.new
|
136
|
-
#
|
137
|
-
# job = speech.recognize_job "path/to/audio.raw",
|
138
|
-
# encoding: :raw, sample_rate: 16000
|
139
|
-
#
|
140
|
-
# job.done? #=> false
|
141
|
-
# job.wait_until_done!
|
142
|
-
# job.done? #=> true
|
143
|
-
#
|
144
|
-
def wait_until_done!
|
145
|
-
@grpc.wait_until_done!
|
146
|
-
end
|
147
|
-
|
148
|
-
##
|
149
|
-
# @private New Result::Job from a Google::Longrunning::Operation
|
150
|
-
# object.
|
151
|
-
def self.from_grpc grpc
|
152
|
-
new.tap do |job|
|
153
|
-
job.instance_variable_set :@grpc, grpc
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|