I am trying to implement the Speech-to-Text API in this tutorial using Cloud Functions (python)
The one implemented here is an asynchronous, long running function. My aim is to have the Cloud Function download an audio from a site, write it to S3, then calls the Speech-to-Text APIs client function on that S3 location of the audio to return a transcibed text. Here is the shortened code from the tutorial:
from google.cloud import speech_v1 as speech
client = speech.SpeechClient()
# storage_uri = 'gs://cloud-samples-data/speech/brooklyn_bridge.raw'
# some configuration
audio = {"uri": storage_uri}
operation = client.long_running_recognize(config, audio)
However, in cases where the audio is too long, it won't fit even the maximum timeout in the Cloud Function and I get timeout in logs. The client.long_running_recognize
was probably finished by Speech-to-Text API but the Cloud Function can't wait for it. What should I do in this case? Is using the asyncio
library in Python a good solution?