1717from google .longrunning import operations_grpc
1818
1919from google .cloud .gapic .speech .v1beta1 .speech_api import SpeechApi
20+ from google .cloud .grpc .speech .v1beta1 .cloud_speech_pb2 import (
21+ AsyncRecognizeMetadata )
22+ from google .cloud .grpc .speech .v1beta1 .cloud_speech_pb2 import (
23+ AsyncRecognizeResponse )
2024from google .cloud .grpc .speech .v1beta1 .cloud_speech_pb2 import SpeechContext
2125from google .cloud .grpc .speech .v1beta1 .cloud_speech_pb2 import RecognitionConfig
2226from google .cloud .grpc .speech .v1beta1 .cloud_speech_pb2 import RecognitionAudio
2529from google .cloud .grpc .speech .v1beta1 .cloud_speech_pb2 import (
2630 StreamingRecognizeRequest )
2731
28-
2932from google .cloud ._helpers import make_secure_stub
3033from google .cloud .connection import DEFAULT_USER_AGENT
3134from google .cloud .speech .transcript import Transcript
3235from google .cloud .operation import Operation
36+ from google .cloud .operation import register_type
37+
3338
3439OPERATIONS_API_HOST = 'speech.googleapis.com'
3540
41+ register_type (AsyncRecognizeMetadata )
42+ register_type (AsyncRecognizeResponse )
43+
3644
3745class GAPICSpeechAPI (object ):
3846 """Manage calls through GAPIC wrappers to the Speech API."""
@@ -80,7 +88,8 @@ def async_recognize(self, sample, language_code=None,
8088 and phrases. This can also be used to add new
8189 words to the vocabulary of the recognizer.
8290
83- :raises NotImplementedError: Always.
91+ :rtype: :class:`~google.cloud.operation.Opeartion`
92+ :returns: Instance of ``Operation`` to poll for results.
8493 """
8594 config = RecognitionConfig (
8695 encoding = sample .encoding , sample_rate = sample .sample_rate ,
@@ -90,15 +99,15 @@ def async_recognize(self, sample, language_code=None,
9099
91100 audio = RecognitionAudio (content = sample .content ,
92101 uri = sample .source_uri )
102+ api = self ._gapic_api
103+ response = api .async_recognize (config = config , audio = audio )
104+
93105 self ._client ._operations_stub = make_secure_stub (
94106 self ._client .connection .credentials ,
95107 DEFAULT_USER_AGENT ,
96108 operations_grpc .OperationsStub ,
97109 OPERATIONS_API_HOST )
98-
99- api = self ._gapic_api
100- operation = api .sync_recognize (config = config , audio = audio )
101- return Operation .from_pb (operation , self ._client )
110+ return Operation .from_pb (response , self ._client )
102111
103112 def sync_recognize (self , sample , language_code = None , max_alternatives = None ,
104113 profanity_filter = None , speech_context = None ):
0 commit comments