Created
December 3, 2018 12:48
-
-
Save code-R/f1465e166c47a676bcab110d29624197 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
from google.cloud import speech | |
from google.cloud.speech import enums | |
from google.cloud.speech import types | |
client = speech.SpeechClient() | |
speech_file = "gcloud_test.wav" | |
with open(speech_file, 'rb') as audio_file: | |
content = audio_file.read() | |
audio = types.RecognitionAudio(content=content) | |
config = types.RecognitionConfig( | |
encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, | |
sample_rate_hertz=16000, | |
language_code='hi-IN') | |
response = client.recognize(config, audio) | |
for result in response.results: | |
# The first alternative is the most likely one for this portion. | |
alternative = result.alternatives[0] | |
print(u'Transcript: {}'.format(alternative.transcript)) | |
print(u'Confidence: {}'.format(alternative.confidence)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment