Created
July 21, 2020 15:18
-
-
Save armindocachada/0685821df39759868a905ad2a3b47f46 to your computer and use it in GitHub Desktop.
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
def speech_to_text(bucket_name, audio_blob_name): | |
client = speech_v1p1beta1.SpeechClient() | |
# storage_uri = 'gs://cloud-samples-data/speech/brooklyn_bridge.mp3' | |
storage_uri = 'gs://' + bucket_name + '/' + audio_blob_name | |
# The language of the supplied audio | |
language_code = "en-GB" | |
# Sample rate in Hertz of the audio data sent | |
sample_rate_hertz = 44100 | |
encoding = enums.RecognitionConfig.AudioEncoding.MP3 | |
config = { | |
"language_code": language_code, | |
"sample_rate_hertz": sample_rate_hertz, | |
"encoding": encoding, | |
"enable_word_time_offsets": True | |
} | |
audio = {"uri": storage_uri} | |
response = client.recognize(config, audio) | |
for result in response.results: | |
# First alternative is the most probable result | |
alternative = result.alternatives[0] | |
for word in alternative.words: | |
print("Start Time: {}".format(word.start_time)) | |
print("End Time: {}".format(word.end_time)) | |
print(u"Transcript: {}".format(alternative.transcript)) | |
return alternative.transcript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment