google-cloud-speech 0.29.0 → 0.30.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 +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
metadata
CHANGED
@@ -1,30 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-speech
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
- Chris Smith
|
7
|
+
- Google LLC
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2018-
|
11
|
+
date: 2018-06-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: google-cloud-core
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.2'
|
21
|
-
type: :runtime
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '1.2'
|
28
13
|
- !ruby/object:Gem::Dependency
|
29
14
|
name: google-gax
|
30
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,62 +38,6 @@ dependencies:
|
|
53
38
|
- - "~>"
|
54
39
|
- !ruby/object:Gem::Version
|
55
40
|
version: '5.10'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: minitest-autotest
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '1.0'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '1.0'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: minitest-focus
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - "~>"
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '1.1'
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '1.1'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: minitest-rg
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - "~>"
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '5.2'
|
91
|
-
type: :development
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '5.2'
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: autotest-suffix
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
102
|
-
- - "~>"
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: '1.1'
|
105
|
-
type: :development
|
106
|
-
prerelease: false
|
107
|
-
version_requirements: !ruby/object:Gem::Requirement
|
108
|
-
requirements:
|
109
|
-
- - "~>"
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
version: '1.1'
|
112
41
|
- !ruby/object:Gem::Dependency
|
113
42
|
name: rubocop
|
114
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,38 +66,8 @@ dependencies:
|
|
137
66
|
- - "~>"
|
138
67
|
- !ruby/object:Gem::Version
|
139
68
|
version: '0.9'
|
140
|
-
-
|
141
|
-
|
142
|
-
requirement: !ruby/object:Gem::Requirement
|
143
|
-
requirements:
|
144
|
-
- - "~>"
|
145
|
-
- !ruby/object:Gem::Version
|
146
|
-
version: '0.9'
|
147
|
-
type: :development
|
148
|
-
prerelease: false
|
149
|
-
version_requirements: !ruby/object:Gem::Requirement
|
150
|
-
requirements:
|
151
|
-
- - "~>"
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
version: '0.9'
|
154
|
-
- !ruby/object:Gem::Dependency
|
155
|
-
name: yard-doctest
|
156
|
-
requirement: !ruby/object:Gem::Requirement
|
157
|
-
requirements:
|
158
|
-
- - "<="
|
159
|
-
- !ruby/object:Gem::Version
|
160
|
-
version: 0.1.8
|
161
|
-
type: :development
|
162
|
-
prerelease: false
|
163
|
-
version_requirements: !ruby/object:Gem::Requirement
|
164
|
-
requirements:
|
165
|
-
- - "<="
|
166
|
-
- !ruby/object:Gem::Version
|
167
|
-
version: 0.1.8
|
168
|
-
description: google-cloud-speech is the official library for Google Cloud Speech API.
|
169
|
-
email:
|
170
|
-
- mike@blowmage.com
|
171
|
-
- quartzmo@gmail.com
|
69
|
+
description: google-cloud-speech is the official library for Cloud Speech API.
|
70
|
+
email: googleapis-packages@google.com
|
172
71
|
executables: []
|
173
72
|
extensions: []
|
174
73
|
extra_rdoc_files: []
|
@@ -176,32 +75,42 @@ files:
|
|
176
75
|
- ".yardopts"
|
177
76
|
- LICENSE
|
178
77
|
- README.md
|
179
|
-
- lib/google-cloud-speech.rb
|
180
78
|
- lib/google/cloud/speech.rb
|
181
|
-
- lib/google/cloud/speech/audio.rb
|
182
|
-
- lib/google/cloud/speech/convert.rb
|
183
|
-
- lib/google/cloud/speech/credentials.rb
|
184
|
-
- lib/google/cloud/speech/operation.rb
|
185
|
-
- lib/google/cloud/speech/project.rb
|
186
|
-
- lib/google/cloud/speech/result.rb
|
187
|
-
- lib/google/cloud/speech/service.rb
|
188
|
-
- lib/google/cloud/speech/stream.rb
|
189
79
|
- lib/google/cloud/speech/v1.rb
|
190
80
|
- lib/google/cloud/speech/v1/cloud_speech_pb.rb
|
191
81
|
- lib/google/cloud/speech/v1/cloud_speech_services_pb.rb
|
82
|
+
- lib/google/cloud/speech/v1/credentials.rb
|
192
83
|
- lib/google/cloud/speech/v1/doc/google/cloud/speech/v1/cloud_speech.rb
|
84
|
+
- lib/google/cloud/speech/v1/doc/google/longrunning/operations.rb
|
193
85
|
- lib/google/cloud/speech/v1/doc/google/protobuf/any.rb
|
194
86
|
- lib/google/cloud/speech/v1/doc/google/protobuf/duration.rb
|
195
87
|
- lib/google/cloud/speech/v1/doc/google/rpc/status.rb
|
196
88
|
- lib/google/cloud/speech/v1/doc/overview.rb
|
89
|
+
- lib/google/cloud/speech/v1/helpers.rb
|
197
90
|
- lib/google/cloud/speech/v1/speech_client.rb
|
198
91
|
- lib/google/cloud/speech/v1/speech_client_config.json
|
199
|
-
- lib/google/cloud/speech/
|
200
|
-
|
92
|
+
- lib/google/cloud/speech/v1/stream.rb
|
93
|
+
- lib/google/cloud/speech/v1p1beta1.rb
|
94
|
+
- lib/google/cloud/speech/v1p1beta1/cloud_speech_pb.rb
|
95
|
+
- lib/google/cloud/speech/v1p1beta1/cloud_speech_services_pb.rb
|
96
|
+
- lib/google/cloud/speech/v1p1beta1/credentials.rb
|
97
|
+
- lib/google/cloud/speech/v1p1beta1/doc/google/cloud/speech/v1p1beta1/cloud_speech.rb
|
98
|
+
- lib/google/cloud/speech/v1p1beta1/doc/google/longrunning/operations.rb
|
99
|
+
- lib/google/cloud/speech/v1p1beta1/doc/google/protobuf/any.rb
|
100
|
+
- lib/google/cloud/speech/v1p1beta1/doc/google/protobuf/duration.rb
|
101
|
+
- lib/google/cloud/speech/v1p1beta1/doc/google/rpc/status.rb
|
102
|
+
- lib/google/cloud/speech/v1p1beta1/doc/overview.rb
|
103
|
+
- lib/google/cloud/speech/v1p1beta1/helpers.rb
|
104
|
+
- lib/google/cloud/speech/v1p1beta1/speech_client.rb
|
105
|
+
- lib/google/cloud/speech/v1p1beta1/speech_client_config.json
|
106
|
+
- lib/google/cloud/speech/v1p1beta1/stream.rb
|
107
|
+
homepage: https://github.com/googleapis/googleapis
|
201
108
|
licenses:
|
202
109
|
- Apache-2.0
|
203
110
|
metadata: {}
|
204
|
-
post_install_message:
|
111
|
+
post_install_message: 'The 0.30.0 release introduced breaking changes relative to
|
112
|
+
the previous release, 0.29.0. For more details and instructions to migrate your
|
113
|
+
code, please visit the migration guide: https://cloud.google.com/speech-to-text/docs/ruby-client-migration.'
|
205
114
|
rdoc_options: []
|
206
115
|
require_paths:
|
207
116
|
- lib
|
@@ -217,8 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
126
|
version: '0'
|
218
127
|
requirements: []
|
219
128
|
rubyforge_project:
|
220
|
-
rubygems_version: 2.7.
|
129
|
+
rubygems_version: 2.7.7
|
221
130
|
signing_key:
|
222
131
|
specification_version: 4
|
223
|
-
summary: API Client library for
|
132
|
+
summary: API Client library for Cloud Speech API
|
224
133
|
test_files: []
|
data/lib/google-cloud-speech.rb
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
##
|
16
|
-
# This file is here to be autorequired by bundler, so that the
|
17
|
-
# Google::Cloud.speech and Google::Cloud#speech methods can be available, but
|
18
|
-
# the library and all dependencies won't be loaded until required and used.
|
19
|
-
|
20
|
-
|
21
|
-
gem "google-cloud-core"
|
22
|
-
require "google/cloud"
|
23
|
-
require "google/cloud/config"
|
24
|
-
require "googleauth"
|
25
|
-
|
26
|
-
module Google
|
27
|
-
module Cloud
|
28
|
-
##
|
29
|
-
# Creates a new object for connecting to the Speech service.
|
30
|
-
# Each call creates a new connection.
|
31
|
-
#
|
32
|
-
# For more information on connecting to Google Cloud see the [Authentication
|
33
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
34
|
-
#
|
35
|
-
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
36
|
-
# set of resources and operations that the connection can access. See
|
37
|
-
# [Using OAuth 2.0 to Access Google
|
38
|
-
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
39
|
-
#
|
40
|
-
# The default scope is:
|
41
|
-
#
|
42
|
-
# * `https://www.googleapis.com/auth/speech`
|
43
|
-
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
44
|
-
# @param [Hash] client_config A hash of values to override the default
|
45
|
-
# behavior of the API client. Optional.
|
46
|
-
#
|
47
|
-
# @return [Google::Cloud::Speech::Project]
|
48
|
-
#
|
49
|
-
# @example
|
50
|
-
# require "google/cloud"
|
51
|
-
#
|
52
|
-
# gcloud = Google::Cloud.new
|
53
|
-
# speech = gcloud.speech
|
54
|
-
#
|
55
|
-
# audio = speech.audio "path/to/audio.raw",
|
56
|
-
# encoding: :linear16,
|
57
|
-
# language: "en-US",
|
58
|
-
# sample_rate: 16000
|
59
|
-
#
|
60
|
-
# @example The default scope can be overridden with the `scope` option:
|
61
|
-
# require "google/cloud"
|
62
|
-
#
|
63
|
-
# gcloud = Google::Cloud.new
|
64
|
-
# platform_scope = "https://www.googleapis.com/auth/cloud-platform"
|
65
|
-
# speech = gcloud.speech scope: platform_scope
|
66
|
-
#
|
67
|
-
def speech scope: nil, timeout: nil, client_config: nil
|
68
|
-
Google::Cloud.speech @project, @keyfile, scope: scope,
|
69
|
-
timeout: (timeout || @timeout),
|
70
|
-
client_config: client_config
|
71
|
-
end
|
72
|
-
|
73
|
-
##
|
74
|
-
# Creates a new object for connecting to the Speech service.
|
75
|
-
# Each call creates a new connection.
|
76
|
-
#
|
77
|
-
# For more information on connecting to Google Cloud see the [Authentication
|
78
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
79
|
-
#
|
80
|
-
# @param [String] project_id Project identifier for the Speech service
|
81
|
-
# you are connecting to. If not present, the default project for the
|
82
|
-
# credentials is used.
|
83
|
-
# @param [String, Hash, Google::Auth::Credentials] credentials The path to
|
84
|
-
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
85
|
-
# Google::Auth::Credentials object. (See {Speech::Credentials})
|
86
|
-
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
87
|
-
# set of resources and operations that the connection can access. See
|
88
|
-
# [Using OAuth 2.0 to Access Google
|
89
|
-
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
90
|
-
#
|
91
|
-
# The default scope is:
|
92
|
-
#
|
93
|
-
# * `https://www.googleapis.com/auth/speech`
|
94
|
-
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
95
|
-
# @param [Hash] client_config A hash of values to override the default
|
96
|
-
# behavior of the API client. Optional.
|
97
|
-
#
|
98
|
-
# @return [Google::Cloud::Speech::Project]
|
99
|
-
#
|
100
|
-
# @example
|
101
|
-
# require "google/cloud"
|
102
|
-
#
|
103
|
-
# speech = Google::Cloud.speech
|
104
|
-
#
|
105
|
-
# audio = speech.audio "path/to/audio.raw",
|
106
|
-
# encoding: :linear16,
|
107
|
-
# language: "en-US",
|
108
|
-
# sample_rate: 16000
|
109
|
-
#
|
110
|
-
def self.speech project_id = nil, credentials = nil, scope: nil,
|
111
|
-
timeout: nil, client_config: nil
|
112
|
-
require "google/cloud/speech"
|
113
|
-
Google::Cloud::Speech.new project_id: project_id,
|
114
|
-
credentials: credentials,
|
115
|
-
scope: scope, timeout: timeout,
|
116
|
-
client_config: client_config
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# Set the default speech configuration
|
122
|
-
Google::Cloud.configure.add_config! :speech do |config|
|
123
|
-
default_project = Google::Cloud::Config.deferred do
|
124
|
-
ENV["SPEECH_PROJECT"]
|
125
|
-
end
|
126
|
-
default_creds = Google::Cloud::Config.deferred do
|
127
|
-
Google::Cloud::Config.credentials_from_env(
|
128
|
-
"SPEECH_CREDENTIALS", "SPEECH_CREDENTIALS_JSON",
|
129
|
-
"SPEECH_KEYFILE", "SPEECH_KEYFILE_JSON"
|
130
|
-
)
|
131
|
-
end
|
132
|
-
|
133
|
-
config.add_field! :project_id, default_project, match: String, allow_nil: true
|
134
|
-
config.add_alias! :project, :project_id
|
135
|
-
config.add_field! :credentials, default_creds,
|
136
|
-
match: [String, Hash, Google::Auth::Credentials],
|
137
|
-
allow_nil: true
|
138
|
-
config.add_alias! :keyfile, :credentials
|
139
|
-
config.add_field! :scope, nil, match: [String, Array]
|
140
|
-
config.add_field! :timeout, nil, match: Integer
|
141
|
-
config.add_field! :client_config, nil, match: Hash
|
142
|
-
end
|
@@ -1,330 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
|
16
|
-
module Google
|
17
|
-
module Cloud
|
18
|
-
module Speech
|
19
|
-
##
|
20
|
-
# # Audio
|
21
|
-
#
|
22
|
-
# Represents a source of audio data, with related metadata such as the
|
23
|
-
# [audio encoding](https://cloud.google.com/speech/docs/basics#audio-encodings),
|
24
|
-
# [sample rate](https://cloud.google.com/speech/docs/basics#sample-rates),
|
25
|
-
# and [language](https://cloud.google.com/speech/docs/basics#languages).
|
26
|
-
#
|
27
|
-
# See {Project#audio}.
|
28
|
-
#
|
29
|
-
# @see https://cloud.google.com/speech/docs/basics#audio-encodings
|
30
|
-
# Audio Encodings
|
31
|
-
# @see https://cloud.google.com/speech/docs/basics#sample-rates
|
32
|
-
# Sample Rates
|
33
|
-
# @see https://cloud.google.com/speech/docs/basics#languages
|
34
|
-
# Languages
|
35
|
-
#
|
36
|
-
# @example
|
37
|
-
# require "google/cloud/speech"
|
38
|
-
#
|
39
|
-
# speech = Google::Cloud::Speech.new
|
40
|
-
#
|
41
|
-
# audio = speech.audio "path/to/audio.raw",
|
42
|
-
# encoding: :linear16,
|
43
|
-
# language: "en-US",
|
44
|
-
# sample_rate: 16000
|
45
|
-
#
|
46
|
-
# results = audio.recognize
|
47
|
-
# result = results.first
|
48
|
-
# result.transcript #=> "how old is the Brooklyn Bridge"
|
49
|
-
# result.confidence #=> 0.9826789498329163
|
50
|
-
#
|
51
|
-
class Audio
|
52
|
-
# @private The V1::RecognitionAudio object.
|
53
|
-
attr_reader :grpc
|
54
|
-
# @private The Project object.
|
55
|
-
attr_reader :speech
|
56
|
-
|
57
|
-
##
|
58
|
-
# Encoding of audio data to be recognized.
|
59
|
-
#
|
60
|
-
# Acceptable values are:
|
61
|
-
#
|
62
|
-
# * `linear16` - Uncompressed 16-bit signed little-endian samples.
|
63
|
-
# (LINEAR16)
|
64
|
-
# * `flac` - The [Free Lossless Audio
|
65
|
-
# Codec](http://flac.sourceforge.net/documentation.html) encoding.
|
66
|
-
# Only 16-bit samples are supported. Not all fields in STREAMINFO
|
67
|
-
# are supported. (FLAC)
|
68
|
-
# * `mulaw` - 8-bit samples that compand 14-bit audio samples using
|
69
|
-
# G.711 PCMU/mu-law. (MULAW)
|
70
|
-
# * `amr` - Adaptive Multi-Rate Narrowband codec. (`sample_rate` must
|
71
|
-
# be 8000 Hz.) (AMR)
|
72
|
-
# * `amr_wb` - Adaptive Multi-Rate Wideband codec. (`sample_rate` must
|
73
|
-
# be 16000 Hz.) (AMR_WB)
|
74
|
-
# * `ogg_opus` - Ogg Mapping for Opus. (OGG_OPUS)
|
75
|
-
#
|
76
|
-
# Lossy codecs do not recommend, as they result in a lower-quality
|
77
|
-
# speech transcription.
|
78
|
-
# * `speex` - Speex with header byte. (SPEEX_WITH_HEADER_BYTE)
|
79
|
-
#
|
80
|
-
# Lossy codecs do not recommend, as they result in a lower-quality
|
81
|
-
# speech transcription. If you must use a low-bitrate encoder,
|
82
|
-
# OGG_OPUS is preferred.
|
83
|
-
#
|
84
|
-
# @return [String,Symbol]
|
85
|
-
#
|
86
|
-
# @example
|
87
|
-
# require "google/cloud/speech"
|
88
|
-
#
|
89
|
-
# speech = Google::Cloud::Speech.new
|
90
|
-
#
|
91
|
-
# audio = speech.audio "path/to/audio.raw",
|
92
|
-
# language: "en-US",
|
93
|
-
# sample_rate: 16000
|
94
|
-
#
|
95
|
-
# audio.encoding = :linear16
|
96
|
-
# audio.encoding #=> :linear16
|
97
|
-
#
|
98
|
-
attr_accessor :encoding
|
99
|
-
|
100
|
-
##
|
101
|
-
# The language of the supplied audio as a
|
102
|
-
# [BCP-47](https://tools.ietf.org/html/bcp47) language code. e.g.
|
103
|
-
# "en-US" for English (United States), "en-GB" for English (United
|
104
|
-
# Kingdom), "fr-FR" for French (France). See [Language
|
105
|
-
# Support](https://cloud.google.com/speech/docs/languages) for a list of
|
106
|
-
# the currently supported language codes.
|
107
|
-
#
|
108
|
-
# @return [String,Symbol]
|
109
|
-
#
|
110
|
-
# @example
|
111
|
-
# require "google/cloud/speech"
|
112
|
-
#
|
113
|
-
# speech = Google::Cloud::Speech.new
|
114
|
-
#
|
115
|
-
# audio = speech.audio "path/to/audio.raw",
|
116
|
-
# encoding: :linear16,
|
117
|
-
# sample_rate: 16000
|
118
|
-
#
|
119
|
-
# audio.language = "en-US"
|
120
|
-
# audio.language #=> "en-US"
|
121
|
-
#
|
122
|
-
attr_accessor :language
|
123
|
-
|
124
|
-
##
|
125
|
-
# Sample rate in Hertz of the audio data to be recognized. Valid values
|
126
|
-
# are: 8000-48000. 16000 is optimal. For best results, set the sampling
|
127
|
-
# rate of the audio source to 16000 Hz. If that's not possible, use the
|
128
|
-
# native sample rate of the audio source (instead of re-sampling).
|
129
|
-
#
|
130
|
-
# @return [Integer]
|
131
|
-
#
|
132
|
-
# @example
|
133
|
-
# require "google/cloud/speech"
|
134
|
-
#
|
135
|
-
# speech = Google::Cloud::Speech.new
|
136
|
-
#
|
137
|
-
# audio = speech.audio "path/to/audio.raw",
|
138
|
-
# encoding: :linear16,
|
139
|
-
# language: "en-US"
|
140
|
-
#
|
141
|
-
# audio.sample_rate = 16000
|
142
|
-
# audio.sample_rate #=> 16000
|
143
|
-
#
|
144
|
-
attr_accessor :sample_rate
|
145
|
-
|
146
|
-
##
|
147
|
-
# @private Creates a new Audio instance.
|
148
|
-
def initialize
|
149
|
-
@grpc = V1::RecognitionAudio.new
|
150
|
-
end
|
151
|
-
|
152
|
-
##
|
153
|
-
# @private Whether the Audio has content.
|
154
|
-
#
|
155
|
-
def content?
|
156
|
-
@grpc.audio_source == :content
|
157
|
-
end
|
158
|
-
|
159
|
-
##
|
160
|
-
# @private Whether the Audio is a URL.
|
161
|
-
#
|
162
|
-
def url?
|
163
|
-
@grpc.audio_source == :uri
|
164
|
-
end
|
165
|
-
|
166
|
-
##
|
167
|
-
# Performs synchronous speech recognition. Sends audio data to the
|
168
|
-
# Speech API, which performs recognition on that data, and returns
|
169
|
-
# results only after all audio has been processed. Limited to audio data
|
170
|
-
# of 1 minute or less in duration.
|
171
|
-
#
|
172
|
-
# The Speech API will take roughly the same amount of time to process
|
173
|
-
# audio data sent synchronously as the duration of the supplied audio
|
174
|
-
# data. That is, if you send audio data of 30 seconds in length, expect
|
175
|
-
# the synchronous request to take approximately 30 seconds to return
|
176
|
-
# results.
|
177
|
-
#
|
178
|
-
# @see https://cloud.google.com/speech/docs/basics#synchronous-recognition
|
179
|
-
# Synchronous Speech API Recognition
|
180
|
-
# @see https://cloud.google.com/speech/docs/basics#phrase-hints
|
181
|
-
# Phrase Hints
|
182
|
-
#
|
183
|
-
# @param [String] max_alternatives The Maximum number of recognition
|
184
|
-
# hypotheses to be returned. Default is 1. The service may return
|
185
|
-
# fewer. Valid values are 0-30. Defaults to 1. Optional.
|
186
|
-
# @param [Boolean] profanity_filter When `true`, the service will
|
187
|
-
# attempt to filter out profanities, replacing all but the initial
|
188
|
-
# character in each filtered word with asterisks, e.g. "f***". Default
|
189
|
-
# is `false`.
|
190
|
-
# @param [Array<String>] phrases A list of strings containing words and
|
191
|
-
# phrases "hints" so that the speech recognition is more likely to
|
192
|
-
# recognize them. See [usage
|
193
|
-
# limits](https://cloud.google.com/speech/limits#content). Optional.
|
194
|
-
# @param [Boolean] words When `true`, return a list of words with
|
195
|
-
# additional information about each word. Currently, the only
|
196
|
-
# additional information provided is the the start and end time
|
197
|
-
# offsets. See {Result#words}. Default is `false`.
|
198
|
-
#
|
199
|
-
# @return [Array<Result>] The transcribed text of audio recognized.
|
200
|
-
#
|
201
|
-
# @example
|
202
|
-
# require "google/cloud/speech"
|
203
|
-
#
|
204
|
-
# speech = Google::Cloud::Speech.new
|
205
|
-
#
|
206
|
-
# audio = speech.audio "path/to/audio.raw",
|
207
|
-
# encoding: :linear16,
|
208
|
-
# language: "en-US",
|
209
|
-
# sample_rate: 16000
|
210
|
-
#
|
211
|
-
# results = audio.recognize
|
212
|
-
# result = results.first
|
213
|
-
# result.transcript #=> "how old is the Brooklyn Bridge"
|
214
|
-
# result.confidence #=> 0.9826789498329163
|
215
|
-
#
|
216
|
-
def recognize max_alternatives: nil, profanity_filter: nil,
|
217
|
-
phrases: nil, words: nil
|
218
|
-
ensure_speech!
|
219
|
-
|
220
|
-
speech.recognize self, encoding: encoding, sample_rate: sample_rate,
|
221
|
-
language: language,
|
222
|
-
max_alternatives: max_alternatives,
|
223
|
-
profanity_filter: profanity_filter,
|
224
|
-
phrases: phrases, words: words
|
225
|
-
end
|
226
|
-
|
227
|
-
##
|
228
|
-
# Performs asynchronous speech recognition. Requests are processed
|
229
|
-
# asynchronously, meaning a Operation is returned once the audio data
|
230
|
-
# has been sent, and can be refreshed to retrieve recognition results
|
231
|
-
# once the audio data has been processed.
|
232
|
-
#
|
233
|
-
# @see https://cloud.google.com/speech/docs/basics#async-responses
|
234
|
-
# Asynchronous Speech API Responses
|
235
|
-
#
|
236
|
-
# @param [String] max_alternatives The Maximum number of recognition
|
237
|
-
# hypotheses to be returned. Default is 1. The service may return
|
238
|
-
# fewer. Valid values are 0-30. Defaults to 1. Optional.
|
239
|
-
# @param [Boolean] profanity_filter When `true`, the service will
|
240
|
-
# attempt to filter out profanities, replacing all but the initial
|
241
|
-
# character in each filtered word with asterisks, e.g. "f***". Default
|
242
|
-
# is `false`.
|
243
|
-
# @param [Array<String>] phrases A list of strings containing words and
|
244
|
-
# phrases "hints" so that the speech recognition is more likely to
|
245
|
-
# recognize them. See [usage
|
246
|
-
# limits](https://cloud.google.com/speech/limits#content). Optional.
|
247
|
-
# @param [Boolean] words When `true`, return a list of words with
|
248
|
-
# additional information about each word. Currently, the only
|
249
|
-
# additional information provided is the the start and end time
|
250
|
-
# offsets. See {Result#words}. Default is `false`.
|
251
|
-
#
|
252
|
-
# @return [Operation] A resource represents the long-running,
|
253
|
-
# asynchronous processing of a speech-recognition operation.
|
254
|
-
#
|
255
|
-
# @example
|
256
|
-
# require "google/cloud/speech"
|
257
|
-
#
|
258
|
-
# speech = Google::Cloud::Speech.new
|
259
|
-
#
|
260
|
-
# audio = speech.audio "path/to/audio.raw",
|
261
|
-
# encoding: :linear16,
|
262
|
-
# language: "en-US",
|
263
|
-
# sample_rate: 16000
|
264
|
-
#
|
265
|
-
# op = audio.process
|
266
|
-
# op.done? #=> false
|
267
|
-
# op.reload!
|
268
|
-
# op.done? #=> true
|
269
|
-
# results = op.results
|
270
|
-
#
|
271
|
-
def process max_alternatives: nil, profanity_filter: nil,
|
272
|
-
phrases: nil, words: nil
|
273
|
-
ensure_speech!
|
274
|
-
|
275
|
-
speech.process self, encoding: encoding,
|
276
|
-
sample_rate: sample_rate,
|
277
|
-
language: language,
|
278
|
-
max_alternatives: max_alternatives,
|
279
|
-
profanity_filter: profanity_filter,
|
280
|
-
phrases: phrases, words: words
|
281
|
-
end
|
282
|
-
alias long_running_recognize process
|
283
|
-
alias recognize_job process
|
284
|
-
|
285
|
-
##
|
286
|
-
# @private The Google API Client object for the Audio.
|
287
|
-
def to_grpc
|
288
|
-
@grpc
|
289
|
-
end
|
290
|
-
|
291
|
-
##
|
292
|
-
# @private New Audio from a source object.
|
293
|
-
def self.from_source source, speech
|
294
|
-
audio = new
|
295
|
-
audio.instance_variable_set :@speech, speech
|
296
|
-
if source.respond_to?(:read) && source.respond_to?(:rewind)
|
297
|
-
source.rewind
|
298
|
-
audio.grpc.content = source.read
|
299
|
-
return audio
|
300
|
-
end
|
301
|
-
# Convert Storage::File objects to the URL
|
302
|
-
source = source.to_gs_url if source.respond_to? :to_gs_url
|
303
|
-
# Everything should be a string from now on
|
304
|
-
source = String source
|
305
|
-
# Create an Audio from the Google Storage URL
|
306
|
-
if source.start_with? "gs://"
|
307
|
-
audio.grpc.uri = source
|
308
|
-
return audio
|
309
|
-
end
|
310
|
-
# Create an audio from a file on the filesystem
|
311
|
-
if File.file? source
|
312
|
-
raise ArgumentError, "Cannot read #{source}" unless \
|
313
|
-
File.readable? source
|
314
|
-
audio.grpc.content = File.read source, mode: "rb"
|
315
|
-
return audio
|
316
|
-
end
|
317
|
-
raise ArgumentError, "Unable to convert #{source} to an Audio"
|
318
|
-
end
|
319
|
-
|
320
|
-
protected
|
321
|
-
|
322
|
-
##
|
323
|
-
# Raise an error unless an active Speech Project object is available.
|
324
|
-
def ensure_speech!
|
325
|
-
raise "Must have active connection" unless @speech
|
326
|
-
end
|
327
|
-
end
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|