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.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/LICENSE +1 -1
- data/README.md +69 -43
- data/lib/google/cloud/speech.rb +94 -252
- data/lib/google/cloud/speech/v1.rb +11 -1
- data/lib/google/cloud/speech/v1/cloud_speech_services_pb.rb +1 -1
- data/lib/google/cloud/speech/{version.rb → v1/credentials.rb} +12 -2
- data/lib/google/cloud/speech/v1/doc/google/cloud/speech/v1/cloud_speech.rb +2 -2
- data/lib/google/cloud/speech/v1/doc/google/longrunning/operations.rb +92 -0
- data/lib/google/cloud/speech/v1/doc/google/protobuf/any.rb +1 -1
- data/lib/google/cloud/speech/v1/doc/google/protobuf/duration.rb +1 -1
- data/lib/google/cloud/speech/v1/doc/google/rpc/status.rb +1 -1
- data/lib/google/cloud/speech/v1/doc/overview.rb +1 -1
- data/lib/google/cloud/speech/v1/helpers.rb +93 -0
- data/lib/google/cloud/speech/v1/speech_client.rb +26 -49
- data/lib/google/cloud/speech/v1/speech_client_config.json +5 -5
- data/lib/google/cloud/speech/v1/stream.rb +614 -0
- data/lib/google/cloud/speech/v1p1beta1.rb +126 -0
- data/lib/google/cloud/speech/v1p1beta1/cloud_speech_pb.rb +175 -0
- data/lib/google/cloud/speech/v1p1beta1/cloud_speech_services_pb.rb +54 -0
- data/lib/google/cloud/speech/v1p1beta1/credentials.rb +32 -0
- data/lib/google/cloud/speech/v1p1beta1/doc/google/cloud/speech/v1p1beta1/cloud_speech.rb +625 -0
- data/lib/google/cloud/speech/v1p1beta1/doc/google/longrunning/operations.rb +92 -0
- data/lib/google/cloud/speech/v1p1beta1/doc/google/protobuf/any.rb +124 -0
- data/lib/google/cloud/speech/v1p1beta1/doc/google/protobuf/duration.rb +90 -0
- data/lib/google/cloud/speech/v1p1beta1/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/speech/v1p1beta1/doc/overview.rb +73 -0
- data/lib/google/cloud/speech/v1p1beta1/helpers.rb +93 -0
- data/lib/google/cloud/speech/v1p1beta1/speech_client.rb +322 -0
- data/lib/google/cloud/speech/v1p1beta1/speech_client_config.json +41 -0
- data/lib/google/cloud/speech/v1p1beta1/stream.rb +614 -0
- metadata +29 -120
- data/lib/google-cloud-speech.rb +0 -142
- data/lib/google/cloud/speech/audio.rb +0 -330
- data/lib/google/cloud/speech/convert.rb +0 -46
- data/lib/google/cloud/speech/credentials.rb +0 -57
- data/lib/google/cloud/speech/operation.rb +0 -262
- data/lib/google/cloud/speech/project.rb +0 -651
- data/lib/google/cloud/speech/result.rb +0 -240
- data/lib/google/cloud/speech/service.rb +0 -121
- data/lib/google/cloud/speech/stream.rb +0 -564
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 763195f0925921b082ea312d0287d4ca43e57bcdba2348379b2a47df410be135
|
4
|
+
data.tar.gz: 30d926a0eecbe5a1a6aa70391d4b83db808425c96e69290171e1c1080ae6b533
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c32bacca6be56b87b96176b1b6dd9afde7910e5958ab7c264206cd34224889ceb6a2b708566eb1b409ef7c17b5a2f7ee23dac6b9d7f56db40ffc92db83a5ecc
|
7
|
+
data.tar.gz: 36157d4b83b244f712dfcecbab3a3ce13d7522e7175736c6b50c6234e2e8922d7569f521e71496a054544fcd8bbc0c9686059ba0086b0ab0576bab4a6da6b231
|
data/.yardopts
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,64 +1,90 @@
|
|
1
|
-
# google-cloud-
|
1
|
+
# Ruby Client for Cloud Speech API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
|
2
2
|
|
3
|
-
[
|
4
|
-
|
5
|
-
- [
|
6
|
-
- [
|
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
|
-
|
17
|
+
### Installation
|
18
|
+
```
|
12
19
|
$ gem install google-cloud-speech
|
13
20
|
```
|
14
21
|
|
15
|
-
|
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
|
-
|
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
|
-
|
29
|
+
### Preview
|
30
|
+
#### SpeechClient
|
31
|
+
```rb
|
24
32
|
require "google/cloud/speech"
|
25
33
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
##
|
56
|
+
## Enabling Logging
|
50
57
|
|
51
|
-
|
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
|
-
|
60
|
+
Configuring a Ruby stdlib logger:
|
54
61
|
|
55
|
-
|
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
|
-
##
|
78
|
+
## Supported Ruby Versions
|
58
79
|
|
59
|
-
This library is
|
80
|
+
This library is supported on Ruby 2.0+.
|
60
81
|
|
61
|
-
|
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
|
-
|
64
|
-
|
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
|
data/lib/google/cloud/speech.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
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 "
|
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
|
-
#
|
36
|
-
# Speech API
|
25
|
+
# [Google Cloud Speech API][Product Documentation]:
|
26
|
+
# Google Cloud Speech API.
|
27
|
+
# - [Product Documentation][]
|
37
28
|
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
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
|
-
#
|
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
|
-
#
|
50
|
-
# several types of audio data source, along with metadata such as the audio
|
51
|
-
# encoding type.
|
38
|
+
# ### Migration Guide
|
52
39
|
#
|
53
|
-
#
|
54
|
-
#
|
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
|
-
#
|
45
|
+
# ### Preview
|
46
|
+
# #### SpeechClient
|
47
|
+
# ```rb
|
57
48
|
# require "google/cloud/speech"
|
58
49
|
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
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
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
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
|
-
#
|
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
|
-
|
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
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
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
|
-
#
|
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
|
-
# @
|
268
|
-
#
|
269
|
-
#
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
#
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
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
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
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
|