googleapis / googleapis/google-cloud-node

Speech v2 is not drop-in replacement for v1, and it is undocumented

Aperta
#3,952 8 commenti 2 reazioni 1 assegnatario Assegnata a @dizcology Vedi su GitHub
priority: p2 type: bug
Lingua principale
TypeScript
Stelle
3.2k
Fork
712
Merge medio
2g 9h
PR unite (30g)
104

Descrizione

#### 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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.