google-cloud-speech 0.28.0 → 0.29.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ea8bfc2549536e0da9030f8dfc3cc3abbbdf6f2f611ad761901720e67d84b8f
4
- data.tar.gz: 83808483ace60d98c0166416867ee40122f3158e92e6757d46684264b3c6ac45
3
+ metadata.gz: 1c8413795f1ff1fc9d4cf12d6d60c49fe0239788fc150a7e2717fb0553659c53
4
+ data.tar.gz: 316185b6b5db45d5e7bdcf4ed800bbf06d39b049938d7e5b47502576a261a41f
5
5
  SHA512:
6
- metadata.gz: 89d38a6c84418d91afac2858a919d94e5486bee9c0b461dac6ace854eb2b1a940f9210c576c65d2f091a25fc40d23e0e5008e63152b46ceaf6bf1ccc374dc2be
7
- data.tar.gz: c070e9db594451f1567e01a0f7739dc95692c99cfd129ae0a5a668ccd35897de05c6410a83c82925837f0c725308005499ccdf8b9303f87bcb2c49a7fd546900
6
+ metadata.gz: 435c456d09e05127f99dceba69eca467cdef99101064668a1a888824d8b24eff2ccab37474c5ba801b5d797138fa9ceb9d9dbf5cc541384be0b178505e26e9bd
7
+ data.tar.gz: a766e0c9faf23aaa982cb0d5a1c9c5678d7b6227f09faf9de330c09bce559527d32e2a22e0bc1cac98b018e8d9aeb162ce534637161a3499bfcf25f876591155
@@ -20,6 +20,8 @@
20
20
 
21
21
  gem "google-cloud-core"
22
22
  require "google/cloud"
23
+ require "google/cloud/config"
24
+ require "googleauth"
23
25
 
24
26
  module Google
25
27
  module Cloud
@@ -115,3 +117,26 @@ module Google
115
117
  end
116
118
  end
117
119
  end
120
+
121
+ # Set the default speech configuration
122
+ Google::Cloud.configure.add_config! :speech do |config|
123
+ default_project = Google::Cloud::Config.deferred do
124
+ ENV["SPEECH_PROJECT"]
125
+ end
126
+ default_creds = Google::Cloud::Config.deferred do
127
+ Google::Cloud::Config.credentials_from_env(
128
+ "SPEECH_CREDENTIALS", "SPEECH_CREDENTIALS_JSON",
129
+ "SPEECH_KEYFILE", "SPEECH_KEYFILE_JSON"
130
+ )
131
+ end
132
+
133
+ config.add_field! :project_id, default_project, match: String, allow_nil: true
134
+ config.add_alias! :project, :project_id
135
+ config.add_field! :credentials, default_creds,
136
+ match: [String, Hash, Google::Auth::Credentials],
137
+ allow_nil: true
138
+ config.add_alias! :keyfile, :credentials
139
+ config.add_field! :scope, nil, match: [String, Array]
140
+ config.add_field! :timeout, nil, match: Integer
141
+ config.add_field! :client_config, nil, match: Hash
142
+ end
@@ -15,6 +15,8 @@
15
15
 
16
16
  require "google-cloud-speech"
17
17
  require "google/cloud/speech/project"
18
+ require "google/cloud/config"
19
+ require "google/cloud/env"
18
20
 
19
21
  module Google
20
22
  module Cloud
@@ -34,11 +36,12 @@ module Google
34
36
  # Speech API Documentation](https://cloud.google.com/speech/docs/).
35
37
  #
36
38
  # The goal of google-cloud is to provide an API that is comfortable to
37
- # Rubyists. Authentication is handled by {Google::Cloud#speech}. You can
38
- # provide the project and credential information to connect to the Cloud
39
- # Speech service, or if you are running on Google Compute Engine this
40
- # configuration is taken care of for you. You can read more about the
41
- # options for connecting in the [Authentication
39
+ # Rubyists. Your authentication credentials are detected automatically in
40
+ # Google Cloud Platform environments such as Google Compute Engine, Google
41
+ # App Engine and Google Kubernetes Engine. In other environments you can
42
+ # configure authentication easily, either directly in your code or via
43
+ # environment variables. Read more about the options for connecting in the
44
+ # [Authentication
42
45
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
43
46
  #
44
47
  # ## Creating audio sources
@@ -224,11 +227,14 @@ module Google
224
227
  #
225
228
  def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
226
229
  client_config: nil, project: nil, keyfile: nil
227
- project_id ||= (project || Speech::Project.default_project_id)
230
+ project_id ||= (project || default_project_id)
228
231
  project_id = project_id.to_s # Always cast to a string
229
- fail ArgumentError, "project_id is missing" if project_id.empty?
232
+ raise ArgumentError, "project_id is missing" if project_id.empty?
230
233
 
231
- credentials ||= (keyfile || Speech::Credentials.default(scope: scope))
234
+ scope ||= configure.scope
235
+ timeout ||= configure.timeout
236
+ client_config ||= configure.client_config
237
+ credentials ||= (keyfile || default_credentials(scope: scope))
232
238
  unless credentials.is_a? Google::Auth::Credentials
233
239
  credentials = Speech::Credentials.new credentials, scope: scope
234
240
  end
@@ -236,7 +242,51 @@ module Google
236
242
  Speech::Project.new(
237
243
  Speech::Service.new(
238
244
  project_id, credentials, timeout: timeout,
239
- client_config: client_config))
245
+ client_config: client_config
246
+ )
247
+ )
248
+ end
249
+
250
+ ##
251
+ # Configure the Google Cloud Speech library.
252
+ #
253
+ # The following Speech configuration parameters are supported:
254
+ #
255
+ # * `project_id` - (String) Identifier for a Speech project. (The
256
+ # parameter `project` is considered deprecated, but may also be used.)
257
+ # * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
258
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
259
+ # Google::Auth::Credentials object. (See {Speech::Credentials}) (The
260
+ # parameter `keyfile` is considered deprecated, but may also be used.)
261
+ # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
262
+ # the set of resources and operations that the connection can access.
263
+ # * `timeout` - (Integer) Default timeout to use in requests.
264
+ # * `client_config` - (Hash) A hash of values to override the default
265
+ # behavior of the API client.
266
+ #
267
+ # @return [Google::Cloud::Config] The configuration object the
268
+ # Google::Cloud::Speech library uses.
269
+ #
270
+ def self.configure
271
+ yield Google::Cloud.configure.speech if block_given?
272
+
273
+ Google::Cloud.configure.speech
274
+ end
275
+
276
+ ##
277
+ # @private Default project.
278
+ def self.default_project_id
279
+ Google::Cloud.configure.speech.project_id ||
280
+ Google::Cloud.configure.project_id ||
281
+ Google::Cloud.env.project_id
282
+ end
283
+
284
+ ##
285
+ # @private Default credentials.
286
+ def self.default_credentials scope: nil
287
+ Google::Cloud.configure.speech.credentials ||
288
+ Google::Cloud.configure.credentials ||
289
+ Speech::Credentials.default(scope: scope)
240
290
  end
241
291
  end
242
292
  end
@@ -279,8 +279,8 @@ module Google
279
279
  profanity_filter: profanity_filter,
280
280
  phrases: phrases, words: words
281
281
  end
282
- alias_method :long_running_recognize, :process
283
- alias_method :recognize_job, :process
282
+ alias long_running_recognize process
283
+ alias recognize_job process
284
284
 
285
285
  ##
286
286
  # @private The Google API Client object for the Audio.
@@ -309,12 +309,12 @@ module Google
309
309
  end
310
310
  # Create an audio from a file on the filesystem
311
311
  if File.file? source
312
- fail ArgumentError, "Cannot read #{source}" unless \
312
+ raise ArgumentError, "Cannot read #{source}" unless \
313
313
  File.readable? source
314
314
  audio.grpc.content = File.read source, mode: "rb"
315
315
  return audio
316
316
  end
317
- fail ArgumentError, "Unable to convert #{source} to an Audio"
317
+ raise ArgumentError, "Unable to convert #{source} to an Audio"
318
318
  end
319
319
 
320
320
  protected
@@ -322,7 +322,7 @@ module Google
322
322
  ##
323
323
  # Raise an error unless an active Speech Project object is available.
324
324
  def ensure_speech!
325
- fail "Must have active connection" unless @speech
325
+ raise "Must have active connection" unless @speech
326
326
  end
327
327
  end
328
328
  end
@@ -33,7 +33,7 @@ module Google
33
33
  def duration_to_number duration
34
34
  return nil if duration.nil?
35
35
 
36
- return duration.seconds if duration.nanos == 0
36
+ return duration.seconds if duration.nanos.zero?
37
37
 
38
38
  duration.seconds + (duration.nanos / 1000000000.0)
39
39
  end
@@ -38,19 +38,19 @@ module Google
38
38
  # speech.project_id #=> "my-project"
39
39
  #
40
40
  class Credentials < Google::Auth::Credentials
41
- SCOPE = ["https://www.googleapis.com/auth/cloud-platform"]
42
- PATH_ENV_VARS = %w(SPEECH_CREDENTIALS
41
+ SCOPE = ["https://www.googleapis.com/auth/cloud-platform"].freeze
42
+ PATH_ENV_VARS = %w[SPEECH_CREDENTIALS
43
43
  SPEECH_KEYFILE
44
44
  GOOGLE_CLOUD_CREDENTIALS
45
45
  GOOGLE_CLOUD_KEYFILE
46
- GCLOUD_KEYFILE)
47
- JSON_ENV_VARS = %w(SPEECH_CREDENTIALS_JSON
46
+ GCLOUD_KEYFILE].freeze
47
+ JSON_ENV_VARS = %w[SPEECH_CREDENTIALS_JSON
48
48
  SPEECH_KEYFILE_JSON
49
49
  GOOGLE_CLOUD_CREDENTIALS_JSON
50
50
  GOOGLE_CLOUD_KEYFILE_JSON
51
- GCLOUD_KEYFILE_JSON)
51
+ GCLOUD_KEYFILE_JSON].freeze
52
52
  DEFAULT_PATHS = \
53
- ["~/.config/gcloud/application_default_credentials.json"]
53
+ ["~/.config/gcloud/application_default_credentials.json"].freeze
54
54
  end
55
55
  end
56
56
  end
@@ -224,7 +224,7 @@ module Google
224
224
  @grpc.reload!
225
225
  self
226
226
  end
227
- alias_method :refresh!, :reload!
227
+ alias refresh! reload!
228
228
 
229
229
  ##
230
230
  # Reloads the op until the operation is complete. The delay between
@@ -14,7 +14,6 @@
14
14
 
15
15
 
16
16
  require "google/cloud/errors"
17
- require "google/cloud/env"
18
17
  require "google/cloud/speech/service"
19
18
  require "google/cloud/speech/audio"
20
19
  require "google/cloud/speech/result"
@@ -79,16 +78,7 @@ module Google
79
78
  def project_id
80
79
  service.project
81
80
  end
82
- alias_method :project, :project_id
83
-
84
- ##
85
- # @private Default project.
86
- def self.default_project_id
87
- ENV["SPEECH_PROJECT"] ||
88
- ENV["GOOGLE_CLOUD_PROJECT"] ||
89
- ENV["GCLOUD_PROJECT"] ||
90
- Google::Cloud.env.project_id
91
- end
81
+ alias project project_id
92
82
 
93
83
  ##
94
84
  # Returns a new Audio instance from the given source. No API call is
@@ -185,11 +175,11 @@ module Google
185
175
  # sample_rate: 16000
186
176
  #
187
177
  def audio source, encoding: nil, language: nil, sample_rate: nil
188
- if source.is_a? Audio
189
- audio = source.dup
190
- else
191
- audio = Audio.from_source source, self
192
- end
178
+ audio = if source.is_a? Audio
179
+ source.dup
180
+ else
181
+ Audio.from_source source, self
182
+ end
193
183
  audio.encoding = encoding unless encoding.nil?
194
184
  audio.language = language unless language.nil?
195
185
  audio.sample_rate = sample_rate unless sample_rate.nil?
@@ -324,7 +314,8 @@ module Google
324
314
  encoding: audio_obj.encoding, sample_rate: audio_obj.sample_rate,
325
315
  language: audio_obj.language, max_alternatives: max_alternatives,
326
316
  profanity_filter: profanity_filter, phrases: phrases,
327
- words: words)
317
+ words: words
318
+ )
328
319
 
329
320
  grpc = service.recognize_sync audio_obj.to_grpc, config
330
321
  grpc.results.map do |result_grpc|
@@ -462,13 +453,14 @@ module Google
462
453
  encoding: audio_obj.encoding, sample_rate: audio_obj.sample_rate,
463
454
  language: audio_obj.language, max_alternatives: max_alternatives,
464
455
  profanity_filter: profanity_filter, phrases: phrases,
465
- words: words)
456
+ words: words
457
+ )
466
458
 
467
459
  grpc = service.recognize_async audio_obj.to_grpc, config
468
460
  Operation.from_grpc grpc
469
461
  end
470
- alias_method :long_running_recognize, :process
471
- alias_method :recognize_job, :process
462
+ alias long_running_recognize process
463
+ alias recognize_job process
472
464
 
473
465
  ##
474
466
  # Creates a Stream object to perform bidirectional streaming
@@ -587,7 +579,7 @@ module Google
587
579
 
588
580
  Stream.new service, grpc_req
589
581
  end
590
- alias_method :stream_recognize, :stream
582
+ alias stream_recognize stream
591
583
 
592
584
  ##
593
585
  # Performs asynchronous speech recognition. Requests are processed
@@ -651,7 +643,7 @@ module Google
651
643
  # @private Raise an error unless an active connection to the service is
652
644
  # available.
653
645
  def ensure_service!
654
- fail "Must have active connection to service" unless service
646
+ raise "Must have active connection to service" unless service
655
647
  end
656
648
  end
657
649
  end
@@ -104,7 +104,7 @@ module Google
104
104
  # experimental feature and the accuracy of the time offset can vary.
105
105
  class Word
106
106
  attr_reader :word, :start_time, :end_time
107
- alias_method :to_str, :word
107
+ alias to_str word
108
108
 
109
109
  ##
110
110
  # @private Creates a new Result::Word instance.
@@ -218,7 +218,7 @@ module Google
218
218
  ##
219
219
  # @private Creates a new InterimResult instance.
220
220
  def initialize transcript, confidence, stability, alternatives = []
221
- @transcript = transcript
221
+ @transcript = transcript
222
222
  @confidence = confidence
223
223
  @stability = stability
224
224
  @alternatives = alternatives
@@ -50,7 +50,8 @@ module Google
50
50
  timeout: timeout,
51
51
  client_config: client_config,
52
52
  lib_name: "gccl",
53
- lib_version: Google::Cloud::Speech::VERSION)
53
+ lib_version: Google::Cloud::Speech::VERSION
54
+ )
54
55
  end
55
56
  attr_accessor :mocked_service
56
57
 
@@ -62,7 +63,8 @@ module Google
62
63
  timeout: timeout,
63
64
  client_config: client_config,
64
65
  lib_name: "gccl",
65
- lib_version: Google::Cloud::Speech::VERSION)
66
+ lib_version: Google::Cloud::Speech::VERSION
67
+ )
66
68
  end
67
69
  attr_accessor :mocked_ops
68
70
 
@@ -119,7 +119,8 @@ module Google
119
119
  # TODO: do not send if stopped?
120
120
  synchronize do
121
121
  req = V1::StreamingRecognizeRequest.new(
122
- audio_content: bytes.encode("ASCII-8BIT"))
122
+ audio_content: bytes.encode("ASCII-8BIT")
123
+ )
123
124
  @request_queue.push req
124
125
  end
125
126
  end
@@ -489,11 +490,11 @@ module Google
489
490
  background_results response
490
491
  background_event_type response.speech_event_type
491
492
  background_error response.error
492
- rescue => e
493
+ rescue StandardError => e
493
494
  error! Google::Cloud::Error.from_error(e)
494
495
  end
495
496
  end
496
- rescue => e
497
+ rescue StandardError => e
497
498
  error! Google::Cloud::Error.from_error(e)
498
499
  ensure
499
500
  pass_complete!
@@ -532,7 +533,7 @@ module Google
532
533
  return if error.nil?
533
534
 
534
535
  require "grpc/errors"
535
- fail GRPC::BadStatus.new(error.code, error.message)
536
+ raise GRPC::BadStatus.new(error.code, error.message)
536
537
  end
537
538
 
538
539
  # @private
@@ -552,7 +553,7 @@ module Google
552
553
  loop do
553
554
  r = @q.pop
554
555
  break if r.equal? @sentinel
555
- fail r if r.is_a? Exception
556
+ raise r if r.is_a? Exception
556
557
  yield r
557
558
  end
558
559
  end
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Speech
19
- VERSION = "0.28.0"
19
+ VERSION = "0.29.0".freeze
20
20
  end
21
21
  end
22
22
  end
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.28.0
4
+ version: 0.29.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-12-19 00:00:00.000000000 Z
12
+ date: 2018-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.1'
20
+ version: '1.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.1'
27
+ version: '1.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: google-gax
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -113,16 +113,16 @@ dependencies:
113
113
  name: rubocop
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - "<="
116
+ - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: 0.35.1
118
+ version: 0.50.0
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - "<="
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: 0.35.1
125
+ version: 0.50.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: simplecov
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  version: '0'
218
218
  requirements: []
219
219
  rubyforge_project:
220
- rubygems_version: 2.7.3
220
+ rubygems_version: 2.7.6
221
221
  signing_key:
222
222
  specification_version: 4
223
223
  summary: API Client library for Google Cloud Speech API