运行 Cloud Functions 中的一个异步函数
Running an asynchronous function within a Cloud Function
我正在尝试使用 Cloud Functions (python)
在本教程中实现 Speech-to-Text API
这里实现的是一个异步的长 运行 函数。我的目标是让 Cloud Function 从站点下载音频,将其写入 S3,然后在音频的 S3 位置调用 Speech-to-Text APIs 客户端函数到 return a转录的文本。这是教程中的缩短代码:
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)
但是,如果音频太长,它甚至无法适应 Cloud Function 中的最大超时,我会在日志中遇到超时。 client.long_running_recognize
可能已由 Speech-to-Text API 完成,但 Cloud Function 等不及了。在这种情况下我该怎么办?在 Python 中使用 asyncio
库是一个好的解决方案吗?
Cloud Functions 目前的最大超时时间为 9 minutes。
您可以使用可以执行更长操作的其他 GCP 服务。例如,App Engine Flexible 有一个 response time limit of 60 minutes or App Engine Standard with basic scaling which has a response time limit of 24 hours
我正在尝试使用 Cloud Functions (python)
在本教程中实现 Speech-to-Text API这里实现的是一个异步的长 运行 函数。我的目标是让 Cloud Function 从站点下载音频,将其写入 S3,然后在音频的 S3 位置调用 Speech-to-Text APIs 客户端函数到 return a转录的文本。这是教程中的缩短代码:
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)
但是,如果音频太长,它甚至无法适应 Cloud Function 中的最大超时,我会在日志中遇到超时。 client.long_running_recognize
可能已由 Speech-to-Text API 完成,但 Cloud Function 等不及了。在这种情况下我该怎么办?在 Python 中使用 asyncio
库是一个好的解决方案吗?
Cloud Functions 目前的最大超时时间为 9 minutes。
您可以使用可以执行更长操作的其他 GCP 服务。例如,App Engine Flexible 有一个 response time limit of 60 minutes or App Engine Standard with basic scaling which has a response time limit of 24 hours