googleapis / googleapis/google-cloud-node
Speech v2 is not drop-in replacement for v1, and it is undocumented
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 712
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 99
Description
#### Environment details
- OS: Windows 10
- Node.js version: 18.13
- npm version: 8.19.3
- google-cloud-node version: 5.3.0
#### Steps to reproduce
Running the following program (either with or without `doStream`), fails with errors.
```js
const speech = require('@google-cloud/speech');
const fs = require('fs');
var protos = speech.protos.google.cloud.speech;
const client = new speech.v2.SpeechClient({
credentials: {
client_email: 'MY_MAIL',
private_key: 'MY_KEY',
},
projectId: 'MY_PROJECT',
});
const doStream = true;
(async () => {
try {
if (doStream) {
const file = fs.createReadStream('test.wav');
const recognizer = await client.streamingRecognize({
config: {
encoding: protos.v1.RecognitionConfig.AudioEncoding.MULAW,
languageCode: 'en-US',
sampleRateHertz: 16000,
model: 'phone_call'
},
interimResults: true
});
recognizer.on('error', console.error);
recognizer.on('data', (data) => console.log('data', data.results[0].alternatives[0].transcript));
file.pipe(recognizer);
} else {
const [response] = await client.recognize({
config: {
encoding: protos.v1.RecognitionConfig.AudioEncoding.MULAW,
languageCode: 'en-US',
sampleRateHertz: 16000,
model: 'phone_call'
},
audio: { content: fs.readFileSync('test.wav') },
interimResults: true
});
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join('\n');
console.log(`Transcription: ${transcription}`);
}
}
catch (err) {
console.error(err);
}
})();
```
Error:
```
Error: 3 INVALID_ARGUMENT: Invalid resource field value in the request.
at callErrorFromStatus (F:\Projects\jstest\node_modules\@grpc\grpc-js\build\src\call.js:31:19)
...
for call at
at ServiceClientImpl.makeUnaryRequest (F:\Projects\jstest\node_modules\@grpc\grpc-js\build\src\client.js:160:34)
...
reason: 'RESOURCE_PROJECT_INVALID',
```
Changing v2 to v1 works as expected.
I've noticed that there's a helper function in helpers.js, which translates the request. I'm not sure if/how it should be adapted for v2.
I couldn't find any documentation or a running example how to correctly use v2.
Contributor guide
Assessment
This issue has not been assessed yet.