php - 类 google.cloud.speech.v1.LongRunningRecognizeMetadata 尚未添加到描述符池
问题描述
尝试恢复 Speech to Text 操作时出现此错误。
Google\Protobuf\Internal\GPBDecodeException: Error occurred during parsing: Class google.cloud.speech.v1.LongRunningRecognizeMetadata hasn't been added to descriptor pool in Google\Protobuf\Internal\Message->parseFromJsonStream()
我正在做的是开始长时间运行并存储名称。稍后,我将创建一个单独的页面,其中包含基于我之前存储的名称的操作状态。
这就是我用来尝试获取操作状态的方法
$speechClient = new SpeechClient();
$operationResponse = $speechClient->resumeOperation($record->operation_name, 'longRunningRecognize');
有可能做这样的事情吗?
解决方案
我花了很长时间才想出这么简单的修复方法,但是你去吧。
在调用之前放置这一行resumeOperation
:
\GPBMetadata\Google\Cloud\Speech\V1\CloudSpeech::initOnce();
.
我认为这是 SDK 中的一个错误,但考虑到他们的文档说客户端库是 Alpha 版,这是有道理的。
更长的解释(因为我花了这么长时间,而且我知道如果我再次遇到这个问题,我会在未来找到我的答案):
该SpeechGapicClient::longRunningRecognize()
方法上方的 DocBlocks 显示了阻止轮询的替代方法$operation->pollUntilComplete()
// start the operation, keep the operation name, and resume later
$operationResponse = $speechClient->longRunningRecognize($config, $audio);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $speechClient->resumeOperation($operationName, 'longRunningRecognize');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
resumeOperation()
如果您调用该方法返回的相同操作,一切都会很好longRunningRecognize()
。如果您像您和我一样尝试在单独的请求中恢复,我们会收到您上面提到的错误。
不同之处在于,该longRunningRecognize()
方法创建了一个请求(LongRunningRecognizeRequest
resumeOperation()
这里的区别在于,LongRunningRecognizeRequest
调用的构造函数\GPBMetadata\Google\Cloud\Speech\V1\CloudSpeech::initOnce();
设置了所需的语音描述符。
我希望这有帮助!
推荐阅读
- javascript - react-leaflet v3 缩放监听器
- python - 计算模型中的两个损失并反向传播两次
- hibernate - 将本机查询转换器列休眠到 dto 中的复杂属性
- c++ - 在基类中声明的 C++ 结构在子类中不可访问
- angular - 使用 kendo UI 和 Angular 显示上传文件的日期
- ios - 如何隐藏/删除“来自消息”键盘建议 - Flutter IOS
- sql - Oracle SQL Developer 中如何检查另一列的值是否最高以确定多次出现的最新记录?
- c++ - 我无法让它显示更新后的温度
- excel - Excel 中的自定义标记取决于数据点值
- sql - SQL QUERY:如何在同一个查询中的多个位置制作和使用查询结果