google-cloud-speech 0.32.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +4 -1
  3. data/AUTHENTICATION.md +169 -0
  4. data/LICENSE.md +201 -0
  5. data/MIGRATING.md +367 -0
  6. data/README.md +97 -52
  7. data/lib/google/cloud/speech/version.rb +22 -0
  8. data/lib/google/cloud/speech.rb +88 -139
  9. data/lib/google-cloud-speech.rb +19 -0
  10. metadata +111 -49
  11. data/LICENSE +0 -201
  12. data/lib/google/cloud/speech/v1/cloud_speech_pb.rb +0 -129
  13. data/lib/google/cloud/speech/v1/cloud_speech_services_pb.rb +0 -56
  14. data/lib/google/cloud/speech/v1/credentials.rb +0 -41
  15. data/lib/google/cloud/speech/v1/doc/google/cloud/speech/v1/cloud_speech.rb +0 -482
  16. data/lib/google/cloud/speech/v1/doc/google/longrunning/operations.rb +0 -93
  17. data/lib/google/cloud/speech/v1/doc/google/protobuf/any.rb +0 -130
  18. data/lib/google/cloud/speech/v1/doc/google/protobuf/duration.rb +0 -91
  19. data/lib/google/cloud/speech/v1/doc/google/rpc/status.rb +0 -84
  20. data/lib/google/cloud/speech/v1/helpers.rb +0 -136
  21. data/lib/google/cloud/speech/v1/speech_client.rb +0 -331
  22. data/lib/google/cloud/speech/v1/speech_client_config.json +0 -41
  23. data/lib/google/cloud/speech/v1/stream.rb +0 -614
  24. data/lib/google/cloud/speech/v1.rb +0 -157
  25. data/lib/google/cloud/speech/v1p1beta1/cloud_speech_pb.rb +0 -190
  26. data/lib/google/cloud/speech/v1p1beta1/cloud_speech_services_pb.rb +0 -56
  27. data/lib/google/cloud/speech/v1p1beta1/credentials.rb +0 -41
  28. data/lib/google/cloud/speech/v1p1beta1/doc/google/cloud/speech/v1p1beta1/cloud_speech.rb +0 -719
  29. data/lib/google/cloud/speech/v1p1beta1/doc/google/longrunning/operations.rb +0 -93
  30. data/lib/google/cloud/speech/v1p1beta1/doc/google/protobuf/any.rb +0 -130
  31. data/lib/google/cloud/speech/v1p1beta1/doc/google/protobuf/duration.rb +0 -91
  32. data/lib/google/cloud/speech/v1p1beta1/doc/google/rpc/status.rb +0 -84
  33. data/lib/google/cloud/speech/v1p1beta1/helpers.rb +0 -136
  34. data/lib/google/cloud/speech/v1p1beta1/speech_client.rb +0 -331
  35. data/lib/google/cloud/speech/v1p1beta1/speech_client_config.json +0 -41
  36. data/lib/google/cloud/speech/v1p1beta1/stream.rb +0 -614
  37. data/lib/google/cloud/speech/v1p1beta1.rb +0 -157
@@ -1,331 +0,0 @@
1
- # Copyright 2018 Google LLC
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
- # https://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
- # EDITING INSTRUCTIONS
16
- # This file was generated from the file
17
- # https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1p1beta1/cloud_speech.proto,
18
- # and updates to that file get reflected here through a refresh process.
19
- # For the short term, the refresh process will only be runnable by Google
20
- # engineers.
21
-
22
-
23
- require "json"
24
- require "pathname"
25
-
26
- require "google/gax"
27
- require "google/gax/operation"
28
- require "google/longrunning/operations_client"
29
-
30
- require "google/cloud/speech/v1p1beta1/cloud_speech_pb"
31
- require "google/cloud/speech/v1p1beta1/credentials"
32
-
33
- module Google
34
- module Cloud
35
- module Speech
36
- module V1p1beta1
37
- # Service that implements Google Cloud Speech API.
38
- #
39
- # @!attribute [r] speech_stub
40
- # @return [Google::Cloud::Speech::V1p1beta1::Speech::Stub]
41
- class SpeechClient
42
- # @private
43
- attr_reader :speech_stub
44
-
45
- # The default address of the service.
46
- SERVICE_ADDRESS = "speech.googleapis.com".freeze
47
-
48
- # The default port of the service.
49
- DEFAULT_SERVICE_PORT = 443
50
-
51
- # The default set of gRPC interceptors.
52
- GRPC_INTERCEPTORS = []
53
-
54
- DEFAULT_TIMEOUT = 30
55
-
56
- # The scopes needed to make gRPC calls to all of the methods defined in
57
- # this service.
58
- ALL_SCOPES = [
59
- "https://www.googleapis.com/auth/cloud-platform"
60
- ].freeze
61
-
62
- # @private
63
- class OperationsClient < Google::Longrunning::OperationsClient
64
- self::SERVICE_ADDRESS = SpeechClient::SERVICE_ADDRESS
65
- self::GRPC_INTERCEPTORS = SpeechClient::GRPC_INTERCEPTORS
66
- end
67
-
68
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
69
- # Provides the means for authenticating requests made by the client. This parameter can
70
- # be many types.
71
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
72
- # authenticating requests made by this client.
73
- # A `String` will be treated as the path to the keyfile to be used for the construction of
74
- # credentials for this client.
75
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
76
- # credentials for this client.
77
- # A `GRPC::Core::Channel` will be used to make calls through.
78
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
79
- # should already be composed with a `GRPC::Core::CallCredentials` object.
80
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
81
- # metadata for requests, generally, to give OAuth credentials.
82
- # @param scopes [Array<String>]
83
- # The OAuth scopes for this service. This parameter is ignored if
84
- # an updater_proc is supplied.
85
- # @param client_config [Hash]
86
- # A Hash for call options for each method. See
87
- # Google::Gax#construct_settings for the structure of
88
- # this data. Falls back to the default config if not specified
89
- # or the specified config is missing data points.
90
- # @param timeout [Numeric]
91
- # The default timeout, in seconds, for calls made through this client.
92
- # @param metadata [Hash]
93
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
94
- # @param exception_transformer [Proc]
95
- # An optional proc that intercepts any exceptions raised during an API call to inject
96
- # custom error handling.
97
- def initialize \
98
- credentials: nil,
99
- scopes: ALL_SCOPES,
100
- client_config: {},
101
- timeout: DEFAULT_TIMEOUT,
102
- metadata: nil,
103
- exception_transformer: nil,
104
- lib_name: nil,
105
- lib_version: ""
106
- # These require statements are intentionally placed here to initialize
107
- # the gRPC module only when it's required.
108
- # See https://github.com/googleapis/toolkit/issues/446
109
- require "google/gax/grpc"
110
- require "google/cloud/speech/v1p1beta1/cloud_speech_services_pb"
111
-
112
- credentials ||= Google::Cloud::Speech::V1p1beta1::Credentials.default
113
-
114
- @operations_client = OperationsClient.new(
115
- credentials: credentials,
116
- scopes: scopes,
117
- client_config: client_config,
118
- timeout: timeout,
119
- lib_name: lib_name,
120
- lib_version: lib_version,
121
- )
122
-
123
- if credentials.is_a?(String) || credentials.is_a?(Hash)
124
- updater_proc = Google::Cloud::Speech::V1p1beta1::Credentials.new(credentials).updater_proc
125
- end
126
- if credentials.is_a?(GRPC::Core::Channel)
127
- channel = credentials
128
- end
129
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
130
- chan_creds = credentials
131
- end
132
- if credentials.is_a?(Proc)
133
- updater_proc = credentials
134
- end
135
- if credentials.is_a?(Google::Auth::Credentials)
136
- updater_proc = credentials.updater_proc
137
- end
138
-
139
- package_version = Gem.loaded_specs['google-cloud-speech'].version.version
140
-
141
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
142
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
143
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
144
- google_api_client << " grpc/#{GRPC::VERSION}"
145
- google_api_client.freeze
146
-
147
- headers = { :"x-goog-api-client" => google_api_client }
148
- headers.merge!(metadata) unless metadata.nil?
149
- client_config_file = Pathname.new(__dir__).join(
150
- "speech_client_config.json"
151
- )
152
- defaults = client_config_file.open do |f|
153
- Google::Gax.construct_settings(
154
- "google.cloud.speech.v1p1beta1.Speech",
155
- JSON.parse(f.read),
156
- client_config,
157
- Google::Gax::Grpc::STATUS_CODE_NAMES,
158
- timeout,
159
- errors: Google::Gax::Grpc::API_ERRORS,
160
- metadata: headers
161
- )
162
- end
163
-
164
- # Allow overriding the service path/port in subclasses.
165
- service_path = self.class::SERVICE_ADDRESS
166
- port = self.class::DEFAULT_SERVICE_PORT
167
- interceptors = self.class::GRPC_INTERCEPTORS
168
- @speech_stub = Google::Gax::Grpc.create_stub(
169
- service_path,
170
- port,
171
- chan_creds: chan_creds,
172
- channel: channel,
173
- updater_proc: updater_proc,
174
- scopes: scopes,
175
- interceptors: interceptors,
176
- &Google::Cloud::Speech::V1p1beta1::Speech::Stub.method(:new)
177
- )
178
-
179
- @recognize = Google::Gax.create_api_call(
180
- @speech_stub.method(:recognize),
181
- defaults["recognize"],
182
- exception_transformer: exception_transformer
183
- )
184
- @long_running_recognize = Google::Gax.create_api_call(
185
- @speech_stub.method(:long_running_recognize),
186
- defaults["long_running_recognize"],
187
- exception_transformer: exception_transformer
188
- )
189
- @streaming_recognize = Google::Gax.create_api_call(
190
- @speech_stub.method(:streaming_recognize),
191
- defaults["streaming_recognize"],
192
- exception_transformer: exception_transformer
193
- )
194
- end
195
-
196
- # Service calls
197
-
198
- # Performs synchronous speech recognition: receive results after all audio
199
- # has been sent and processed.
200
- #
201
- # @param config [Google::Cloud::Speech::V1p1beta1::RecognitionConfig | Hash]
202
- # *Required* Provides information to the recognizer that specifies how to
203
- # process the request.
204
- # A hash of the same form as `Google::Cloud::Speech::V1p1beta1::RecognitionConfig`
205
- # can also be provided.
206
- # @param audio [Google::Cloud::Speech::V1p1beta1::RecognitionAudio | Hash]
207
- # *Required* The audio data to be recognized.
208
- # A hash of the same form as `Google::Cloud::Speech::V1p1beta1::RecognitionAudio`
209
- # can also be provided.
210
- # @param options [Google::Gax::CallOptions]
211
- # Overrides the default settings for this call, e.g, timeout,
212
- # retries, etc.
213
- # @yield [result, operation] Access the result along with the RPC operation
214
- # @yieldparam result [Google::Cloud::Speech::V1p1beta1::RecognizeResponse]
215
- # @yieldparam operation [GRPC::ActiveCall::Operation]
216
- # @return [Google::Cloud::Speech::V1p1beta1::RecognizeResponse]
217
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
218
- # @example
219
- # require "google/cloud/speech"
220
- #
221
- # speech_client = Google::Cloud::Speech.new(version: :v1p1beta1)
222
- # encoding = :FLAC
223
- # sample_rate_hertz = 44100
224
- # language_code = "en-US"
225
- # config = {
226
- # encoding: encoding,
227
- # sample_rate_hertz: sample_rate_hertz,
228
- # language_code: language_code
229
- # }
230
- # uri = "gs://bucket_name/file_name.flac"
231
- # audio = { uri: uri }
232
- # response = speech_client.recognize(config, audio)
233
-
234
- def recognize \
235
- config,
236
- audio,
237
- options: nil,
238
- &block
239
- req = {
240
- config: config,
241
- audio: audio
242
- }.delete_if { |_, v| v.nil? }
243
- req = Google::Gax::to_proto(req, Google::Cloud::Speech::V1p1beta1::RecognizeRequest)
244
- @recognize.call(req, options, &block)
245
- end
246
-
247
- # Performs asynchronous speech recognition: receive results via the
248
- # google.longrunning.Operations interface. Returns either an
249
- # `Operation.error` or an `Operation.response` which contains
250
- # a `LongRunningRecognizeResponse` message.
251
- #
252
- # @param config [Google::Cloud::Speech::V1p1beta1::RecognitionConfig | Hash]
253
- # *Required* Provides information to the recognizer that specifies how to
254
- # process the request.
255
- # A hash of the same form as `Google::Cloud::Speech::V1p1beta1::RecognitionConfig`
256
- # can also be provided.
257
- # @param audio [Google::Cloud::Speech::V1p1beta1::RecognitionAudio | Hash]
258
- # *Required* The audio data to be recognized.
259
- # A hash of the same form as `Google::Cloud::Speech::V1p1beta1::RecognitionAudio`
260
- # can also be provided.
261
- # @param options [Google::Gax::CallOptions]
262
- # Overrides the default settings for this call, e.g, timeout,
263
- # retries, etc.
264
- # @return [Google::Gax::Operation]
265
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
266
- # @example
267
- # require "google/cloud/speech"
268
- #
269
- # speech_client = Google::Cloud::Speech.new(version: :v1p1beta1)
270
- # encoding = :FLAC
271
- # sample_rate_hertz = 44100
272
- # language_code = "en-US"
273
- # config = {
274
- # encoding: encoding,
275
- # sample_rate_hertz: sample_rate_hertz,
276
- # language_code: language_code
277
- # }
278
- # uri = "gs://bucket_name/file_name.flac"
279
- # audio = { uri: uri }
280
- #
281
- # # Register a callback during the method call.
282
- # operation = speech_client.long_running_recognize(config, audio) do |op|
283
- # raise op.results.message if op.error?
284
- # op_results = op.results
285
- # # Process the results.
286
- #
287
- # metadata = op.metadata
288
- # # Process the metadata.
289
- # end
290
- #
291
- # # Or use the return value to register a callback.
292
- # operation.on_done do |op|
293
- # raise op.results.message if op.error?
294
- # op_results = op.results
295
- # # Process the results.
296
- #
297
- # metadata = op.metadata
298
- # # Process the metadata.
299
- # end
300
- #
301
- # # Manually reload the operation.
302
- # operation.reload!
303
- #
304
- # # Or block until the operation completes, triggering callbacks on
305
- # # completion.
306
- # operation.wait_until_done!
307
-
308
- def long_running_recognize \
309
- config,
310
- audio,
311
- options: nil
312
- req = {
313
- config: config,
314
- audio: audio
315
- }.delete_if { |_, v| v.nil? }
316
- req = Google::Gax::to_proto(req, Google::Cloud::Speech::V1p1beta1::LongRunningRecognizeRequest)
317
- operation = Google::Gax::Operation.new(
318
- @long_running_recognize.call(req, options),
319
- @operations_client,
320
- Google::Cloud::Speech::V1p1beta1::LongRunningRecognizeResponse,
321
- Google::Cloud::Speech::V1p1beta1::LongRunningRecognizeMetadata,
322
- call_options: options
323
- )
324
- operation.on_done { |operation| yield(operation) } if block_given?
325
- operation
326
- end
327
- end
328
- end
329
- end
330
- end
331
- end
@@ -1,41 +0,0 @@
1
- {
2
- "interfaces": {
3
- "google.cloud.speech.v1p1beta1.Speech": {
4
- "retry_codes": {
5
- "idempotent": [
6
- "DEADLINE_EXCEEDED",
7
- "UNAVAILABLE"
8
- ],
9
- "non_idempotent": []
10
- },
11
- "retry_params": {
12
- "default": {
13
- "initial_retry_delay_millis": 100,
14
- "retry_delay_multiplier": 1.3,
15
- "max_retry_delay_millis": 60000,
16
- "initial_rpc_timeout_millis": 1000000,
17
- "rpc_timeout_multiplier": 1.0,
18
- "max_rpc_timeout_millis": 1000000,
19
- "total_timeout_millis": 5000000
20
- }
21
- },
22
- "methods": {
23
- "Recognize": {
24
- "timeout_millis": 200000,
25
- "retry_codes_name": "idempotent",
26
- "retry_params_name": "default"
27
- },
28
- "LongRunningRecognize": {
29
- "timeout_millis": 200000,
30
- "retry_codes_name": "non_idempotent",
31
- "retry_params_name": "default"
32
- },
33
- "StreamingRecognize": {
34
- "timeout_millis": 905000,
35
- "retry_codes_name": "idempotent",
36
- "retry_params_name": "default"
37
- }
38
- }
39
- }
40
- }
41
- }