Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5459ff7

Browse filesBrowse files
author
Jerjou Cheng
committed
Some updates for utility
1 parent 4c83e78 commit 5459ff7
Copy full SHA for 5459ff7

File tree

Expand file treeCollapse file tree

3 files changed

+14
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+14
-6
lines changed

‎speech/cloud-client/transcribe.py

Copy file name to clipboardExpand all lines: speech/cloud-client/transcribe.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
# [START import_libraries]
2626
import argparse
27+
import time
2728
import io
2829
# [END import_libraries]
2930

@@ -41,9 +42,11 @@ def transcribe_file(speech_file):
4142
encoding='LINEAR16',
4243
sample_rate_hertz=16000)
4344

44-
alternatives = audio_sample.recognize('en-US')
45+
start = time.time()
46+
alternatives = audio_sample.recognize('ja-JP')
47+
print('Runtime: %s' % (time.time() - start))
4548
for alternative in alternatives:
46-
print('Transcript: {}'.format(alternative.transcript))
49+
print(u'Transcript: {}'.format(alternative.transcript))
4750

4851

4952
def transcribe_gcs(gcs_uri):

‎speech/grpc/transcribe.py

Copy file name to clipboardExpand all lines: speech/grpc/transcribe.py
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"""
2121

2222
import argparse
23+
import time
2324

2425
import google.auth
2526
import google.auth.transport.grpc
@@ -44,13 +45,15 @@ def make_channel(host, port):
4445
credentials, http_request, target)
4546

4647

47-
def main(input_uri, encoding, sample_rate, language_code='en-US'):
48+
def main(input_uri, encoding, sample_rate, language_code='ja-JP'):
4849
service = cloud_speech_pb2.SpeechStub(
50+
#make_channel('jerjou-dev-speech.sandbox.googleapis.com', 443))
4951
make_channel('speech.googleapis.com', 443))
5052

5153
# The method and parameters can be inferred from the proto from which the
5254
# grpc client lib was generated. See:
5355
# https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1/cloud_speech.proto
56+
start = time.time()
5457
response = service.SyncRecognize(cloud_speech_pb2.SyncRecognizeRequest(
5558
config=cloud_speech_pb2.RecognitionConfig(
5659
# There are a bunch of config options you can specify. See
@@ -65,6 +68,7 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'):
6568
uri=input_uri,
6669
)
6770
), DEADLINE_SECS)
71+
print('Time: %s' % (time.time() - start))
6872

6973
# Print the recognition result alternatives and confidence scores.
7074
for result in response.results:
@@ -90,9 +94,10 @@ def _gcs_uri(text):
9094
parser.add_argument('input_uri', type=_gcs_uri)
9195
parser.add_argument(
9296
'--encoding', default='LINEAR16', choices=[
93-
'LINEAR16', 'FLAC', 'MULAW', 'AMR', 'AMR_WB'],
97+
'LINEAR16', 'FLAC', 'MULAW', 'AMR', 'AMR_WB', 'SPEEX_WITH_HEADER_BYTE'],
9498
help='How the audio file is encoded. See {}#L67'.format(PROTO_URL))
9599
parser.add_argument('--sample_rate', type=int, default=16000)
100+
parser.add_argument('--lang', default='en-US')
96101

97102
args = parser.parse_args()
98-
main(args.input_uri, args.encoding, args.sample_rate)
103+
main(args.input_uri, args.encoding, args.sample_rate, args.lang)

‎speech/grpc/transcribe_streaming.py

Copy file name to clipboardExpand all lines: speech/grpc/transcribe_streaming.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def request_stream(data_stream, rate, interim_results=True):
142142
sample_rate=rate, # the rate in hertz
143143
# See http://g.co/cloud/speech/docs/languages
144144
# for a list of supported languages.
145-
language_code='en-US', # a BCP-47 language tag
145+
language_code='ja-JP', # a BCP-47 language tag
146146
)
147147
streaming_config = cloud_speech_pb2.StreamingRecognitionConfig(
148148
interim_results=interim_results,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.