RESOURCE_PROJECT_INVALID error: GCP Speech To Text v2 NodeJS

Hi!

I am trying to use Cloud Speech-To-Text v2 in a NodeJS application. My code works well with v1:

import { v1 } from '@google-cloud/speech';
const { SpeechClient } = v1;
let speechClient: v1.SpeechClient | undefined;

speechClient = new SpeechClient(); // GOOGLE_APPLICATION_CREDENTIALS is set to ./google-credentials.json, which exists, is valid and has the Roles 'Cloud Speech CLient', Cloud Speech-to-Text Service Agent' and 'Cloud Translation API User'

const googleCloudSpeechConfig = {
config: {
encoding: "LINEAR16",
sampleRateHertz: 16000,
languageCode: "EN-US"
    },
    interimResults: true,
};
recognizeStream = speechClient
    .streamingRecognize(config)
    .on('error', (err) => { ... })
    .on('data', async (data) => { ... });

However, when I switch to v2 using

import { v2 } from '@google-cloud/speech';
const { SpeechClient } = v2;
let speechClient: v2.SpeechClient | undefined;

I get the error

Error: 3 INVALID_ARGUMENT: Invalid resource field value in the request.
at callErrorFromStatus (/Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/@grpc/grpc-js/src/call.ts:82:17)
at Object.onReceiveStatus (/Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/@grpc/grpc-js/src/client.ts:705:51)
at Object.onReceiveStatus (/Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/@grpc/grpc-js/src/client-interceptors.ts:419:48)
at /Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/@grpc/grpc-js/src/resolving-call.ts:132:24
at processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
at ServiceClientImpl.makeBidiStreamRequest (/Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/@grpc/grpc-js/src/client.ts:689:42)
at ServiceClientImpl.<anonymous> (/Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/@grpc/grpc-js/src/make-client.ts:189:15)
at /Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/@google-cloud/speech/build/src/v2/speech_client.js:317:29
at /Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/google-gax/build/src/streamingCalls/streamingApiCaller.js:46:28
at /Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
at StreamProxy.setStream (/Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/google-gax/build/src/streamingCalls/streaming.js:144:24)
at StreamingApiCaller.call (/Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/google-gax/build/src/streamingCalls/streamingApiCaller.js:54:16)
at /Users/dominik/Documents/Git Projects/event_subtitles/server/node_modules/google-gax/build/src/createApiCall.js:84:30
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 3,
details: 'Invalid resource field value in the request.',
metadata: Metadata {
internalRepr: Map(2) {
'google.rpc.errorinfo-bin' => [Array],
'grpc-status-details-bin' => [Array]
},
options: {}
},
statusDetails: [
ErrorInfo {
metadata: [Object],
reason: 'RESOURCE_PROJECT_INVALID',
domain: 'googleapis.com'
}
],
reason: 'RESOURCE_PROJECT_INVALID',
domain: 'googleapis.com',
errorInfoMetadata: {
service: 'speech.googleapis.com',
method: 'google.cloud.speech.v2.Speech.StreamingRecognize'
}
}

How come?

I also noticed that the types seem weird. v2.SpeechClient.streamingRecognize expects the type

streamingConfig?: google.cloud.speech.v1.IStreamingRecognitionConfig | google.cloud.speech.v1p1beta1.IStreamingRecognitionConfig | undefined

which seems very strange.

Also, the documentation at

https://cloud.google.com/speech-to-text/v2/docs/streaming-recognize

has a Python example, but no NodeJS example.

What am I doing wrong?

6 2 776
2 REPLIES 2

Got the same issue, any update?

Im saving the same problem, Im calling it from a google function onCall