如何序列化和反序列化 `longRunningRecognize` 操作以在稍后获得其结果?

问题描述

我正在使用 firebase 云函数通过 the example code for longRunningRecognize 转录用户上传的音频文件:

// Detects speech in the audio file. This creates a recognition job that you
// can wait for now,or get its result later.
const [operation] = await client.longRunningRecognize(request);

// Get a Promise representation of the final result of the job
const [response] = await operation.promise();

此代码适用于可以比 9-minute firebase cloud function maximum execution limit 更快地转录的短音频文件,但是 1) 我的许多 ~ 小时长的用户上传的文件不能那么快地转录,并且 2) 它拥有一个云函数 getting billed for each tenth of a second it's running 只是坐在那里等待 API 响应似乎很浪费。

我认为这里明显的解决方法是让 Google's Speech-to-Text API 支持网络钩子。

在此之前,我如何序列化和反序列化 SpeechClient operation 以便稍后从 scheduled function 获得此转录作业的结果?

具体来说,我正在寻找类似于本示例中的组合 SERIALIZEDESERIALIZE 函数的东西:

// start speech recognition job:
const [operation] = await client.longRunningRecognize(request);
const serializedOperation = operation.SERIALIZE();
db.doc("jobs/job1").set(serializedOperation);

// get the result later in a scheduled function:
const snap = await db.doc("jobs/job1").get();
const serializedOperation = snap.data();
const operation = DESERIALIZE(serializedOperation);
const [response] = await operation.promise();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)