This question is a followup to a previous question.
The snippet of code below almost works...it runs without error yet gives back a None
value for results_list
. This means it is accessing the file (I think) but just can't extract anything from it.
I have a file, sample.wav
, living publicly here: https://storage.googleapis.com/speech_proj_files/sample.wav
I am trying to access it by specifying source_uri='gs://speech_proj_files/sample.wav'
.
I don't understand why this isn't working. I don't think it's a permissions problem. My session is instantiated fine. The code chugs for a second, yet always comes up with no result. How can I debug this?? Any advice is much appreciated.
from google.cloud import speech
speech_client = speech.Client()
audio_sample = speech_client.sample(
content=None,
source_uri='gs://speech_proj_files/sample.wav',
encoding='LINEAR16',
sample_rate_hertz= 44100)
results_list = audio_sample.async_recognize(language_code='en-US')
Ah, that's my fault from the last question. That's the
async_recognize
command, not thesync_recognize
command.That library has three recognize commands.
sync_recognize
reads the whole file and returns the results. That's probably the one you want. Remove the letter "a" and try again.Here's an example Python program that does this: https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/cloud-client/transcribe.py
FYI, here's a summary of the other types:
async_recognize
starts a long-running, server-side operation to translate the whole file. You can make further calls to the server to see whether it's finished with theoperation.poll()
method and, when complete, can get the results viaoperation.results
.The third type is
streaming_recognize
, which sends you results continually as they are processed. This can be useful for long files where you want some results immediately, or if you're continuously uploading live audio.I finally got something to work:
Then something like