felixjunghans / google_speech

Flutter google spech
MIT License
69 stars 42 forks source link

longRunningRecognize - gRPC Error (code: 3, codeName: INVALID_ARGUMENT, message: Invalid resource field value in the request., details: [reason: RESOURCE_PROJECT_INVALID #44

Closed KyMHP closed 1 year ago

KyMHP commented 1 year ago

I'm trying to use longRunningRecognize to transcribe a file I've got in a bucket. The bucket is under the same project as Cloud speech. I can run recognize() with a local file but I am getting the below error when using longRunningRecognize().

gRPC Error (code: 3, codeName: INVALID_ARGUMENT, message: Invalid resource field value in the request., details: [reason: RESOURCE_PROJECT_INVALID domain: googleapis.com metadata: {service : speech.googleapis.com} metadata: {method : google.cloud.speech.v2.Speech.BatchRecognize} ], rawResponse: null, trailers: {google.rpc.errorinfo-bin

Below is my code. Is there something I've done wrong? I've checked the service account permissions for the bucket and it has the following: Cloud Speech-to-Text Service Agent, Storage Legacy Bucket Owner, Storage Legacy Object Owner, Storage Admin

final speechToText =SpeechToTextV2.viaServiceAccount(serviceAccount, projectId: 'matters-dictation');

final config = RecognitionConfigV2(
    autoDecodingConfig:AutoDetectDecodingConfig(),
    features: RecognitionFeatures(
        enableSpokenPunctuation: true,
        enableAutomaticPunctuation: true),
    model: RecognitionModelV2.long,
    languageCodes: ['en-GB']);

final response = await speechToText.longRunningRecognize(config, "gs://matters_dictation/welcome.wav");
felixjunghans commented 1 year ago

Hello @KyMHP, can you try if it works with SpeechToText instead of SpeechToTextV2?

KyMHP commented 1 year ago

Thanks for responding. I've just tried that and that has worked. Is V2 compatible at all? If not I'll just stick to V1.

And also, as this just returns a name, is there a simple way to get the transcript. I know this has been asked a couple times before but I couldn't see how to do it? Thanks

felixjunghans commented 1 year ago

Ok good. I haven't had time to test longRunningRequest with V2 yet. I guess there is still a bug. I will have a look at it soon and hope to fix the bug soon.

For your second question. Could you try this code?

    speechToText.longRunningRecognize(config, '...').then((Operation operation) {
      /// If the value is `false`, it means the operation is still in progress.
      /// If `true`, the operation is completed, and either `error` or `response` is
      /// available.
      if(operation.done) {
        final response = operation.response as LongRunningRecognizeResponse;
        setState(() {
          text = response.results
              .map((e) => e.alternatives.first.transcript)
              .join('\n');
        });
      }
    });
KyMHP commented 1 year ago

Sorry I've not been able to try it sooner. I've had a go with the above code just now. Operation.done is never triggered, it is always false, I've waited for a while to see if any response but still doesn't seem to be working. I've checked on the API dashboard and I can see the request with a status code 200 and no errors. It's a 2 min 30 file but I've still not got a response after 25 minutes.

felixjunghans commented 1 year ago

And operation.response is also always empty? Can you check if operation.response is not empty or if operation.error is not empty? Ignore operation.done.

KyMHP commented 1 year ago

operation.response and operation.error are both empty.

Freedisch commented 1 year ago

I'm experiencing the same issue here as well đŸ‘€. It seems that longrecognize is still not supported as no text is being generated.

felixjunghans commented 1 year ago

Hi @KyMHP and @Freedisch

Sorry for the late response. I have finally found time to take a closer look at this problem. I have found the error and fixed it.

I also added a new function called pollingLongRunningRecognize() with version 4.3.0 of google_speech. This now automatically takes over the polling of the operation and then returns the result as soon as the operation has been completed.

Please test it once and give feedback if it works now.