Reputation: 7801
I'm getting this error when trying to resume a Speech to Text operation.
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()
What I'm doing is starting the longrunning operation and storing the name. Later I'm creating a separate page with the status of the operation based on the name I stored previously.
This is what I'm using to try and get the operation status
$speechClient = new SpeechClient();
$operationResponse = $speechClient->resumeOperation($record->operation_name, 'longRunningRecognize');
Is it possible to do something like this?
Upvotes: 1
Views: 921
Reputation: 3289
I had a very similar issue, trying to get information about an operation (getOperation
):
Google\Protobuf\Internal\GPBDecodeException Error occurred during parsing: Class google.cloud.speech.v1p1beta1.LongRunningRecognizeMetadata hasn't been added to descriptor pool
As @stevenwadejr already answered correctly, this can be solved by calling initOnce() before the call.
<?php
use Google\Cloud\Speech\V1p1beta1\SpeechClient;
use GPBMetadata\Google\Cloud\Speech\V1P1Beta1\CloudSpeech;
$client = new SpeechClient();
// This line is required. It adds LongRunningRecognizeMetadata and others to the pool of recognized classes
CloudSpeech::initOnce();
// Now, I can get the operation without raising an exception
$operation = $client->getOperationsClient()->getOperation('1234567890123456789');
You can check file \vendor\google\protobuf\src\Google\Protobuf\Internal\AnyBase.php function unpack()
. Without the initOnce command the pool variable did not have the fully_qualifed_name (google.cloud.speech.v1p1beta1.LongRunningRecognizeMetadata) in the $proto->proto_to_class
array.
Upvotes: 0
Reputation: 81
This took me way too long to figure out for such a simple fix, but here you go.
Put this line before calling resumeOperation
:
\GPBMetadata\Google\Cloud\Speech\V1\CloudSpeech::initOnce();
.
I think this is a bug within the SDK, but considering their docs say the client libraries are in Alpha, it makes sense.
A longer explanation (since it took me so darn long, and I know I'll find my SO answer in the future if I run into this problem again):
The DocBlocks above the SpeechGapicClient::longRunningRecognize()
method show an alternative to blocking polling with $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)
}
Everything works great if you call resumeOperation()
on the same operation returned by the longRunningRecognize()
method. If you try to resume in a separate request, as you and I did, we get the error you mentioned above.
The difference is, the longRunningRecognize()
method creates a request (LongRunningRecognizeRequest
) which is executed whereas resumeOperation()
is pretty straight forward and doesn't need to combine request parameters for sending to Google.
The difference here is, the constructor of the LongRunningRecognizeRequest
calls \GPBMetadata\Google\Cloud\Speech\V1\CloudSpeech::initOnce();
which sets up the needed speech descriptors.
I hope this helps!
Upvotes: 6