google-cloud-speech 1.7.1 → 2.0.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 -1
- data/README.md +32 -9
- data/lib/google/cloud/speech/version.rb +1 -1
- data/lib/google/cloud/speech.rb +29 -27
- metadata +13 -29
- data/MIGRATING.md +0 -367
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01aa397e81479c1f954041d7deafb255dc01d92f79c613aa131e87c0b2823e76
|
4
|
+
data.tar.gz: 3a202a63664922895bed5ff8b02c99d1eeba919dd0b62767e4b9151848dd4696
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52abb02e78f420ae4b4e067870d1e2c503613bb19d802b108f751d33ae24db2142ccc65aebc407c90503b9b664120ea55691817cd6ec884a2e0ebfabe42781c2
|
7
|
+
data.tar.gz: 8acdc78b4e8fde8e4c46e38f63fecb858a734db9cd4e2776fb473b132e00b97498f5ce59cd464104969ed000a489647e3aab0e0a3074fb0784ce3809774941f6
|
data/.yardopts
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,7 @@ constructing client objects. Reference documentation for the client objects
|
|
17
17
|
themselves can be found in the client library documentation for the versioned
|
18
18
|
client gems:
|
19
19
|
[google-cloud-speech-v1](https://cloud.google.com/ruby/docs/reference/google-cloud-speech-v1/latest),
|
20
|
-
[google-cloud-speech-
|
20
|
+
[google-cloud-speech-v2](https://cloud.google.com/ruby/docs/reference/google-cloud-speech-v2/latest).
|
21
21
|
|
22
22
|
See also the [Product Documentation](https://cloud.google.com/speech-to-text)
|
23
23
|
for more usage information.
|
@@ -35,17 +35,40 @@ In order to use this library, you first need to go through the following steps:
|
|
35
35
|
1. [Enable the API.](https://console.cloud.google.com/apis/library/speech.googleapis.com)
|
36
36
|
1. {file:AUTHENTICATION.md Set up authentication.}
|
37
37
|
|
38
|
-
##
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
## Debug Logging
|
39
|
+
|
40
|
+
This library comes with opt-in Debug Logging that can help you troubleshoot
|
41
|
+
your application's integration with the API. When logging is activated, key
|
42
|
+
events such as requests and responses, along with data payloads and metadata
|
43
|
+
such as headers and client configuration, are logged to the standard error
|
44
|
+
stream.
|
45
|
+
|
46
|
+
**WARNING:** Client Library Debug Logging includes your data payloads in
|
47
|
+
plaintext, which could include sensitive data such as PII for yourself or your
|
48
|
+
customers, private keys, or other security data that could be compromising if
|
49
|
+
leaked. Always practice good data hygiene with your application logs, and follow
|
50
|
+
the principle of least access. Google also recommends that Client Library Debug
|
51
|
+
Logging be enabled only temporarily during active debugging, and not used
|
52
|
+
permanently in production.
|
53
|
+
|
54
|
+
To enable logging, set the environment variable `GOOGLE_SDK_RUBY_LOGGING_GEMS`
|
55
|
+
to the value `all`. Alternatively, you can set the value to a comma-delimited
|
56
|
+
list of client library gem names. This will select the default logging behavior,
|
57
|
+
which writes logs to the standard error stream. On a local workstation, this may
|
58
|
+
result in logs appearing on the console. When running on a Google Cloud hosting
|
59
|
+
service such as [Google Cloud Run](https://cloud.google.com/run), this generally
|
60
|
+
results in logs appearing alongside your application logs in the
|
61
|
+
[Google Cloud Logging](https://cloud.google.com/logging/) service.
|
62
|
+
|
63
|
+
Debug logging also requires that the versioned clients for this service be
|
64
|
+
sufficiently recent, released after about Dec 10, 2024. If logging is not
|
65
|
+
working, try updating the versioned clients in your bundle or installed gems:
|
66
|
+
[google-cloud-speech-v1](https://cloud.google.com/ruby/docs/reference/google-cloud-speech-v1/latest),
|
67
|
+
[google-cloud-speech-v2](https://cloud.google.com/ruby/docs/reference/google-cloud-speech-v2/latest).
|
45
68
|
|
46
69
|
## Supported Ruby Versions
|
47
70
|
|
48
|
-
This library is supported on Ruby
|
71
|
+
This library is supported on Ruby 3.0+.
|
49
72
|
|
50
73
|
Google provides official support for Ruby versions that are actively supported
|
51
74
|
by Ruby Core—that is, Ruby versions that are either in normal maintenance or
|
data/lib/google/cloud/speech.rb
CHANGED
@@ -49,8 +49,8 @@ module Google
|
|
49
49
|
# Create a new client object for Speech.
|
50
50
|
#
|
51
51
|
# By default, this returns an instance of
|
52
|
-
# [Google::Cloud::Speech::
|
53
|
-
# for a gRPC client for version
|
52
|
+
# [Google::Cloud::Speech::V2::Speech::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-speech-v2/latest/Google-Cloud-Speech-V2-Speech-Client)
|
53
|
+
# for a gRPC client for version V2 of the API.
|
54
54
|
# However, you can specify a different API version by passing it in the
|
55
55
|
# `version` parameter. If the Speech service is
|
56
56
|
# supported by that API version, and the corresponding gem is available, the
|
@@ -58,16 +58,21 @@ module Google
|
|
58
58
|
# You can also specify a different transport by passing `:rest` or `:grpc` in
|
59
59
|
# the `transport` parameter.
|
60
60
|
#
|
61
|
+
# Raises an exception if the currently installed versioned client gem for the
|
62
|
+
# given API version does not support the given transport of the Speech service.
|
63
|
+
# You can determine whether the method will succeed by calling
|
64
|
+
# {Google::Cloud::Speech.speech_available?}.
|
65
|
+
#
|
61
66
|
# ## About Speech
|
62
67
|
#
|
63
|
-
#
|
68
|
+
# Enables speech transcription and resource management.
|
64
69
|
#
|
65
70
|
# @param version [::String, ::Symbol] The API version to connect to. Optional.
|
66
|
-
# Defaults to `:
|
71
|
+
# Defaults to `:v2`.
|
67
72
|
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
|
68
73
|
# @return [::Object] A client object for the specified version.
|
69
74
|
#
|
70
|
-
def self.speech version: :
|
75
|
+
def self.speech version: :v2, transport: :grpc, &block
|
71
76
|
require "google/cloud/speech/#{version.to_s.downcase}"
|
72
77
|
|
73
78
|
package_name = Google::Cloud::Speech
|
@@ -80,37 +85,34 @@ module Google
|
|
80
85
|
end
|
81
86
|
|
82
87
|
##
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
# However, you can specify a different API version by passing it in the
|
89
|
-
# `version` parameter. If the Adaptation service is
|
90
|
-
# supported by that API version, and the corresponding gem is available, the
|
91
|
-
# appropriate versioned client will be returned.
|
92
|
-
# You can also specify a different transport by passing `:rest` or `:grpc` in
|
93
|
-
# the `transport` parameter.
|
94
|
-
#
|
95
|
-
# ## About Adaptation
|
96
|
-
#
|
97
|
-
# Service that implements Google Cloud Speech Adaptation API.
|
88
|
+
# Determines whether the Speech service is supported by the current client.
|
89
|
+
# If true, you can retrieve a client object by calling {Google::Cloud::Speech.speech}.
|
90
|
+
# If false, that method will raise an exception. This could happen if the given
|
91
|
+
# API version does not exist or does not support the Speech service,
|
92
|
+
# or if the versioned client gem needs an update to support the Speech service.
|
98
93
|
#
|
99
94
|
# @param version [::String, ::Symbol] The API version to connect to. Optional.
|
100
|
-
# Defaults to `:
|
95
|
+
# Defaults to `:v2`.
|
101
96
|
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
|
102
|
-
# @return [
|
97
|
+
# @return [boolean] Whether the service is available.
|
103
98
|
#
|
104
|
-
def self.
|
99
|
+
def self.speech_available? version: :v2, transport: :grpc
|
105
100
|
require "google/cloud/speech/#{version.to_s.downcase}"
|
106
|
-
|
107
101
|
package_name = Google::Cloud::Speech
|
108
102
|
.constants
|
109
103
|
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
|
110
104
|
.first
|
111
|
-
|
112
|
-
service_module =
|
113
|
-
service_module.
|
105
|
+
return false unless package_name
|
106
|
+
service_module = Google::Cloud::Speech.const_get package_name
|
107
|
+
return false unless service_module.const_defined? :Speech
|
108
|
+
service_module = service_module.const_get :Speech
|
109
|
+
if transport == :rest
|
110
|
+
return false unless service_module.const_defined? :Rest
|
111
|
+
service_module = service_module.const_get :Rest
|
112
|
+
end
|
113
|
+
service_module.const_defined? :Client
|
114
|
+
rescue ::LoadError
|
115
|
+
false
|
114
116
|
end
|
115
117
|
|
116
118
|
##
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-speech
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Google LLC
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-13 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: google-cloud-core
|
@@ -28,42 +27,30 @@ dependencies:
|
|
28
27
|
name: google-cloud-speech-v1
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.16'
|
34
|
-
- - "<"
|
30
|
+
- - "~>"
|
35
31
|
- !ruby/object:Gem::Version
|
36
|
-
version: 2
|
32
|
+
version: '1.2'
|
37
33
|
type: :runtime
|
38
34
|
prerelease: false
|
39
35
|
version_requirements: !ruby/object:Gem::Requirement
|
40
36
|
requirements:
|
41
|
-
- - "
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0.16'
|
44
|
-
- - "<"
|
37
|
+
- - "~>"
|
45
38
|
- !ruby/object:Gem::Version
|
46
|
-
version: 2
|
39
|
+
version: '1.2'
|
47
40
|
- !ruby/object:Gem::Dependency
|
48
|
-
name: google-cloud-speech-
|
41
|
+
name: google-cloud-speech-v2
|
49
42
|
requirement: !ruby/object:Gem::Requirement
|
50
43
|
requirements:
|
51
|
-
- - "
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0.20'
|
54
|
-
- - "<"
|
44
|
+
- - "~>"
|
55
45
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
46
|
+
version: '1.0'
|
57
47
|
type: :runtime
|
58
48
|
prerelease: false
|
59
49
|
version_requirements: !ruby/object:Gem::Requirement
|
60
50
|
requirements:
|
61
|
-
- - "
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '0.20'
|
64
|
-
- - "<"
|
51
|
+
- - "~>"
|
65
52
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
53
|
+
version: '1.0'
|
67
54
|
description: Google Speech-to-Text enables developers to convert audio to text by
|
68
55
|
applying powerful neural network models in an easy-to-use API. The API recognizes
|
69
56
|
more than 120 languages and variants to support your global user base. You can enable
|
@@ -78,7 +65,6 @@ files:
|
|
78
65
|
- ".yardopts"
|
79
66
|
- AUTHENTICATION.md
|
80
67
|
- LICENSE.md
|
81
|
-
- MIGRATING.md
|
82
68
|
- README.md
|
83
69
|
- lib/google-cloud-speech.rb
|
84
70
|
- lib/google/cloud/speech.rb
|
@@ -87,7 +73,6 @@ homepage: https://github.com/googleapis/google-cloud-ruby
|
|
87
73
|
licenses:
|
88
74
|
- Apache-2.0
|
89
75
|
metadata: {}
|
90
|
-
post_install_message:
|
91
76
|
rdoc_options: []
|
92
77
|
require_paths:
|
93
78
|
- lib
|
@@ -95,15 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
80
|
requirements:
|
96
81
|
- - ">="
|
97
82
|
- !ruby/object:Gem::Version
|
98
|
-
version: '
|
83
|
+
version: '3.0'
|
99
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
85
|
requirements:
|
101
86
|
- - ">="
|
102
87
|
- !ruby/object:Gem::Version
|
103
88
|
version: '0'
|
104
89
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
106
|
-
signing_key:
|
90
|
+
rubygems_version: 3.6.3
|
107
91
|
specification_version: 4
|
108
92
|
summary: API Client library for the Cloud Speech-to-Text API
|
109
93
|
test_files: []
|
data/MIGRATING.md
DELETED
@@ -1,367 +0,0 @@
|
|
1
|
-
## Migrating to google-cloud-speech 1.0
|
2
|
-
|
3
|
-
The 1.0 release of the google-cloud-speech client is a significant upgrade
|
4
|
-
based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-ruby),
|
5
|
-
and includes substantial interface changes. Existing code written for earlier
|
6
|
-
versions of this library will likely require updates to use this version.
|
7
|
-
This document describes the changes that have been made, and what you need to
|
8
|
-
do to update your usage.
|
9
|
-
|
10
|
-
To summarize:
|
11
|
-
|
12
|
-
* The library has been broken out into multiple libraries. The new gems
|
13
|
-
`google-cloud-speech-v1` and `google-cloud-speech-v1p1beta1` contain the
|
14
|
-
actual client classes for versions V1 and V1p1beta1 of the Speech service,
|
15
|
-
and the gem `google-cloud-speech` now simply provides a convenience wrapper.
|
16
|
-
See [Library Structure](#library-structure) for more info.
|
17
|
-
* The library uses a new configuration mechanism giving you closer control
|
18
|
-
over endpoint address, network timeouts, and retry. See
|
19
|
-
[Client Configuration](#client-configuration) for more info. Furthermore,
|
20
|
-
when creating a client object, you can customize its configuration in a
|
21
|
-
block rather than passing arguments to the constructor. See
|
22
|
-
[Creating Clients](#creating-clients) for more info.
|
23
|
-
* Previously, positional arguments were used to indicate required arguments.
|
24
|
-
Now, all method arguments are keyword arguments, with documentation that
|
25
|
-
specifies whether they are required or optional. Additionally, you can pass
|
26
|
-
a proto request object instead of separate arguments. See
|
27
|
-
[Passing Arguments](#passing-arguments) for more info.
|
28
|
-
* Previously, the client included a method supporting bidirectional streaming
|
29
|
-
recognition requests, both incremental audio and incremental results. The
|
30
|
-
current client retains this method, but simplifies the interface to match
|
31
|
-
streaming methods in other Ruby clients. See
|
32
|
-
[Streaming Interface](#streaming-interface) for more info.
|
33
|
-
* Previously, clients reported RPC errors by raising instances of
|
34
|
-
`Google::Gax::GaxError` and its subclasses. Now, RPC exceptions are of type
|
35
|
-
`Google::Cloud::Error` and its subclasses. See
|
36
|
-
[Handling Errors](#handling-errors) for more info.
|
37
|
-
* Some classes have moved into different namespaces. See
|
38
|
-
[Class Namespaces](#class-namespaces) for more info.
|
39
|
-
|
40
|
-
### Library Structure
|
41
|
-
|
42
|
-
Older 0.x releases of the `google-cloud-speech` gem were all-in-one gems
|
43
|
-
that included potentially multiple clients for multiple versions of the Speech
|
44
|
-
service. The `Google::Cloud::Speech.new` factory method would
|
45
|
-
return you an instance of a `Google::Cloud::Speech::V1::SpeechClient`
|
46
|
-
object for the V1 version of the service, or a
|
47
|
-
`Google::Cloud::Speech::V1p1beta1::SpeechClient` object for the V1p1beta1
|
48
|
-
version of the service. All these classes were defined in the same gem.
|
49
|
-
|
50
|
-
With the 1.0 release, the `google-cloud-speech` gem still provides factory
|
51
|
-
methods for obtaining clients. (The method signatures will have changed. See
|
52
|
-
[Creating Clients](#creating-clients) for details.) However, the actual client
|
53
|
-
classes have been moved into separate gems, one per service version. The
|
54
|
-
`Google::Cloud::Speech::V1::Speech::Client` class, along with its
|
55
|
-
helpers and data types, is now part of the `google-cloud-speech-v1` gem.
|
56
|
-
Similarly, the `Google::Cloud::Speech::V1p1beta1::Speech::Client`
|
57
|
-
class is part of the `google-cloud-speech-v1p1beta1` gem.
|
58
|
-
|
59
|
-
For normal usage, you can continue to install the `google-cloud-speech` gem
|
60
|
-
(which will bring in the versioned client gems as dependencies) and continue to
|
61
|
-
use factory methods to create clients. However, you may alternatively choose to
|
62
|
-
install only one of the versioned gems. For example, if you know you will only
|
63
|
-
use `V1` of the service, you can install `google-cloud-speech-v1` by
|
64
|
-
itself, and construct instances of the
|
65
|
-
`Google::Cloud::Speech::V1::Speech::Client` client class directly.
|
66
|
-
|
67
|
-
### Client Configuration
|
68
|
-
|
69
|
-
In older releases, if you wanted to customize performance parameters or
|
70
|
-
low-level behavior of the client (such as credentials, timeouts, or
|
71
|
-
instrumentation), you would pass a variety of keyword arguments to the client
|
72
|
-
constructor. It was also extremely difficult to customize the default settings.
|
73
|
-
|
74
|
-
With the 1.0 release, a configuration interface provides control over these
|
75
|
-
parameters, including defaults for all instances of a client, and settings for
|
76
|
-
each specific client instance. For example, to set default credentials and
|
77
|
-
timeout for all Speech V1 clients:
|
78
|
-
|
79
|
-
```
|
80
|
-
Google::Cloud::Speech::V1::Speech::Client.configure do |config|
|
81
|
-
config.credentials = "/path/to/credentials.json"
|
82
|
-
config.timeout = 10.0
|
83
|
-
end
|
84
|
-
```
|
85
|
-
|
86
|
-
Individual RPCs can also be configured independently. For example, to set the
|
87
|
-
timeout for the `recognize` call:
|
88
|
-
|
89
|
-
```
|
90
|
-
Google::Cloud::Speech::V1::Speech::Client.configure do |config|
|
91
|
-
config.rpcs.recognize.timeout = 20.0
|
92
|
-
end
|
93
|
-
```
|
94
|
-
|
95
|
-
Defaults for certain configurations can be set for all Speech versions and
|
96
|
-
services globally:
|
97
|
-
|
98
|
-
```
|
99
|
-
Google::Cloud::Speech.configure do |config|
|
100
|
-
config.credentials = "/path/to/credentials.json"
|
101
|
-
config.timeout = 10.0
|
102
|
-
end
|
103
|
-
```
|
104
|
-
|
105
|
-
Finally, you can override the configuration for each client instance. See the
|
106
|
-
next section on [Creating Clients](#creating-clients) for details.
|
107
|
-
|
108
|
-
### Creating Clients
|
109
|
-
|
110
|
-
In older releases, to create a client object, you would use the
|
111
|
-
`Google::Cloud::Speech.new` class method. Keyword arguments were available to
|
112
|
-
select a service version and to configure parameters such as credentials and
|
113
|
-
timeouts.
|
114
|
-
|
115
|
-
With the 1.0 release, use the `Google::Cloud::Speech.speech` class
|
116
|
-
method to create a client object. You may select a service version using the
|
117
|
-
`:version` keyword argument. However, other configuration parameters should be
|
118
|
-
set in a configuration block when you create the client.
|
119
|
-
|
120
|
-
Old:
|
121
|
-
```
|
122
|
-
client = Google::Cloud::Speech.new credentials: "/path/to/credentials.json"
|
123
|
-
```
|
124
|
-
|
125
|
-
New:
|
126
|
-
```
|
127
|
-
client = Google::Cloud::Speech.speech do |config|
|
128
|
-
config.credentials = "/path/to/credentials.json"
|
129
|
-
end
|
130
|
-
```
|
131
|
-
|
132
|
-
The configuration block is optional. If you do not provide it, or you do not
|
133
|
-
set some configuration parameters, then the default configuration is used. See
|
134
|
-
[Client Configuration](#client-configuration).
|
135
|
-
|
136
|
-
### Passing Arguments
|
137
|
-
|
138
|
-
In older releases, required arguments would be passed as positional method
|
139
|
-
arguments, while most optional arguments would be passed as keyword arguments.
|
140
|
-
|
141
|
-
With the 1.0 release, all RPC arguments are passed as keyword arguments,
|
142
|
-
regardless of whether they are required or optional. For example:
|
143
|
-
|
144
|
-
Old:
|
145
|
-
```
|
146
|
-
client = Google::Cloud::Speech.new
|
147
|
-
|
148
|
-
config = {
|
149
|
-
language_code: "en-US",
|
150
|
-
sample_rate_hertz: 44_100,
|
151
|
-
encoding: :FLAC
|
152
|
-
}
|
153
|
-
audio = {
|
154
|
-
uri: "gs://cloud-samples-data/speech/brooklyn_bridge.flac"
|
155
|
-
}
|
156
|
-
|
157
|
-
# Config and audio are positional arguments
|
158
|
-
response = client.recognize config, audio
|
159
|
-
```
|
160
|
-
|
161
|
-
New:
|
162
|
-
```
|
163
|
-
client = Google::Cloud::Speech.speech
|
164
|
-
|
165
|
-
config = {
|
166
|
-
language_code: "en-US",
|
167
|
-
sample_rate_hertz: 44_100,
|
168
|
-
encoding: :FLAC
|
169
|
-
}
|
170
|
-
audio = {
|
171
|
-
uri: "gs://cloud-samples-data/speech/brooklyn_bridge.flac"
|
172
|
-
}
|
173
|
-
|
174
|
-
# Config and audio are keyword arguments
|
175
|
-
response = client.recognize config: config, audio: audio
|
176
|
-
```
|
177
|
-
|
178
|
-
In the 1.0 release, it is also possible to pass a request object, either
|
179
|
-
as a hash or as a protocol buffer.
|
180
|
-
|
181
|
-
New:
|
182
|
-
```
|
183
|
-
client = Google::Cloud::Speech.speech
|
184
|
-
|
185
|
-
request_object = Google::Cloud::Speech::V1::RecognizeRequest.new(
|
186
|
-
config: {
|
187
|
-
language_code: "en-US",
|
188
|
-
sample_rate_hertz: 44_100,
|
189
|
-
encoding: :FLAC
|
190
|
-
},
|
191
|
-
audio: {
|
192
|
-
uri: "gs://cloud-samples-data/speech/brooklyn_bridge.flac"
|
193
|
-
}
|
194
|
-
)
|
195
|
-
|
196
|
-
# Pass a request object as a positional argument:
|
197
|
-
response = client.recognize request_object
|
198
|
-
```
|
199
|
-
|
200
|
-
Finally, in older releases, to provide call options, you would pass a
|
201
|
-
`Google::Gax::CallOptions` object with the `:options` keyword argument. In the
|
202
|
-
1.0 release, pass call options using a _second set_ of keyword arguments.
|
203
|
-
|
204
|
-
Old:
|
205
|
-
```
|
206
|
-
client = Google::Cloud::Speech.new
|
207
|
-
|
208
|
-
config = {
|
209
|
-
language_code: "en-US",
|
210
|
-
sample_rate_hertz: 44_100,
|
211
|
-
encoding: :FLAC
|
212
|
-
}
|
213
|
-
audio = {
|
214
|
-
uri: "gs://cloud-samples-data/speech/brooklyn_bridge.flac"
|
215
|
-
}
|
216
|
-
|
217
|
-
options = Google::Gax::CallOptions.new timeout: 10.0
|
218
|
-
|
219
|
-
response = client.recognize config, audio, options: options
|
220
|
-
```
|
221
|
-
|
222
|
-
New:
|
223
|
-
```
|
224
|
-
client = Google::Cloud::Speech.speech
|
225
|
-
|
226
|
-
config = {
|
227
|
-
language_code: "en-US",
|
228
|
-
sample_rate_hertz: 44_100,
|
229
|
-
encoding: :FLAC
|
230
|
-
}
|
231
|
-
audio = {
|
232
|
-
uri: "gs://cloud-samples-data/speech/brooklyn_bridge.flac"
|
233
|
-
}
|
234
|
-
|
235
|
-
# Use a hash to wrap the normal call arguments (or pass a request object), and
|
236
|
-
# then add further keyword arguments for the call options.
|
237
|
-
response = client.batch_annotate_images(
|
238
|
-
{ config: config, audio: audio },
|
239
|
-
timeout: 10.0)
|
240
|
-
```
|
241
|
-
|
242
|
-
### Streaming Interface
|
243
|
-
|
244
|
-
The client library includes one special streaming method `streaming_recognize`.
|
245
|
-
In the older client, this method employed a streaming interface in which you
|
246
|
-
would register callbacks for different incremental result events. In version
|
247
|
-
1.0, we have standardized the streaming interfaces across the various Ruby
|
248
|
-
client libraries. The `streaming_recognize` call returns a lazy enumerable that
|
249
|
-
you can query for incremental results.
|
250
|
-
|
251
|
-
Old:
|
252
|
-
```
|
253
|
-
client = Google::Cloud::Speech.new
|
254
|
-
|
255
|
-
config = {
|
256
|
-
language_code: "en-US",
|
257
|
-
sample_rate_hertz: 44_100,
|
258
|
-
encoding: :FLAC
|
259
|
-
}
|
260
|
-
stream = client.streaming_recognize config: config
|
261
|
-
|
262
|
-
stream.on_interim { |result| puts "received interim" }
|
263
|
-
stream.on_complete { |result| puts "received complete" }
|
264
|
-
|
265
|
-
stream.send File.read("my_input.flac", mode: "rb")
|
266
|
-
stream.stop
|
267
|
-
|
268
|
-
stream.wait_until_complete!
|
269
|
-
results = stream.results
|
270
|
-
```
|
271
|
-
|
272
|
-
New:
|
273
|
-
```
|
274
|
-
client = Google::Cloud::Speech.speech
|
275
|
-
|
276
|
-
input_stream = Gapic::StreamInput.new
|
277
|
-
output_stream = client.streaming_recognize input_stream
|
278
|
-
|
279
|
-
config = {
|
280
|
-
language_code: "en-US",
|
281
|
-
sample_rate_hertz: 44_100,
|
282
|
-
encoding: :FLAC
|
283
|
-
}
|
284
|
-
streaming_config = { config: config }
|
285
|
-
|
286
|
-
input_stream.push({ streaming_config: streaming_config })
|
287
|
-
input_stream.push({ audio_content: File.read("my_input.flac", mode: "rb") })
|
288
|
-
input_stream.close
|
289
|
-
|
290
|
-
output_stream.each do |response|
|
291
|
-
puts "received: #{response}"
|
292
|
-
end
|
293
|
-
```
|
294
|
-
|
295
|
-
### Handling Errors
|
296
|
-
|
297
|
-
The client reports standard
|
298
|
-
[gRPC error codes](https://github.com/grpc/grpc/blob/master/doc/statuscodes.md)
|
299
|
-
by raising exceptions. In older releases, these exceptions were located in the
|
300
|
-
`Google::Gax` namespace and were subclasses of the `Google::Gax::GaxError` base
|
301
|
-
exception class, defined in the `google-gax` gem. However, these classes were
|
302
|
-
different from the standard exceptions (subclasses of `Google::Cloud::Error`)
|
303
|
-
thrown by other client libraries such as `google-cloud-storage`.
|
304
|
-
|
305
|
-
The 1.0 client library now uses the `Google::Cloud::Error` exception hierarchy,
|
306
|
-
for consistency across all the Google Cloud client libraries. In general, these
|
307
|
-
exceptions have the same name as their counterparts from older releases, but
|
308
|
-
are located in the `Google::Cloud` namespace rather than the `Google::Gax`
|
309
|
-
namespace.
|
310
|
-
|
311
|
-
Old:
|
312
|
-
```
|
313
|
-
client = Google::Cloud::Speech.new
|
314
|
-
|
315
|
-
config = {
|
316
|
-
language_code: "en-US",
|
317
|
-
sample_rate_hertz: 44_100,
|
318
|
-
encoding: :FLAC
|
319
|
-
}
|
320
|
-
audio = {
|
321
|
-
uri: "gs://cloud-samples-data/speech/brooklyn_bridge.flac"
|
322
|
-
}
|
323
|
-
|
324
|
-
begin
|
325
|
-
response = client.recognize config, audio
|
326
|
-
rescue Google::Gax::Error => e
|
327
|
-
# Handle exceptions that subclass Google::Gax::Error
|
328
|
-
end
|
329
|
-
```
|
330
|
-
|
331
|
-
New:
|
332
|
-
```
|
333
|
-
client = Google::Cloud::Speech.speech
|
334
|
-
|
335
|
-
config = {
|
336
|
-
language_code: "en-US",
|
337
|
-
sample_rate_hertz: 44_100,
|
338
|
-
encoding: :FLAC
|
339
|
-
}
|
340
|
-
audio = {
|
341
|
-
uri: "gs://cloud-samples-data/speech/brooklyn_bridge.flac"
|
342
|
-
}
|
343
|
-
|
344
|
-
begin
|
345
|
-
response = client.recognize config: config, audio: audio
|
346
|
-
rescue Google::Cloud::Error => e
|
347
|
-
# Handle exceptions that subclass Google::Cloud::Error
|
348
|
-
end
|
349
|
-
```
|
350
|
-
|
351
|
-
### Class Namespaces
|
352
|
-
|
353
|
-
In older releases, the client object was of classes with names like:
|
354
|
-
`Google::Cloud::Speech::V1::SpeechClient`.
|
355
|
-
In the 1.0 release, the client object is of a different class:
|
356
|
-
`Google::Cloud::Speech::V1::Speech::Client`.
|
357
|
-
Note that most users will use the factory methods such as
|
358
|
-
`Google::Cloud::Speech.speech` to create instances of the client object,
|
359
|
-
so you may not need to reference the actual class directly.
|
360
|
-
See [Creating Clients](#creating-clients).
|
361
|
-
|
362
|
-
In older releases, the credentials object was of class
|
363
|
-
`Google::Cloud::Speech::V1::Credentials`.
|
364
|
-
In the 1.0 release, each service has its own credentials class, e.g.
|
365
|
-
`Google::Cloud::Speech::V1::Speech::Credentials`.
|
366
|
-
Again, most users will not need to reference this class directly.
|
367
|
-
See [Client Configuration](#client-configuration).
|