0

I am having issue when using Google asynchronous speech recognition long running API. The operation.done is not returning true.

I had modified the objective-C sample program https://github.com/GoogleCloudPlatform/ios-docs-samples/blob/master/speech/Objective-C/Speech-gRPC-Nonstreaming/Speech/SpeechRecognitionService.m to use longruning API.

Here are the modified snippet -

// prepare a single gRPC call to make the request
GRPCProtoCall *call = [client RPCToLongRunningRecognizeWithRequest:recognizeRequest
                                                            handler:
                        ^(Operation *operation, NSError *nserror) {
                            if (nserror) {
                                NSLog(@"ERROR: %@", nserror);
                                completion([nserror description]);
                            } else {
                                NSLog(@"RESPONSE name %@", operation.name);
                                while (!operation.done) {
                                    NSLog(@"operation done -  %d", operation.done);
                                    usleep(2000000);
                                }
                                    GPBAny *gpbAny = operation.response;
                                    NSLog(@"RESPONSE typeURL %@", gpbAny.typeURL);
                                    NSLog(@"RESPONSE deescription %@", gpbAny.value.description);
                                    GPBMessage *longRunningResponse = [gpbAny unpackMessageClass:LongRunningRecognizeResponse.class error:nil];
                                    NSLog(@"RESPONSE RECEIVED %@", longRunningResponse);
                                completion(longRunningResponse);
                            }
                        }];

It never come out from the while (!operation.done) loop. operation.name return the correct operation id. I was able to verify using gcloud ml speech operations describe 2104003022050949209 command that call went to google speech API and it return the transcribed message. But objective-C code does not return the operation.done true.

sam aga
  • 1
  • 1

1 Answers1

0

I don't think this is how gRPC or this API is supposed to work. For gRPC, after you receive the response (the Operation object), its value will no longer change, so while-looping on that will for sure cause infinite loop. LongRunningRecognize method is an asynchronous RPC method, so operation.done == false in this case simply mean that this operation is still running on the server side. You will need the methods in Operation service to further interact with the server for result of this request.

Muxi
  • 178
  • 7