2020import time
2121
2222from google .cloud .credentials import get_credentials
23- from google .cloud .speech .v1beta1 import cloud_speech_pb2
24- from google .longrunning import operations_grpc_pb2
23+ from google .cloud .grpc . speech .v1beta1 import cloud_speech_pb2
24+ from google .longrunning import operations_pb2
2525from grpc .beta import implementations
2626
2727# Keep the request alive for this many seconds
@@ -76,7 +76,7 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'):
7676 print (operation )
7777
7878 # Construct a long running operation endpoint.
79- service = operations_grpc_pb2 .beta_create_Operations_stub (channel )
79+ service = operations_pb2 .beta_create_Operations_stub (channel )
8080
8181 name = operation .name
8282
@@ -85,9 +85,12 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'):
8585 print ('Waiting for server processing...' )
8686 time .sleep (1 )
8787 operation = service .GetOperation (
88- operations_grpc_pb2 .GetOperationRequest (name = name ),
88+ operations_pb2 .GetOperationRequest (name = name ),
8989 DEADLINE_SECS )
9090
91+ if operation .error .message :
92+ print ('\n Operation error:\n {}' .format (operation .error ))
93+
9194 if operation .done :
9295 break
9396
@@ -112,7 +115,7 @@ def _gcs_uri(text):
112115 parser = argparse .ArgumentParser ()
113116 parser .add_argument ('input_uri' , type = _gcs_uri )
114117 parser .add_argument (
115- '--encoding' , default = 'FLAC ' , choices = [
118+ '--encoding' , default = 'LINEAR16 ' , choices = [
116119 'LINEAR16' , 'FLAC' , 'MULAW' , 'AMR' , 'AMR_WB' ],
117120 help = 'How the audio file is encoded. See {}#L67' .format (
118121 'https://github.com/googleapis/googleapis/blob/master/'
0 commit comments