35
35
from google .cloud .speech_v1 .proto import cloud_speech_pb2_grpc
36
36
from google .longrunning import operations_pb2
37
37
38
- _GAPIC_LIBRARY_VERSION = pkg_resources .get_distribution (
39
- 'google-cloud-speech' , ).version
38
+ _GAPIC_LIBRARY_VERSION = pkg_resources .get_distribution ("google-cloud-speech" ).version
40
39
41
40
42
41
class SpeechClient (object ):
43
42
"""Service that implements Google Cloud Speech API."""
44
43
45
- SERVICE_ADDRESS = ' speech.googleapis.com:443'
44
+ SERVICE_ADDRESS = " speech.googleapis.com:443"
46
45
"""The default address of the service."""
47
46
48
47
# The name of the interface for this client. This is the key used to
49
48
# find the method configuration in the client_config dictionary.
50
- _INTERFACE_NAME = ' google.cloud.speech.v1.Speech'
49
+ _INTERFACE_NAME = " google.cloud.speech.v1.Speech"
51
50
52
51
@classmethod
53
52
def from_service_account_file (cls , filename , * args , ** kwargs ):
@@ -63,19 +62,20 @@ def from_service_account_file(cls, filename, *args, **kwargs):
63
62
Returns:
64
63
SpeechClient: The constructed client.
65
64
"""
66
- credentials = service_account .Credentials .from_service_account_file (
67
- filename )
68
- kwargs ['credentials' ] = credentials
65
+ credentials = service_account .Credentials .from_service_account_file (filename )
66
+ kwargs ["credentials" ] = credentials
69
67
return cls (* args , ** kwargs )
70
68
71
69
from_service_account_json = from_service_account_file
72
70
73
- def __init__ (self ,
74
- transport = None ,
75
- channel = None ,
76
- credentials = None ,
77
- client_config = None ,
78
- client_info = None ):
71
+ def __init__ (
72
+ self ,
73
+ transport = None ,
74
+ channel = None ,
75
+ credentials = None ,
76
+ client_config = None ,
77
+ client_info = None ,
78
+ ):
79
79
"""Constructor.
80
80
81
81
Args:
@@ -109,18 +109,19 @@ def __init__(self,
109
109
# Raise deprecation warnings for things we want to go away.
110
110
if client_config is not None :
111
111
warnings .warn (
112
- ' The `client_config` argument is deprecated.' ,
112
+ " The `client_config` argument is deprecated." ,
113
113
PendingDeprecationWarning ,
114
- stacklevel = 2 )
114
+ stacklevel = 2 ,
115
+ )
115
116
else :
116
117
client_config = speech_client_config .config
117
118
118
119
if channel :
119
120
warnings .warn (
120
- 'The `channel` argument is deprecated; use '
121
- '`transport` instead.' ,
121
+ "The `channel` argument is deprecated; use " "`transport` instead." ,
122
122
PendingDeprecationWarning ,
123
- stacklevel = 2 )
123
+ stacklevel = 2 ,
124
+ )
124
125
125
126
# Instantiate the transport.
126
127
# The transport is responsible for handling serialization and
@@ -134,19 +135,19 @@ def __init__(self,
134
135
else :
135
136
if credentials :
136
137
raise ValueError (
137
- 'Received both a transport instance and '
138
- 'credentials; these are mutually exclusive.' )
138
+ "Received both a transport instance and "
139
+ "credentials; these are mutually exclusive."
140
+ )
139
141
self .transport = transport
140
142
else :
141
143
self .transport = speech_grpc_transport .SpeechGrpcTransport (
142
- address = self .SERVICE_ADDRESS ,
143
- channel = channel ,
144
- credentials = credentials ,
144
+ address = self .SERVICE_ADDRESS , channel = channel , credentials = credentials
145
145
)
146
146
147
147
if client_info is None :
148
148
client_info = google .api_core .gapic_v1 .client_info .ClientInfo (
149
- gapic_version = _GAPIC_LIBRARY_VERSION , )
149
+ gapic_version = _GAPIC_LIBRARY_VERSION
150
+ )
150
151
else :
151
152
client_info .gapic_version = _GAPIC_LIBRARY_VERSION
152
153
self ._client_info = client_info
@@ -156,7 +157,8 @@ def __init__(self,
156
157
# (Ordinarily, these are the defaults specified in the `*_config.py`
157
158
# file next to this one.)
158
159
self ._method_configs = google .api_core .gapic_v1 .config .parse_method_configs (
159
- client_config ['interfaces' ][self ._INTERFACE_NAME ], )
160
+ client_config ["interfaces" ][self ._INTERFACE_NAME ]
161
+ )
160
162
161
163
# Save a dictionary of cached API call functions.
162
164
# These are the actual callables which invoke the proper
@@ -165,12 +167,14 @@ def __init__(self,
165
167
self ._inner_api_calls = {}
166
168
167
169
# Service calls
168
- def recognize (self ,
169
- config ,
170
- audio ,
171
- retry = google .api_core .gapic_v1 .method .DEFAULT ,
172
- timeout = google .api_core .gapic_v1 .method .DEFAULT ,
173
- metadata = None ):
170
+ def recognize (
171
+ self ,
172
+ config ,
173
+ audio ,
174
+ retry = google .api_core .gapic_v1 .method .DEFAULT ,
175
+ timeout = google .api_core .gapic_v1 .method .DEFAULT ,
176
+ metadata = None ,
177
+ ):
174
178
"""
175
179
Performs synchronous speech recognition: receive results after all audio
176
180
has been sent and processed.
@@ -220,28 +224,29 @@ def recognize(self,
220
224
ValueError: If the parameters are invalid.
221
225
"""
222
226
# Wrap the transport method to add retry and timeout logic.
223
- if ' recognize' not in self ._inner_api_calls :
227
+ if " recognize" not in self ._inner_api_calls :
224
228
self ._inner_api_calls [
225
- 'recognize' ] = google .api_core .gapic_v1 .method .wrap_method (
226
- self .transport .recognize ,
227
- default_retry = self ._method_configs ['Recognize' ].retry ,
228
- default_timeout = self ._method_configs ['Recognize' ].timeout ,
229
- client_info = self ._client_info ,
230
- )
229
+ "recognize"
230
+ ] = google .api_core .gapic_v1 .method .wrap_method (
231
+ self .transport .recognize ,
232
+ default_retry = self ._method_configs ["Recognize" ].retry ,
233
+ default_timeout = self ._method_configs ["Recognize" ].timeout ,
234
+ client_info = self ._client_info ,
235
+ )
231
236
232
- request = cloud_speech_pb2 .RecognizeRequest (
233
- config = config ,
234
- audio = audio ,
237
+ request = cloud_speech_pb2 .RecognizeRequest (config = config , audio = audio )
238
+ return self . _inner_api_calls [ "recognize" ](
239
+ request , retry = retry , timeout = timeout , metadata = metadata
235
240
)
236
- return self . _inner_api_calls [ 'recognize' ](
237
- request , retry = retry , timeout = timeout , metadata = metadata )
238
-
239
- def long_running_recognize ( self ,
240
- config ,
241
- audio ,
242
- retry = google .api_core .gapic_v1 .method .DEFAULT ,
243
- timeout = google . api_core . gapic_v1 . method . DEFAULT ,
244
- metadata = None ):
241
+
242
+ def long_running_recognize (
243
+ self ,
244
+ config ,
245
+ audio ,
246
+ retry = google . api_core . gapic_v1 . method . DEFAULT ,
247
+ timeout = google .api_core .gapic_v1 .method .DEFAULT ,
248
+ metadata = None ,
249
+ ):
245
250
"""
246
251
Performs asynchronous speech recognition: receive results via the
247
252
google.longrunning.Operations interface. Returns either an
@@ -302,35 +307,36 @@ def long_running_recognize(self,
302
307
ValueError: If the parameters are invalid.
303
308
"""
304
309
# Wrap the transport method to add retry and timeout logic.
305
- if ' long_running_recognize' not in self ._inner_api_calls :
310
+ if " long_running_recognize" not in self ._inner_api_calls :
306
311
self ._inner_api_calls [
307
- 'long_running_recognize' ] = google .api_core .gapic_v1 .method .wrap_method (
308
- self .transport .long_running_recognize ,
309
- default_retry = self ._method_configs ['LongRunningRecognize' ].
310
- retry ,
311
- default_timeout = self .
312
- _method_configs ['LongRunningRecognize' ].timeout ,
313
- client_info = self ._client_info ,
314
- )
312
+ "long_running_recognize"
313
+ ] = google .api_core .gapic_v1 .method .wrap_method (
314
+ self .transport .long_running_recognize ,
315
+ default_retry = self ._method_configs ["LongRunningRecognize" ].retry ,
316
+ default_timeout = self ._method_configs ["LongRunningRecognize" ].timeout ,
317
+ client_info = self ._client_info ,
318
+ )
315
319
316
320
request = cloud_speech_pb2 .LongRunningRecognizeRequest (
317
- config = config ,
318
- audio = audio ,
321
+ config = config , audio = audio
322
+ )
323
+ operation = self ._inner_api_calls ["long_running_recognize" ](
324
+ request , retry = retry , timeout = timeout , metadata = metadata
319
325
)
320
- operation = self ._inner_api_calls ['long_running_recognize' ](
321
- request , retry = retry , timeout = timeout , metadata = metadata )
322
326
return google .api_core .operation .from_gapic (
323
327
operation ,
324
328
self .transport ._operations_client ,
325
329
cloud_speech_pb2 .LongRunningRecognizeResponse ,
326
330
metadata_type = cloud_speech_pb2 .LongRunningRecognizeMetadata ,
327
331
)
328
332
329
- def streaming_recognize (self ,
330
- requests ,
331
- retry = google .api_core .gapic_v1 .method .DEFAULT ,
332
- timeout = google .api_core .gapic_v1 .method .DEFAULT ,
333
- metadata = None ):
333
+ def streaming_recognize (
334
+ self ,
335
+ requests ,
336
+ retry = google .api_core .gapic_v1 .method .DEFAULT ,
337
+ timeout = google .api_core .gapic_v1 .method .DEFAULT ,
338
+ metadata = None ,
339
+ ):
334
340
"""
335
341
Performs bidirectional streaming speech recognition: receive results while
336
342
sending audio. This method is only available via the gRPC API (not REST).
@@ -372,16 +378,16 @@ def streaming_recognize(self,
372
378
ValueError: If the parameters are invalid.
373
379
"""
374
380
# Wrap the transport method to add retry and timeout logic.
375
- if ' streaming_recognize' not in self ._inner_api_calls :
381
+ if " streaming_recognize" not in self ._inner_api_calls :
376
382
self ._inner_api_calls [
377
- 'streaming_recognize' ] = google .api_core .gapic_v1 .method .wrap_method (
378
- self .transport .streaming_recognize ,
379
- default_retry = self ._method_configs ['StreamingRecognize' ].
380
- retry ,
381
- default_timeout = self ._method_configs ['StreamingRecognize' ].
382
- timeout ,
383
- client_info = self ._client_info ,
384
- )
383
+ "streaming_recognize"
384
+ ] = google .api_core .gapic_v1 .method .wrap_method (
385
+ self .transport .streaming_recognize ,
386
+ default_retry = self ._method_configs ["StreamingRecognize" ].retry ,
387
+ default_timeout = self ._method_configs ["StreamingRecognize" ].timeout ,
388
+ client_info = self ._client_info ,
389
+ )
385
390
386
- return self ._inner_api_calls ['streaming_recognize' ](
387
- requests , retry = retry , timeout = timeout , metadata = metadata )
391
+ return self ._inner_api_calls ["streaming_recognize" ](
392
+ requests , retry = retry , timeout = timeout , metadata = metadata
393
+ )
0 commit comments