google-cloud-speech 1.8.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +0 -1
- data/README.md +2 -10
- data/lib/google/cloud/speech/version.rb +1 -1
- data/lib/google/cloud/speech.rb +7 -77
- metadata +12 -25
- 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,14 +35,6 @@ 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
|
-
## Migrating from 0.x versions
|
39
|
-
|
40
|
-
The 1.0 release of the google-cloud-speech client is a significant upgrade
|
41
|
-
based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-ruby),
|
42
|
-
and includes substantial interface changes. Existing code written for earlier
|
43
|
-
versions of this library will likely require updates to use this version.
|
44
|
-
See the {file:MIGRATING.md MIGRATING.md} document for more information.
|
45
|
-
|
46
38
|
## Debug Logging
|
47
39
|
|
48
40
|
This library comes with opt-in Debug Logging that can help you troubleshoot
|
@@ -72,7 +64,7 @@ Debug logging also requires that the versioned clients for this service be
|
|
72
64
|
sufficiently recent, released after about Dec 10, 2024. If logging is not
|
73
65
|
working, try updating the versioned clients in your bundle or installed gems:
|
74
66
|
[google-cloud-speech-v1](https://cloud.google.com/ruby/docs/reference/google-cloud-speech-v1/latest),
|
75
|
-
[google-cloud-speech-
|
67
|
+
[google-cloud-speech-v2](https://cloud.google.com/ruby/docs/reference/google-cloud-speech-v2/latest).
|
76
68
|
|
77
69
|
## Supported Ruby Versions
|
78
70
|
|
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
|
@@ -65,14 +65,14 @@ module Google
|
|
65
65
|
#
|
66
66
|
# ## About Speech
|
67
67
|
#
|
68
|
-
#
|
68
|
+
# Enables speech transcription and resource management.
|
69
69
|
#
|
70
70
|
# @param version [::String, ::Symbol] The API version to connect to. Optional.
|
71
|
-
# Defaults to `:
|
71
|
+
# Defaults to `:v2`.
|
72
72
|
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
|
73
73
|
# @return [::Object] A client object for the specified version.
|
74
74
|
#
|
75
|
-
def self.speech version: :
|
75
|
+
def self.speech version: :v2, transport: :grpc, &block
|
76
76
|
require "google/cloud/speech/#{version.to_s.downcase}"
|
77
77
|
|
78
78
|
package_name = Google::Cloud::Speech
|
@@ -92,11 +92,11 @@ module Google
|
|
92
92
|
# or if the versioned client gem needs an update to support the Speech service.
|
93
93
|
#
|
94
94
|
# @param version [::String, ::Symbol] The API version to connect to. Optional.
|
95
|
-
# Defaults to `:
|
95
|
+
# Defaults to `:v2`.
|
96
96
|
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
|
97
97
|
# @return [boolean] Whether the service is available.
|
98
98
|
#
|
99
|
-
def self.speech_available? version: :
|
99
|
+
def self.speech_available? version: :v2, transport: :grpc
|
100
100
|
require "google/cloud/speech/#{version.to_s.downcase}"
|
101
101
|
package_name = Google::Cloud::Speech
|
102
102
|
.constants
|
@@ -115,76 +115,6 @@ module Google
|
|
115
115
|
false
|
116
116
|
end
|
117
117
|
|
118
|
-
##
|
119
|
-
# Create a new client object for Adaptation.
|
120
|
-
#
|
121
|
-
# By default, this returns an instance of
|
122
|
-
# [Google::Cloud::Speech::V1::Adaptation::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-speech-v1/latest/Google-Cloud-Speech-V1-Adaptation-Client)
|
123
|
-
# for a gRPC client for version V1 of the API.
|
124
|
-
# However, you can specify a different API version by passing it in the
|
125
|
-
# `version` parameter. If the Adaptation service is
|
126
|
-
# supported by that API version, and the corresponding gem is available, the
|
127
|
-
# appropriate versioned client will be returned.
|
128
|
-
# You can also specify a different transport by passing `:rest` or `:grpc` in
|
129
|
-
# the `transport` parameter.
|
130
|
-
#
|
131
|
-
# Raises an exception if the currently installed versioned client gem for the
|
132
|
-
# given API version does not support the given transport of the Adaptation service.
|
133
|
-
# You can determine whether the method will succeed by calling
|
134
|
-
# {Google::Cloud::Speech.adaptation_available?}.
|
135
|
-
#
|
136
|
-
# ## About Adaptation
|
137
|
-
#
|
138
|
-
# Service that implements Google Cloud Speech Adaptation API.
|
139
|
-
#
|
140
|
-
# @param version [::String, ::Symbol] The API version to connect to. Optional.
|
141
|
-
# Defaults to `:v1`.
|
142
|
-
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
|
143
|
-
# @return [::Object] A client object for the specified version.
|
144
|
-
#
|
145
|
-
def self.adaptation version: :v1, transport: :grpc, &block
|
146
|
-
require "google/cloud/speech/#{version.to_s.downcase}"
|
147
|
-
|
148
|
-
package_name = Google::Cloud::Speech
|
149
|
-
.constants
|
150
|
-
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
|
151
|
-
.first
|
152
|
-
service_module = Google::Cloud::Speech.const_get(package_name).const_get(:Adaptation)
|
153
|
-
service_module = service_module.const_get(:Rest) if transport == :rest
|
154
|
-
service_module.const_get(:Client).new(&block)
|
155
|
-
end
|
156
|
-
|
157
|
-
##
|
158
|
-
# Determines whether the Adaptation service is supported by the current client.
|
159
|
-
# If true, you can retrieve a client object by calling {Google::Cloud::Speech.adaptation}.
|
160
|
-
# If false, that method will raise an exception. This could happen if the given
|
161
|
-
# API version does not exist or does not support the Adaptation service,
|
162
|
-
# or if the versioned client gem needs an update to support the Adaptation service.
|
163
|
-
#
|
164
|
-
# @param version [::String, ::Symbol] The API version to connect to. Optional.
|
165
|
-
# Defaults to `:v1`.
|
166
|
-
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
|
167
|
-
# @return [boolean] Whether the service is available.
|
168
|
-
#
|
169
|
-
def self.adaptation_available? version: :v1, transport: :grpc
|
170
|
-
require "google/cloud/speech/#{version.to_s.downcase}"
|
171
|
-
package_name = Google::Cloud::Speech
|
172
|
-
.constants
|
173
|
-
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
|
174
|
-
.first
|
175
|
-
return false unless package_name
|
176
|
-
service_module = Google::Cloud::Speech.const_get package_name
|
177
|
-
return false unless service_module.const_defined? :Adaptation
|
178
|
-
service_module = service_module.const_get :Adaptation
|
179
|
-
if transport == :rest
|
180
|
-
return false unless service_module.const_defined? :Rest
|
181
|
-
service_module = service_module.const_get :Rest
|
182
|
-
end
|
183
|
-
service_module.const_defined? :Client
|
184
|
-
rescue ::LoadError
|
185
|
-
false
|
186
|
-
end
|
187
|
-
|
188
118
|
##
|
189
119
|
# Configure the google-cloud-speech library.
|
190
120
|
#
|
metadata
CHANGED
@@ -1,13 +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
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-13 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: google-cloud-core
|
@@ -27,42 +27,30 @@ dependencies:
|
|
27
27
|
name: google-cloud-speech-v1
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
|
-
- - "
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '0.16'
|
33
|
-
- - "<"
|
30
|
+
- - "~>"
|
34
31
|
- !ruby/object:Gem::Version
|
35
|
-
version: 2
|
32
|
+
version: '1.2'
|
36
33
|
type: :runtime
|
37
34
|
prerelease: false
|
38
35
|
version_requirements: !ruby/object:Gem::Requirement
|
39
36
|
requirements:
|
40
|
-
- - "
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '0.16'
|
43
|
-
- - "<"
|
37
|
+
- - "~>"
|
44
38
|
- !ruby/object:Gem::Version
|
45
|
-
version: 2
|
39
|
+
version: '1.2'
|
46
40
|
- !ruby/object:Gem::Dependency
|
47
|
-
name: google-cloud-speech-
|
41
|
+
name: google-cloud-speech-v2
|
48
42
|
requirement: !ruby/object:Gem::Requirement
|
49
43
|
requirements:
|
50
|
-
- - "
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '0.20'
|
53
|
-
- - "<"
|
44
|
+
- - "~>"
|
54
45
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
46
|
+
version: '1.0'
|
56
47
|
type: :runtime
|
57
48
|
prerelease: false
|
58
49
|
version_requirements: !ruby/object:Gem::Requirement
|
59
50
|
requirements:
|
60
|
-
- - "
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0.20'
|
63
|
-
- - "<"
|
51
|
+
- - "~>"
|
64
52
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
53
|
+
version: '1.0'
|
66
54
|
description: Google Speech-to-Text enables developers to convert audio to text by
|
67
55
|
applying powerful neural network models in an easy-to-use API. The API recognizes
|
68
56
|
more than 120 languages and variants to support your global user base. You can enable
|
@@ -77,7 +65,6 @@ files:
|
|
77
65
|
- ".yardopts"
|
78
66
|
- AUTHENTICATION.md
|
79
67
|
- LICENSE.md
|
80
|
-
- MIGRATING.md
|
81
68
|
- README.md
|
82
69
|
- lib/google-cloud-speech.rb
|
83
70
|
- lib/google/cloud/speech.rb
|
@@ -100,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
87
|
- !ruby/object:Gem::Version
|
101
88
|
version: '0'
|
102
89
|
requirements: []
|
103
|
-
rubygems_version: 3.6.
|
90
|
+
rubygems_version: 3.6.3
|
104
91
|
specification_version: 4
|
105
92
|
summary: API Client library for the Cloud Speech-to-Text API
|
106
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).
|