2828import google .auth
2929import google .auth .transport .grpc
3030import google .auth .transport .requests
31- from google .cloud .proto .speech .v1beta1 import cloud_speech_pb2
31+ from google .cloud .proto .speech .v1 import cloud_speech_pb2
3232from google .longrunning import operations_pb2
3333
3434# Keep the request alive for this many seconds
@@ -49,19 +49,19 @@ def make_channel(host, port):
4949 credentials , http_request , target )
5050
5151
52- def main (input_uri , encoding , sample_rate , language_code = 'en-US ' ):
53- channel = make_channel ('speech.googleapis.com' , 443 )
52+ def main (input_uri , encoding , sample_rate , language_code = 'ja-JP ' ):
53+ channel = make_channel ('jerjou-dev- speech.sandbox .googleapis.com' , 443 )
5454 service = cloud_speech_pb2 .SpeechStub (channel )
5555
5656 # The method and parameters can be inferred from the proto from which the
5757 # grpc client lib was generated. See:
58- # https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1 /cloud_speech.proto
59- operation = service .AsyncRecognize (cloud_speech_pb2 .AsyncRecognizeRequest (
58+ # https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1 /cloud_speech.proto
59+ operation = service .LongRunningRecognize (cloud_speech_pb2 .LongRunningRecognizeRequest (
6060 config = cloud_speech_pb2 .RecognitionConfig (
6161 # There are a bunch of config options you can specify. See
6262 # https://goo.gl/KPZn97 for the full list.
6363 encoding = encoding , # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
64- sample_rate = sample_rate , # the rate in hertz
64+ sample_rate_hertz = sample_rate , # the rate in hertz
6565 # See https://g.co/cloud/speech/docs/languages for a list of
6666 # supported languages.
6767 language_code = language_code , # a BCP-47 language tag
@@ -93,7 +93,7 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'):
9393 if operation .done :
9494 break
9595
96- response = cloud_speech_pb2 .AsyncRecognizeResponse ()
96+ response = cloud_speech_pb2 .LongRunningRecognizeResponse ()
9797 operation .response .Unpack (response )
9898 # Print the recognition result alternatives and confidence scores.
9999 for result in response .results :
@@ -120,7 +120,7 @@ def _gcs_uri(text):
120120 'LINEAR16' , 'FLAC' , 'MULAW' , 'AMR' , 'AMR_WB' ],
121121 help = 'How the audio file is encoded. See {}#L67' .format (
122122 'https://github.com/googleapis/googleapis/blob/master/'
123- 'google/cloud/speech/v1beta1 /cloud_speech.proto' ))
123+ 'google/cloud/speech/v1 /cloud_speech.proto' ))
124124 parser .add_argument ('--sample_rate' , type = int , default = 16000 )
125125
126126 args = parser .parse_args ()
0 commit comments