我已经在 Google Speech API 上苦苦挣扎了一段时间,希望得到一些建议。
这就是我想做的:
我总是收到一个空的结果对象。
当我按照此入门教程进行操作时,一切正常。
我究竟做错了什么?
任何提示/想法将非常感激。
const Speech = require('@google-cloud/speech');
const SpeechV1beta1 = require('@google-cloud/speech/src/v1beta1')
module.exports = {
syncRecognize: function(base64Encoding) {
const speech = Speech();
const speechV1beta1 = SpeechV1beta1();
const client = speechV1beta1.speechClient();
const body = {
"config": {
"encoding":"LINEAR16",
"sampleRate":16000,
"languageCode":"en-US"
},
"audio": {
"content": base64Encoding
}
}
return client.syncRecognize(body)
.then((results) => {
console.log('results', results)
return {transcription: results[0]};
}).catch(function(error) {
return {error: error};
});;
}
}
Run Code Online (Sandbox Code Playgroud)