-
-
Save daspecster/718d01c7896ee576743292549cfb6927 to your computer and use it in GitHub Desktop.
Speech examples results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from google.cloud import speech | |
# client = speech.Client() | |
# sample = client.sample(source_uri='gs://ferrous-arena-my-test-bucket/hello.wav', | |
# encoding=speech.Encoding.LINEAR16, | |
# sample_rate=16000) | |
# operation = sample.async_recognize(max_alternatives=2) | |
# retry_count = 100 | |
# while retry_count > 0 and not operation.complete: | |
# retry_count -= 1 | |
# time.sleep(10) | |
# operation.poll() # API call | |
# operation.complete | |
# | |
# for result in operation.results: | |
# for alternative in result.alternatives: | |
# print('=' * 20) | |
# print(alternative.transcript) | |
# print(alternative.confidence) | |
""" | |
Output: | |
==================== | |
hello thank you for using Google Cloud platform | |
0.927983105183 | |
==================== | |
thank you for using Google Cloud platform | |
None | |
""" | |
# client = speech.Client() | |
# sample = client.sample(source_uri='gs://ferrous-arena-my-test-bucket/hello.wav', | |
# encoding=speech.Encoding.LINEAR16, | |
# sample_rate=16000) | |
# results = sample.sync_recognize(language_code='en-GB', max_alternatives=2) | |
# for result in results: | |
# for alternative in result.alternatives: | |
# print('=' * 20) | |
# print('transcript: ' + alternative.transcript) | |
# print('confidence: ' + str(alternative.confidence)) | |
""" | |
Output: | |
==================== | |
transcript: hello thank you for using Google Cloud platform | |
confidence: 0.975160181522 | |
""" | |
# from google.cloud import speech | |
# client = speech.Client() | |
# sample = client.sample(source_uri='gs://ferrous-arena-my-test-bucket/hello.wav', | |
# encoding=speech.Encoding.LINEAR16, | |
# sample_rate=16000) | |
# results = sample.sync_recognize(max_alternatives=1, profanity_filter=True) | |
# for result in results: | |
# for alternative in result.alternatives: | |
# print('=' * 20) | |
# print('transcript: ' + alternative.transcript) | |
# print('confidence: ' + str(alternative.confidence)) | |
""" | |
Output: | |
==================== | |
transcript: hello thank you for using Google Cloud platform | |
confidence: 0.927982807159 | |
""" | |
# from google.cloud import speech | |
# client = speech.Client() | |
# sample = client.sample(source_uri='gs://ferrous-arena-my-test-bucket/hello.wav', | |
# encoding=speech.Encoding.LINEAR16, | |
# sample_rate=16000) | |
# hints = ['hi', 'good afternoon'] | |
# results = sample.sync_recognize(max_alternatives=2, speech_context=hints) | |
# for result in results: | |
# for alternative in result.alternatives: | |
# print('=' * 20) | |
# print('transcript: ' + alternative.transcript) | |
# print('confidence: ' + str(alternative.confidence)) | |
""" | |
Output: | |
==================== | |
transcript: hello thank you for using Google Cloud platform | |
confidence: 0.927982926369 | |
==================== | |
transcript: thank you for using Google Cloud platform | |
confidence: None | |
""" | |
# client = speech.Client() | |
# with open('./hello-working.wav', 'rb') as stream: | |
# sample = client.sample(stream=stream, | |
# encoding=speech.Encoding.LINEAR16, | |
# sample_rate=16000) | |
# results = sample.streaming_recognize() | |
# | |
# for result in results: | |
# for alternative in result.alternatives: | |
# print('=' * 20) | |
# print('transcript: ' + alternative.transcript) | |
# print('confidence: ' + str(alternative.confidence)) | |
""" | |
Output: | |
==================== | |
transcript: hello thank you for using Google Cloud platform | |
confidence: 0.927983105183 | |
""" | |
# client = speech.Client() | |
# with open('./pause_testing_mono.wav', 'rb') as stream: | |
# sample = client.sample(stream=stream, | |
# encoding=speech.Encoding.LINEAR16, | |
# sample_rate=16000) | |
# results = sample.streaming_recognize(single_utterance=True) | |
# | |
# for result in results: | |
# for alternative in result.alternatives: | |
# print('=' * 20) | |
# print('transcript: ' + alternative.transcript) | |
# print('confidence: ' + str(alternative.confidence)) | |
""" | |
Output: | |
==================== | |
transcript: testing a pause # Note: Full audio is "testing a pause.....1 2 3" | |
confidence: 0.933770477772 | |
""" | |
client = speech.Client() | |
with open('./pause_testing_mono.wav', 'rb') as stream: | |
sample = client.sample(stream=stream, | |
encoding=speech.Encoding.LINEAR16, | |
sample_rate=16000) | |
results = sample.streaming_recognize(interim_results=True) | |
for result in results: | |
for alternative in result.alternatives: | |
print('=' * 20) | |
print('transcript: ' + alternative.transcript) | |
print('confidence: ' + str(alternative.confidence)) | |
print('is_final:' + str(result.is_final)) | |
""" | |
Output: | |
==================== | |
transcript: test | |
confidence: None | |
is_final:False | |
==================== | |
transcript: test a | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing a | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing a paw | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing | |
confidence: None | |
is_final:False | |
==================== | |
transcript: a paw | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing | |
confidence: None | |
is_final:False | |
==================== | |
transcript: a pause | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing a | |
confidence: None | |
is_final:False | |
==================== | |
transcript: pause | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing a pause | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing a pause | |
confidence: None | |
is_final:False | |
==================== | |
transcript: one | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing a pause one | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing a pause one | |
confidence: None | |
is_final:False | |
==================== | |
transcript: to | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing a pause one | |
confidence: None | |
is_final:False | |
==================== | |
transcript: two three | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing a pause one two three | |
confidence: None | |
is_final:False | |
==================== | |
transcript: testing a pause one two three | |
confidence: 0.778945684433 | |
is_final:True | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment