google-cloud-speech 0.29.0 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/LICENSE +1 -1
  4. data/README.md +69 -43
  5. data/lib/google/cloud/speech.rb +94 -252
  6. data/lib/google/cloud/speech/v1.rb +11 -1
  7. data/lib/google/cloud/speech/v1/cloud_speech_services_pb.rb +1 -1
  8. data/lib/google/cloud/speech/{version.rb → v1/credentials.rb} +12 -2
  9. data/lib/google/cloud/speech/v1/doc/google/cloud/speech/v1/cloud_speech.rb +2 -2
  10. data/lib/google/cloud/speech/v1/doc/google/longrunning/operations.rb +92 -0
  11. data/lib/google/cloud/speech/v1/doc/google/protobuf/any.rb +1 -1
  12. data/lib/google/cloud/speech/v1/doc/google/protobuf/duration.rb +1 -1
  13. data/lib/google/cloud/speech/v1/doc/google/rpc/status.rb +1 -1
  14. data/lib/google/cloud/speech/v1/doc/overview.rb +1 -1
  15. data/lib/google/cloud/speech/v1/helpers.rb +93 -0
  16. data/lib/google/cloud/speech/v1/speech_client.rb +26 -49
  17. data/lib/google/cloud/speech/v1/speech_client_config.json +5 -5
  18. data/lib/google/cloud/speech/v1/stream.rb +614 -0
  19. data/lib/google/cloud/speech/v1p1beta1.rb +126 -0
  20. data/lib/google/cloud/speech/v1p1beta1/cloud_speech_pb.rb +175 -0
  21. data/lib/google/cloud/speech/v1p1beta1/cloud_speech_services_pb.rb +54 -0
  22. data/lib/google/cloud/speech/v1p1beta1/credentials.rb +32 -0
  23. data/lib/google/cloud/speech/v1p1beta1/doc/google/cloud/speech/v1p1beta1/cloud_speech.rb +625 -0
  24. data/lib/google/cloud/speech/v1p1beta1/doc/google/longrunning/operations.rb +92 -0
  25. data/lib/google/cloud/speech/v1p1beta1/doc/google/protobuf/any.rb +124 -0
  26. data/lib/google/cloud/speech/v1p1beta1/doc/google/protobuf/duration.rb +90 -0
  27. data/lib/google/cloud/speech/v1p1beta1/doc/google/rpc/status.rb +83 -0
  28. data/lib/google/cloud/speech/v1p1beta1/doc/overview.rb +73 -0
  29. data/lib/google/cloud/speech/v1p1beta1/helpers.rb +93 -0
  30. data/lib/google/cloud/speech/v1p1beta1/speech_client.rb +322 -0
  31. data/lib/google/cloud/speech/v1p1beta1/speech_client_config.json +41 -0
  32. data/lib/google/cloud/speech/v1p1beta1/stream.rb +614 -0
  33. metadata +29 -120
  34. data/lib/google-cloud-speech.rb +0 -142
  35. data/lib/google/cloud/speech/audio.rb +0 -330
  36. data/lib/google/cloud/speech/convert.rb +0 -46
  37. data/lib/google/cloud/speech/credentials.rb +0 -57
  38. data/lib/google/cloud/speech/operation.rb +0 -262
  39. data/lib/google/cloud/speech/project.rb +0 -651
  40. data/lib/google/cloud/speech/result.rb +0 -240
  41. data/lib/google/cloud/speech/service.rb +0 -121
  42. data/lib/google/cloud/speech/stream.rb +0 -564
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c8413795f1ff1fc9d4cf12d6d60c49fe0239788fc150a7e2717fb0553659c53
4
- data.tar.gz: 316185b6b5db45d5e7bdcf4ed800bbf06d39b049938d7e5b47502576a261a41f
3
+ metadata.gz: 763195f0925921b082ea312d0287d4ca43e57bcdba2348379b2a47df410be135
4
+ data.tar.gz: 30d926a0eecbe5a1a6aa70391d4b83db808425c96e69290171e1c1080ae6b533
5
5
  SHA512:
6
- metadata.gz: 435c456d09e05127f99dceba69eca467cdef99101064668a1a888824d8b24eff2ccab37474c5ba801b5d797138fa9ceb9d9dbf5cc541384be0b178505e26e9bd
7
- data.tar.gz: a766e0c9faf23aaa982cb0d5a1c9c5678d7b6227f09faf9de330c09bce559527d32e2a22e0bc1cac98b018e8d9aeb162ce534637161a3499bfcf25f876591155
6
+ metadata.gz: 7c32bacca6be56b87b96176b1b6dd9afde7910e5958ab7c264206cd34224889ceb6a2b708566eb1b409ef7c17b5a2f7ee23dac6b9d7f56db40ffc92db83a5ecc
7
+ data.tar.gz: 36157d4b83b244f712dfcecbab3a3ce13d7522e7175736c6b50c6234e2e8922d7569f521e71496a054544fcd8bbc0c9686059ba0086b0ab0576bab4a6da6b231
data/.yardopts CHANGED
@@ -1,5 +1,6 @@
1
1
  --no-private
2
- --title=Google Cloud Speech
2
+ --title=Cloud Speech API
3
+ --exclude _pb\.rb$
3
4
  --markup markdown
4
5
 
5
6
  ./lib/**/*.rb
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Apache License
1
+ Apache License
2
2
  Version 2.0, January 2004
3
3
  https://www.apache.org/licenses/
4
4
 
data/README.md CHANGED
@@ -1,64 +1,90 @@
1
- # google-cloud-speech
1
+ # Ruby Client for Cloud Speech API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
2
2
 
3
- [Google Cloud Speech API](https://cloud.google.com/speech/) ([docs](https://cloud.google.com/speech/docs)) enables developers to convert audio to text by applying powerful neural network models.
4
-
5
- - [google-cloud-speech API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-speech/latest)
6
- - [google-cloud-speech on RubyGems](https://rubygems.org/gems/google-cloud-speech)
7
- - [Google Cloud Speech API documentation](https://cloud.google.com/speech/docs)
3
+ [Cloud Speech API][Product Documentation]:
4
+ Converts audio to text by applying powerful neural network models.
5
+ - [Client Library Documentation][]
6
+ - [Product Documentation][]
8
7
 
9
8
  ## Quick Start
9
+ In order to use this library, you first need to go through the following
10
+ steps:
11
+
12
+ 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
13
+ 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
14
+ 3. [Enable the Cloud Speech API.](https://console.cloud.google.com/apis/api/speech)
15
+ 4. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
10
16
 
11
- ```sh
17
+ ### Installation
18
+ ```
12
19
  $ gem install google-cloud-speech
13
20
  ```
14
21
 
15
- ## Authentication
16
-
17
- This library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.
18
-
19
- Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-speech/guides/authentication).
22
+ ### Migration Guide
20
23
 
21
- ## Example
24
+ The 0.30.0 release introduced breaking changes relative to the previous release,
25
+ 0.29.0. For more details and instructions to migrate your code, please visit the
26
+ [migration
27
+ guide](https://cloud.google.com/speech-to-text/docs/ruby-client-migration).
22
28
 
23
- ```ruby
29
+ ### Preview
30
+ #### SpeechClient
31
+ ```rb
24
32
  require "google/cloud/speech"
25
33
 
26
- speech = Google::Cloud::Speech.new
27
-
28
- audio = speech.audio "path/to/audio.raw",
29
- encoding: :linear16,
30
- language: "en-US",
31
- sample_rate: 16000
32
-
33
- results = audio.recognize
34
- result = results.first
35
- result.transcript #=> "how old is the Brooklyn Bridge"
36
- result.confidence #=> 0.9826789498329163
34
+ speech_client = Google::Cloud::Speech.new
35
+ language_code = "en-US"
36
+ sample_rate_hertz = 44100
37
+ encoding = :FLAC
38
+ config = {
39
+ language_code: language_code,
40
+ sample_rate_hertz: sample_rate_hertz,
41
+ encoding: encoding
42
+ }
43
+ uri = "gs://gapic-toolkit/hello.flac"
44
+ audio = { uri: uri }
45
+ response = speech_client.recognize(config, audio)
37
46
  ```
38
47
 
39
- ## Supported Ruby Versions
40
-
41
- This library is supported on Ruby 2.0+.
42
-
43
- ## Versioning
44
-
45
- This library follows [Semantic Versioning](http://semver.org/).
46
-
47
- It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.
48
+ ### Next Steps
49
+ - Read the [Client Library Documentation][] for Cloud Speech API
50
+ to see other available methods on the client.
51
+ - Read the [Cloud Speech API Product documentation][Product Documentation]
52
+ to learn more about the product and see How-to Guides.
53
+ - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
54
+ to see the full list of Cloud APIs that we cover.
48
55
 
49
- ## Contributing
56
+ ## Enabling Logging
50
57
 
51
- Contributions to this library are always welcome and highly encouraged.
58
+ To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger) that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
52
59
 
53
- See the [Contributing Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/contributing) for more information on how to get started.
60
+ Configuring a Ruby stdlib logger:
54
61
 
55
- Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct](../CODE_OF_CONDUCT.md) for more information.
62
+ ```ruby
63
+ require "logger"
64
+
65
+ module MyLogger
66
+ LOGGER = Logger.new $stderr, level: Logger::WARN
67
+ def logger
68
+ LOGGER
69
+ end
70
+ end
71
+
72
+ # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
73
+ module GRPC
74
+ extend MyLogger
75
+ end
76
+ ```
56
77
 
57
- ## License
78
+ ## Supported Ruby Versions
58
79
 
59
- This library is licensed under Apache 2.0. Full license text is available in [LICENSE](LICENSE).
80
+ This library is supported on Ruby 2.0+.
60
81
 
61
- ## Support
82
+ However, Ruby 2.3 or later is strongly recommended, as earlier releases have
83
+ reached or are nearing end-of-life. After June 1, 2018, Google will provide
84
+ official support only for Ruby versions that are considered current and
85
+ supported by Ruby Core (that is, Ruby versions that are either in normal
86
+ maintenance or in security maintenance).
87
+ See https://www.ruby-lang.org/en/downloads/branches/ for further details.
62
88
 
63
- Please [report bugs at the project on Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues).
64
- Don't hesitate to [ask questions](http://stackoverflow.com/questions/tagged/google-cloud-ruby) about the client or APIs on [StackOverflow](http://stackoverflow.com).
89
+ [Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-speech/latest/google/cloud/speech
90
+ [Product Documentation]: https://cloud.google.com/speech
@@ -1,4 +1,4 @@
1
- # Copyright 2016 Google LLC
1
+ # Copyright 2018 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -12,281 +12,123 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
-
16
- require "google-cloud-speech"
17
- require "google/cloud/speech/project"
18
- require "google/cloud/config"
19
- require "google/cloud/env"
15
+ require "google/gax"
16
+ require "pathname"
20
17
 
21
18
  module Google
22
19
  module Cloud
20
+ # rubocop:disable LineLength
21
+
23
22
  ##
24
- # # Google Cloud Speech
25
- #
26
- # Google Cloud Speech API enables developers to convert audio to text by
27
- # applying powerful neural network models in an easy to use API. The API
28
- # recognizes over 80 languages and variants, to support your global user
29
- # base. You can transcribe the text of users dictating to an application's
30
- # microphone, enable command-and-control through voice, or transcribe audio
31
- # files, among many other use cases. Recognize audio uploaded in the
32
- # request, and integrate with your audio storage on Google Cloud Storage, by
33
- # using the same technology Google uses to power its own products.
23
+ # # Ruby Client for Google Cloud Speech API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
34
24
  #
35
- # For more information about Google Cloud Speech API, read the [Google Cloud
36
- # Speech API Documentation](https://cloud.google.com/speech/docs/).
25
+ # [Google Cloud Speech API][Product Documentation]:
26
+ # Google Cloud Speech API.
27
+ # - [Product Documentation][]
37
28
  #
38
- # The goal of google-cloud is to provide an API that is comfortable to
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
45
- # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
29
+ # ## Quick Start
30
+ # In order to use this library, you first need to go through the following
31
+ # steps:
46
32
  #
47
- # ## Creating audio sources
33
+ # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
34
+ # 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
35
+ # 3. [Enable the Google Cloud Speech API.](https://console.cloud.google.com/apis/api/speech)
36
+ # 4. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
48
37
  #
49
- # You can create an audio object that holds a reference to any one of
50
- # several types of audio data source, along with metadata such as the audio
51
- # encoding type.
38
+ # ### Migration Guide
52
39
  #
53
- # Use {Speech::Project#audio} to create audio sources for the Cloud Speech
54
- # API. You can provide a file path:
40
+ # The 0.30.0 release introduced breaking changes relative to the previous
41
+ # release, 0.29.0. For more details and instructions to migrate your code,
42
+ # please visit the [migration
43
+ # guide](https://cloud.google.com/speech-to-text/docs/ruby-client-migration).
55
44
  #
56
- # ```ruby
45
+ # ### Preview
46
+ # #### SpeechClient
47
+ # ```rb
57
48
  # require "google/cloud/speech"
58
49
  #
59
- # speech = Google::Cloud::Speech.new
60
- #
61
- # audio = speech.audio "path/to/audio.raw",
62
- # encoding: :linear16,
63
- # language: "en-US",
64
- # sample_rate: 16000
50
+ # speech_client = Google::Cloud::Speech.new
51
+ # language_code = "en-US"
52
+ # sample_rate_hertz = 44100
53
+ # encoding = :FLAC
54
+ # config = {
55
+ # language_code: language_code,
56
+ # sample_rate_hertz: sample_rate_hertz,
57
+ # encoding: encoding
58
+ # }
59
+ # uri = "gs://gapic-toolkit/hello.flac"
60
+ # audio = { uri: uri }
61
+ # response = speech_client.recognize(config, audio)
65
62
  # ```
66
63
  #
67
- # Or, you can initialize the audio instance with a Google Cloud Storage URI:
68
- #
69
- # ```ruby
70
- # require "google/cloud/speech"
71
- #
72
- # speech = Google::Cloud::Speech.new
73
- #
74
- # audio = speech.audio "gs://bucket-name/path/to/audio.raw",
75
- # encoding: :linear16,
76
- # language: "en-US",
77
- # sample_rate: 16000
78
- # ```
64
+ # ### Next Steps
65
+ # - Read the [Google Cloud Speech API Product documentation][Product Documentation]
66
+ # to learn more about the product and see How-to Guides.
67
+ # - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
68
+ # to see the full list of Cloud APIs that we cover.
79
69
  #
80
- # Or, with a Google Cloud Storage File object:
81
- #
82
- # ```ruby
83
- # require "google/cloud/storage"
84
- #
85
- # storage = Google::Cloud::Storage.new
86
- #
87
- # bucket = storage.bucket "bucket-name"
88
- # file = bucket.file "path/to/audio.raw"
89
- #
90
- # require "google/cloud/speech"
91
- #
92
- # speech = Google::Cloud::Speech.new
93
- #
94
- # audio = speech.audio file,
95
- # encoding: :linear16,
96
- # language: "en-US",
97
- # sample_rate: 16000
98
- # ```
70
+ # [Product Documentation]: https://cloud.google.com/speech
99
71
  #
100
- # ## Recognizing speech
101
- #
102
- # The instance methods on {Speech::Audio} can be used to invoke both
103
- # synchronous and asynchronous versions of the Cloud Speech API speech
104
- # recognition operation.
105
- #
106
- # Use {Speech::Audio#recognize} for synchronous speech recognition that
107
- # returns {Speech::Result} objects only after all audio has been processed.
108
- # This method is limited to audio data of 1 minute or less in duration, and
109
- # will take roughly the same amount of time to process as the duration of
110
- # the supplied audio data.
111
- #
112
- # ```ruby
113
- # require "google/cloud/speech"
114
- #
115
- # speech = Google::Cloud::Speech.new
116
- #
117
- # audio = speech.audio "path/to/audio.raw",
118
- # encoding: :linear16,
119
- # language: "en-US",
120
- # sample_rate: 16000
121
- #
122
- # results = audio.recognize
123
- # result = results.first
124
- # result.transcript #=> "how old is the Brooklyn Bridge"
125
- # result.confidence #=> 0.9826789498329163
126
- # ```
127
- #
128
- # Use {Speech::Audio#process} for asynchronous speech recognition, in which
129
- # a {Speech::Operation} is returned immediately after the audio data has
130
- # been sent. The op can be refreshed to retrieve {Speech::Result} objects
131
- # once the audio data has been processed.
132
- #
133
- # ```ruby
134
- # require "google/cloud/speech"
135
- #
136
- # speech = Google::Cloud::Speech.new
137
- #
138
- # audio = speech.audio "path/to/audio.raw",
139
- # encoding: :linear16,
140
- # language: "en-US",
141
- # sample_rate: 16000
142
- #
143
- # op = audio.process
144
- # op.done? #=> false
145
- # op.wait_until_done!
146
- # op.done? #=> true
147
- # results = op.results
148
- #
149
- # result = results.first
150
- # result.transcript #=> "how old is the Brooklyn Bridge"
151
- # result.confidence #=> 0.9826789498329163
152
- # ```
153
- #
154
- # Use {Speech::Project#stream} for streaming audio data for speech
155
- # recognition, in which a {Speech::Stream} is returned. The stream object
156
- # can receive results while sending audio by performing bidirectional
157
- # streaming speech-recognition.
158
- #
159
- # ```ruby
160
- # require "google/cloud/speech"
161
- #
162
- # speech = Google::Cloud::Speech.new
163
- #
164
- # stream = speech.stream encoding: :linear16,
165
- # language: "en-US",
166
- # sample_rate: 16000
167
- #
168
- # # Stream 5 seconds of audio from the microphone
169
- # # Actual implementation of microphone input varies by platform
170
- # 5.times do
171
- # stream.send MicrophoneInput.read(32000)
172
- # end
173
- #
174
- # stream.stop
175
- # stream.wait_until_complete!
176
- #
177
- # results = stream.results
178
- # result = results.first
179
- # result.transcript #=> "how old is the Brooklyn Bridge"
180
- # result.confidence #=> 0.9826789498329163
181
- # ```
182
- #
183
- # Obtaining audio data from input sources such as a Microphone is outside
184
- # the scope of this document.
185
72
  #
186
73
  module Speech
187
- ##
188
- # Creates a new object for connecting to the Speech service.
189
- # Each call creates a new connection.
190
- #
191
- # For more information on connecting to Google Cloud see the
192
- # [Authentication
193
- # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
194
- #
195
- # @param [String] project_id Project identifier for the Speech service
196
- # you are connecting to. If not present, the default project for the
197
- # credentials is used.
198
- # @param [String, Hash, Google::Auth::Credentials] credentials The path to
199
- # the keyfile as a String, the contents of the keyfile as a Hash, or a
200
- # Google::Auth::Credentials object. (See {Speech::Credentials})
201
- # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
202
- # the set of resources and operations that the connection can access.
203
- # See [Using OAuth 2.0 to Access Google
204
- # APIs](https://developers.google.com/identity/protocols/OAuth2).
205
- #
206
- # The default scope is:
207
- #
208
- # * `https://www.googleapis.com/auth/speech`
209
- # @param [Integer] timeout Default timeout to use in requests. Optional.
210
- # @param [Hash] client_config A hash of values to override the default
211
- # behavior of the API client. Optional.
212
- # @param [String] project Alias for the `project_id` argument. Deprecated.
213
- # @param [String] keyfile Alias for the `credentials` argument.
214
- # Deprecated.
215
- #
216
- # @return [Google::Cloud::Speech::Project]
217
- #
218
- # @example
219
- # require "google/cloud/speech"
220
- #
221
- # speech = Google::Cloud::Speech.new
222
- #
223
- # audio = speech.audio "path/to/audio.raw",
224
- # encoding: :linear16,
225
- # language: "en-US",
226
- # sample_rate: 16000
227
- #
228
- def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
229
- client_config: nil, project: nil, keyfile: nil
230
- project_id ||= (project || default_project_id)
231
- project_id = project_id.to_s # Always cast to a string
232
- raise ArgumentError, "project_id is missing" if project_id.empty?
74
+ # rubocop:enable LineLength
233
75
 
234
- scope ||= configure.scope
235
- timeout ||= configure.timeout
236
- client_config ||= configure.client_config
237
- credentials ||= (keyfile || default_credentials(scope: scope))
238
- unless credentials.is_a? Google::Auth::Credentials
239
- credentials = Speech::Credentials.new credentials, scope: scope
240
- end
76
+ FILE_DIR = File.realdirpath(Pathname.new(__FILE__).join("..").join("speech"))
241
77
 
242
- Speech::Project.new(
243
- Speech::Service.new(
244
- project_id, credentials, timeout: timeout,
245
- client_config: client_config
246
- )
247
- )
248
- end
78
+ AVAILABLE_VERSIONS = Dir["#{FILE_DIR}/*"]
79
+ .select { |file| File.directory?(file) }
80
+ .select { |dir| Google::Gax::VERSION_MATCHER.match(File.basename(dir)) }
81
+ .select { |dir| File.exist?(dir + ".rb") }
82
+ .map { |dir| File.basename(dir) }
249
83
 
250
84
  ##
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.
85
+ # Service that implements Google Cloud Speech API.
266
86
  #
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
87
+ # @param version [Symbol, String]
88
+ # The major version of the service to be used. By default :v1
89
+ # is used.
90
+ # @overload new(version:, credentials:, scopes:, client_config:, timeout:)
91
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
92
+ # Provides the means for authenticating requests made by the client. This parameter can
93
+ # be many types.
94
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
95
+ # authenticating requests made by this client.
96
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
97
+ # credentials for this client.
98
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
99
+ # credentials for this client.
100
+ # A `GRPC::Core::Channel` will be used to make calls through.
101
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
102
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
103
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
104
+ # metadata for requests, generally, to give OAuth credentials.
105
+ # @param scopes [Array<String>]
106
+ # The OAuth scopes for this service. This parameter is ignored if
107
+ # an updater_proc is supplied.
108
+ # @param client_config [Hash]
109
+ # A Hash for call options for each method. See
110
+ # Google::Gax#construct_settings for the structure of
111
+ # this data. Falls back to the default config if not specified
112
+ # or the specified config is missing data points.
113
+ # @param timeout [Numeric]
114
+ # The default timeout, in seconds, for calls made through this client.
115
+ # @param metadata [Hash]
116
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
117
+ # @param exception_transformer [Proc]
118
+ # An optional proc that intercepts any exceptions raised during an API call to inject
119
+ # custom error handling.
120
+ def self.new(*args, version: :v1, **kwargs)
121
+ unless AVAILABLE_VERSIONS.include?(version.to_s.downcase)
122
+ raise "The version: #{version} is not available. The available versions " \
123
+ "are: [#{AVAILABLE_VERSIONS.join(", ")}]"
124
+ end
283
125
 
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)
126
+ require "#{FILE_DIR}/#{version.to_s.downcase}"
127
+ version_module = Google::Cloud::Speech
128
+ .constants
129
+ .select {|sym| sym.to_s.downcase == version.to_s.downcase}
130
+ .first
131
+ Google::Cloud::Speech.const_get(version_module).new(*args, **kwargs)
290
132
  end
291
133
  end
292
134
  end