Skip to content

Commit aff38f5

Browse files
committed
Updates from #2344 for speech API.
1 parent 65722de commit aff38f5

File tree

1 file changed

+41
-36
lines changed
  • google-cloud-speech/google/cloud/speech

1 file changed

+41
-36
lines changed

google-cloud-speech/google/cloud/speech/client.py

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,17 @@ class Client(client_module.Client):
4646

4747
_connection_class = Connection
4848

49-
def async_recognize(self, content, source_uri, encoding, sample_rate,
49+
def async_recognize(self, encoding, sample_rate, content=None,
5050
language_code=None, max_alternatives=None,
51-
profanity_filter=None, speech_context=None):
51+
profanity_filter=None, source_uri=None,
52+
speech_context=None):
5253
"""Asychronous Recognize request to Google Speech API.
5354
5455
.. _async_recognize: https://cloud.google.com/speech/reference/\
5556
rest/v1beta1/speech/asyncrecognize
5657
5758
See `async_recognize`_.
5859
59-
:type content: bytes
60-
:param content: Byte stream of audio.
61-
62-
:type source_uri: str
63-
:param source_uri: URI that points to a file that contains audio
64-
data bytes as specified in RecognitionConfig.
65-
Currently, only Google Cloud Storage URIs are
66-
supported, which must be specified in the following
67-
format: ``gs://bucket_name/object_name``.
68-
6960
:type encoding: str
7061
:param encoding: encoding of audio data sent in all RecognitionAudio
7162
messages, can be one of: :attr:`~.Encoding.LINEAR16`,
@@ -80,6 +71,9 @@ def async_recognize(self, content, source_uri, encoding, sample_rate,
8071
native sample rate of the audio source (instead of
8172
re-sampling).
8273
74+
:type content: bytes
75+
:param content: Byte stream of audio.
76+
8377
:type language_code: str
8478
:param language_code: (Optional) The language of the supplied audio as
8579
BCP-47 language tag. Example: ``'en-GB'``.
@@ -99,6 +93,13 @@ def async_recognize(self, content, source_uri, encoding, sample_rate,
9993
asterisks, e.g. ``'f***'``. If False or
10094
omitted, profanities won't be filtered out.
10195
96+
:type source_uri: str
97+
:param source_uri: URI that points to a file that contains audio
98+
data bytes as specified in RecognitionConfig.
99+
Currently, only Google Cloud Storage URIs are
100+
supported, which must be specified in the following
101+
format: ``gs://bucket_name/object_name``.
102+
102103
:type speech_context: list
103104
:param speech_context: A list of strings (max 50) containing words and
104105
phrases "hints" so that the speech recognition
@@ -121,26 +122,17 @@ def async_recognize(self, content, source_uri, encoding, sample_rate,
121122

122123
return Operation.from_api_repr(self, api_response)
123124

124-
def sync_recognize(self, content, source_uri, encoding, sample_rate,
125+
def sync_recognize(self, encoding, sample_rate, content=None,
125126
language_code=None, max_alternatives=None,
126-
profanity_filter=None, speech_context=None):
127+
profanity_filter=None, source_uri=None,
128+
speech_context=None):
127129
"""Synchronous Speech Recognition.
128130
129131
.. _sync_recognize: https://cloud.google.com/speech/reference/\
130132
rest/v1beta1/speech/syncrecognize
131133
132134
See `sync_recognize`_.
133135
134-
:type content: bytes
135-
:param content: Byte stream of audio.
136-
137-
:type source_uri: str
138-
:param source_uri: URI that points to a file that contains audio
139-
data bytes as specified in RecognitionConfig.
140-
Currently, only Google Cloud Storage URIs are
141-
supported, which must be specified in the following
142-
format: ``gs://bucket_name/object_name``.
143-
144136
:type encoding: str
145137
:param encoding: encoding of audio data sent in all RecognitionAudio
146138
messages, can be one of: :attr:`~.Encoding.LINEAR16`,
@@ -155,6 +147,10 @@ def sync_recognize(self, content, source_uri, encoding, sample_rate,
155147
native sample rate of the audio source (instead of
156148
re-sampling).
157149
150+
:type content: bytes
151+
:param content: Byte stream of audio.
152+
153+
158154
:type language_code: str
159155
:param language_code: (Optional) The language of the supplied audio as
160156
BCP-47 language tag. Example: ``'en-GB'``.
@@ -174,6 +170,13 @@ def sync_recognize(self, content, source_uri, encoding, sample_rate,
174170
asterisks, e.g. ``'f***'``. If False or
175171
omitted, profanities won't be filtered out.
176172
173+
:type source_uri: str
174+
:param source_uri: URI that points to a file that contains audio
175+
data bytes as specified in RecognitionConfig.
176+
Currently, only Google Cloud Storage URIs are
177+
supported, which must be specified in the following
178+
format: ``gs://bucket_name/object_name``.
179+
177180
:type speech_context: list
178181
:param speech_context: A list of strings (max 50) containing words and
179182
phrases "hints" so that the speech recognition
@@ -206,21 +209,12 @@ def sync_recognize(self, content, source_uri, encoding, sample_rate,
206209
raise ValueError('result in api should have length 1')
207210

208211

209-
def _build_request_data(content, source_uri, encoding, sample_rate,
212+
def _build_request_data(encoding, sample_rate, content=None,
210213
language_code=None, max_alternatives=None,
211-
profanity_filter=None, speech_context=None):
214+
profanity_filter=None, source_uri=None,
215+
speech_context=None):
212216
"""Builds the request data before making API request.
213217
214-
:type content: bytes
215-
:param content: Byte stream of audio.
216-
217-
:type source_uri: str
218-
:param source_uri: URI that points to a file that contains audio
219-
data bytes as specified in RecognitionConfig.
220-
Currently, only Google Cloud Storage URIs are
221-
supported, which must be specified in the following
222-
format: ``gs://bucket_name/object_name``.
223-
224218
:type encoding: str
225219
:param encoding: encoding of audio data sent in all RecognitionAudio
226220
messages, can be one of: :attr:`~.Encoding.LINEAR16`,
@@ -235,6 +229,10 @@ def _build_request_data(content, source_uri, encoding, sample_rate,
235229
native sample rate of the audio source (instead of
236230
re-sampling).
237231
232+
:type content: bytes
233+
:param content: Byte stream of audio.
234+
235+
238236
:type language_code: str
239237
:param language_code: (Optional) The language of the supplied audio as
240238
BCP-47 language tag. Example: ``'en-GB'``.
@@ -254,6 +252,13 @@ def _build_request_data(content, source_uri, encoding, sample_rate,
254252
asterisks, e.g. ``'f***'``. If False or
255253
omitted, profanities won't be filtered out.
256254
255+
:type source_uri: str
256+
:param source_uri: URI that points to a file that contains audio
257+
data bytes as specified in RecognitionConfig.
258+
Currently, only Google Cloud Storage URIs are
259+
supported, which must be specified in the following
260+
format: ``gs://bucket_name/object_name``.
261+
257262
:type speech_context: list
258263
:param speech_context: A list of strings (max 50) containing words and
259264
phrases "hints" so that the speech recognition

0 commit comments

Comments
 (0)