首页 > 解决方案 > 类 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');

有可能做这样的事情吗?

标签: phpgrpcgoogle-speech-apigoogle-cloud-speech

解决方案


我花了很长时间才想出这么简单的修复方法,但是你去吧。

在调用之前放置这一行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()方法创建了一个请求(LongRunningRecognizeRequestresumeOperation()

这里的区别在于,LongRunningRecognizeRequest调用的构造函数\GPBMetadata\Google\Cloud\Speech\V1\CloudSpeech::initOnce();设置了所需的语音描述符。


我希望这有帮助!


推荐阅读