Skip to content

Instantly share code, notes, and snippets.

@code-R
Created December 3, 2018 12:48
Show Gist options
  • Save code-R/f1465e166c47a676bcab110d29624197 to your computer and use it in GitHub Desktop.
Save code-R/f1465e166c47a676bcab110d29624197 to your computer and use it in GitHub Desktop.
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