28
28
import google .auth
29
29
import google .auth .transport .grpc
30
30
import 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
32
32
from google .longrunning import operations_pb2
33
33
34
34
# Keep the request alive for this many seconds
@@ -49,19 +49,19 @@ def make_channel(host, port):
49
49
credentials , http_request , target )
50
50
51
51
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 )
54
54
service = cloud_speech_pb2 .SpeechStub (channel )
55
55
56
56
# The method and parameters can be inferred from the proto from which the
57
57
# 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 (
60
60
config = cloud_speech_pb2 .RecognitionConfig (
61
61
# There are a bunch of config options you can specify. See
62
62
# https://goo.gl/KPZn97 for the full list.
63
63
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
65
65
# See https://g.co/cloud/speech/docs/languages for a list of
66
66
# supported languages.
67
67
language_code = language_code , # a BCP-47 language tag
@@ -93,7 +93,7 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'):
93
93
if operation .done :
94
94
break
95
95
96
- response = cloud_speech_pb2 .AsyncRecognizeResponse ()
96
+ response = cloud_speech_pb2 .LongRunningRecognizeResponse ()
97
97
operation .response .Unpack (response )
98
98
# Print the recognition result alternatives and confidence scores.
99
99
for result in response .results :
@@ -120,7 +120,7 @@ def _gcs_uri(text):
120
120
'LINEAR16' , 'FLAC' , 'MULAW' , 'AMR' , 'AMR_WB' ],
121
121
help = 'How the audio file is encoded. See {}#L67' .format (
122
122
'https://github.com/googleapis/googleapis/blob/master/'
123
- 'google/cloud/speech/v1beta1 /cloud_speech.proto' ))
123
+ 'google/cloud/speech/v1 /cloud_speech.proto' ))
124
124
parser .add_argument ('--sample_rate' , type = int , default = 16000 )
125
125
126
126
args = parser .parse_args ()
0 commit comments