@@ -117,15 +117,10 @@ def async_recognize(self, sample, language_code=None,
117117 if sample .encoding is not Encoding .LINEAR16 :
118118 raise ValueError ('Only LINEAR16 encoding is supported by '
119119 'asynchronous speech requests.' )
120-
121- data = _build_request_data (sample , language_code , max_alternatives ,
120+ api = self . speech_api
121+ return api . async_recognize (sample , language_code , max_alternatives ,
122122 profanity_filter , speech_context )
123123
124- api_response = self .connection .api_request (
125- method = 'POST' , path = 'speech:asyncrecognize' , data = data )
126-
127- return Operation .from_api_repr (self , api_response )
128-
129124 @staticmethod
130125 def sample (content = None , source_uri = None , encoding = None ,
131126 sample_rate = None ):
@@ -235,6 +230,56 @@ def __init__(self, client):
235230 self ._client = client
236231 self ._connection = client .connection
237232
233+ def async_recognize (self , sample , language_code = None ,
234+ max_alternatives = None , profanity_filter = None ,
235+ speech_context = None ):
236+ """Asychronous Recognize request to Google Speech API.
237+
238+ .. _async_recognize: https://cloud.google.com/speech/reference/\
239+ rest/v1beta1/speech/asyncrecognize
240+
241+ See `async_recognize`_.
242+
243+ :type sample: :class:`~google.cloud.speech.sample.Sample`
244+ :param sample: Instance of ``Sample`` containing audio information.
245+
246+ :type language_code: str
247+ :param language_code: (Optional) The language of the supplied audio as
248+ BCP-47 language tag. Example: ``'en-GB'``.
249+ If omitted, defaults to ``'en-US'``.
250+
251+ :type max_alternatives: int
252+ :param max_alternatives: (Optional) Maximum number of recognition
253+ hypotheses to be returned. The server may
254+ return fewer than maxAlternatives.
255+ Valid values are 0-30. A value of 0 or 1
256+ will return a maximum of 1. Defaults to 1
257+
258+ :type profanity_filter: bool
259+ :param profanity_filter: If True, the server will attempt to filter
260+ out profanities, replacing all but the
261+ initial character in each filtered word with
262+ asterisks, e.g. ``'f***'``. If False or
263+ omitted, profanities won't be filtered out.
264+
265+ :type speech_context: list
266+ :param speech_context: A list of strings (max 50) containing words and
267+ phrases "hints" so that the speech recognition
268+ is more likely to recognize them. This can be
269+ used to improve the accuracy for specific words
270+ and phrases. This can also be used to add new
271+ words to the vocabulary of the recognizer.
272+
273+ :rtype: `~google.cloud.speech.operation.Operation`
274+ :returns: ``Operation`` for asynchronous request to Google Speech API.
275+ """
276+ data = _build_request_data (sample , language_code , max_alternatives ,
277+ profanity_filter , speech_context )
278+ api_response = self ._connection .api_request (
279+ method = 'POST' , path = 'speech:asyncrecognize' , data = data )
280+
281+ return Operation .from_api_repr (self , api_response )
282+
238283 def sync_recognize (self , sample , language_code = None , max_alternatives = None ,
239284 profanity_filter = None , speech_context = None ):
240285 """Synchronous Speech Recognition.
0 commit comments