I am working through the provided code snippets from the Google Speech API, found here. The code should be enough to convert a .wav file into transcribed text.
The block of interest is here:
def transcribe_file(speech_file):
"""Transcribe the given audio file."""
from google.cloud import speech
speech_client = speech.Client()
with io.open(speech_file, 'rb') as audio_file:
content = audio_file.read()
audio_sample = speech_client.sample(
content=content,
source_uri=None,
encoding='LINEAR16',
sample_rate_hertz=16000)
alternatives = audio_sample.recognize('en-US')
for alternative in alternatives:
print('Transcript: {}'.format(alternative.transcript))
First, I think perhaps the code is old, and sample_rate_hertz=16000
had to be changed to sample_rate=16000
.
After that, I got an error for this line:
alternatives = audio_sample.recognize('en-US')
which read
AttributeError: 'Sample' object has no attribute 'recognize'
I am curious about how to rectify this. I can't seem to find any documentation on this method. Maybe it needs to be replaced too.