8000 Update for v1 · janiceblue/python-docs-samples@a9d914b · GitHub
[go: up one dir, main page]

Skip to content

Commit a9d914b

Browse files
author
Jerjou Cheng
committed
Update for v1
1 parent 346ede6 commit a9d914b

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

speech/grpc/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
grpcio==1.1.0
22
PyAudio==0.2.10
3-
proto-google-cloud-speech-v1beta1==0.15.1
3+
proto-google-cloud-speech-v1==0.15.3
44
six==1.10.0
55
requests==2.13.0
66
google-auth==0.8.0

speech/grpc/transcribe.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import google.auth
2626
import google.auth.transport.grpc
2727
import google.auth.transport.requests
28-
from google.cloud.proto.speech.v1beta1 import cloud_speech_pb2
28+
from google.cloud.proto.speech.v1 import cloud_speech_pb2
2929

3030
# Keep the request alive for this many seconds
3131
DEADLINE_SECS = 60
@@ -47,19 +47,19 @@ def make_channel(host, port):
4747

4848
def main(input_uri, encoding, sample_rate, language_code='ja-JP'):
4949
service = cloud_speech_pb2.SpeechStub(
50-
#make_channel('jerjou-dev-speech.sandbox.googleapis.com', 443))
51-
make_channel('speech.googleapis.com', 443))
50+
make_channel('jerjou-dev-speech.sandbox.googleapis.com', 443))
51+
#make_channel('speech.googleapis.com', 443))
5252

5353
# The method and parameters can be inferred from the proto from which the
5454
# grpc client lib was generated. See:
55-
# https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1/cloud_speech.proto
55+
# https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1/cloud_speech.proto
5656
start = time.time()
57-
response = service.SyncRecognize(cloud_speech_pb2.SyncRecognizeRequest(
57+
response = service.Recognize(cloud_speech_pb2.RecognizeRequest(
5858
config=cloud_speech_pb2.RecognitionConfig(
5959
# There are a bunch of config options you can specify. See
6060
# https://goo.gl/KPZn97 for the full list.
6161
encoding=encoding, # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
62-
sample_rate=sample_rate, # the rate in hertz
62+
sample_rate_hertz=sample_rate, # the rate in hertz
6363
# See https://g.co/cloud/speech/docs/languages for a list of
6464
# supported languages.
6565
language_code=language_code, # a BCP-47 language tag
@@ -86,7 +86,7 @@ def _gcs_uri(text):
8686

8787

8888
PROTO_URL = ('https://github.com/googleapis/googleapis/blob/master/'
89-
'google/cloud/speech/v1beta1/cloud_speech.proto')
89+
'google/cloud/speech/v1/cloud_speech.proto')
9090
if __name__ == '__main__':
9191
parser = argparse.ArgumentParser(
9292
description=__doc__,

speech/grpc/transcribe_async.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import google.auth
2929
import google.auth.transport.grpc
3030
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
3232
from 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 57AE '.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()

speech/grpc/transcribe_streaming.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import google.auth
2727
import google.auth.transport.grpc
2828
import google.auth.transport.requests
29-< B41A div class="diff-text-inner">from google.cloud.proto.speech.v1beta1 import cloud_speech_pb2
29+
from google.cloud.proto.speech.v1 import cloud_speech_pb2
3030
from google.rpc import code_pb2
3131
import grpc
3232
import pyaudio
@@ -139,7 +139,7 @@ def request_stream(data_stream, rate, interim_results=True):
139139
# There are a bunch of config options you can specify. See
140140
# https://goo.gl/KPZn97 for the full list.
141141
encoding='LINEAR16', # raw 16-bit signed LE samples
142-
sample_rate=rate, # the rate in hertz
142+
sample_rate_hertz=rate, # the rate in hertz
143143
# See http://g.co/cloud/speech/docs/languages
144144
# for a list of supported languages.
145145
language_code='ja-JP', # a BCP-47 language tag
@@ -207,7 +207,8 @@ def listen_print_loop(recognize_stream):
207207

208208
def main():
209209
service = cloud_speech_pb2.SpeechStub(
210-
make_channel('speech.googleapis.com', 443))
210+
make_channel('jerjou-dev-speech.sandbox.googleapis.com', 443))
211+
#make_channel('speech.googleapis.com', 443))
211212

212213
# For streaming audio from the microphone, there are three threads.
213214
# First, a thread that collects audio data as it comes in

0 commit comments

Comments
 (0)
0