Skip to content

Commit 41f043a

Browse files
committed
Add virtual method for _gax async_recognize.
1 parent 57bb557 commit 41f043a

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

speech/google/cloud/speech/_gax.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,50 @@ class GAPICSpeechAPI(object):
2727
def __init__(self):
2828
self._gapic_api = SpeechApi()
2929

30+
def async_recognize(self, sample, language_code=None,
31+
max_alternatives=None, profanity_filter=None,
32+
speech_context=None):
33+
"""Asychronous Recognize request to Google Speech API.
34+
35+
.. _async_recognize: https://cloud.google.com/speech/reference/\
36+
rest/v1beta1/speech/asyncrecognize
37+
38+
See `async_recognize`_.
39+
40+
:type sample: :class:`~google.cloud.speech.sample.Sample`
41+
:param sample: Instance of ``Sample`` containing audio information.
42+
43+
:type language_code: str
44+
:param language_code: (Optional) The language of the supplied audio as
45+
BCP-47 language tag. Example: ``'en-GB'``.
46+
If omitted, defaults to ``'en-US'``.
47+
48+
:type max_alternatives: int
49+
:param max_alternatives: (Optional) Maximum number of recognition
50+
hypotheses to be returned. The server may
51+
return fewer than maxAlternatives.
52+
Valid values are 0-30. A value of 0 or 1
53+
will return a maximum of 1. Defaults to 1
54+
55+
:type profanity_filter: bool
56+
:param profanity_filter: If True, the server will attempt to filter
57+
out profanities, replacing all but the
58+
initial character in each filtered word with
59+
asterisks, e.g. ``'f***'``. If False or
60+
omitted, profanities won't be filtered out.
61+
62+
:type speech_context: list
63+
:param speech_context: A list of strings (max 50) containing words and
64+
phrases "hints" so that the speech recognition
65+
is more likely to recognize them. This can be
66+
used to improve the accuracy for specific words
67+
and phrases. This can also be used to add new
68+
words to the vocabulary of the recognizer.
69+
70+
:raises NotImplementedError: Always.
71+
"""
72+
raise NotImplementedError
73+
3074
def sync_recognize(self, sample, language_code=None, max_alternatives=None,
3175
profanity_filter=None, speech_context=None):
3276
"""Synchronous Speech Recognition.

speech/unit_tests/test_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,19 @@ def test_async_recognize_no_gax(self):
265265
self.assertFalse(operation.complete)
266266
self.assertIsNone(operation.metadata)
267267

268+
def test_async_recognize_with_gax(self):
269+
from google.cloud import speech
270+
271+
credentials = _Credentials()
272+
client = self._makeOne(credentials=credentials)
273+
client.connection = _Connection()
274+
275+
sample = client.sample(source_uri=self.AUDIO_SOURCE_URI,
276+
encoding=speech.Encoding.LINEAR16,
277+
sample_rate=self.SAMPLE_RATE)
278+
with self.assertRaises(NotImplementedError):
279+
client.async_recognize(sample)
280+
268281
def test_speech_api_with_gax(self):
269282
from google.cloud.speech import _gax as MUT
270283
from google.cloud._testing import _Monkey

0 commit comments

Comments
 (0)