类 google.cloud.speech.v1.LongRunningRecognizeMetadata 尚未添加到描述符池

Pau*_*ake 1 php grpc google-speech-api google-cloud-speech

尝试恢复 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');
Run Code Online (Sandbox Code Playgroud)

有可能做这样的事情吗?

小智 6

我花了很长时间才想出这样一个简单的修复方法,但是就这样吧。

在调用之前放置此行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)
}
Run Code Online (Sandbox Code Playgroud)

如果您调用resumeOperation()longRunningRecognize()方法返回的相同操作,则一切正常。如果您尝试在单独的请求中恢复,就像您和我所做的那样,我们会收到您上面提到的错误。

不同之处在于,该longRunningRecognize()方法创建了一个请求 ( LongRunningRecognizeRequest),该请求被执行而resumeOperation()非常简单,不需要组合请求参数来发送给 Google。

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


我希望这有帮助!