我正在使用node.js客户端库,特别是startRecognition方法,并获得我使用speech.operation的结果。但是,我得到以下结果而不是结果 - 查看包含一些编码字符串而不是JavaScript对象的“value”对象。
{ result: 'response',
name: '3939860839213416358',
metadata:
{ typeUrl: 'type.googleapis.com/google.cloud.speech.v1.LongRunningRecognizeMetadata',
value: 'CGQSCwiKx47IBRCg6pRuGgsIqM6OyAUQgO+vYQ==' },
done: true,
error: null,
response:
{ typeUrl: 'type.googleapis.com/google.cloud.speech.v1.LongRunningRecognizeResponse',
value: 'EoQaCtICCsoCVGhleSBzbWFsbCBsYXRlc3QgZW52aXJvbm1lbnQuIFdlIGhhdmUgYSBjb3Jwb3JhdGUgYnVzaW5lc3Mgc2VydmljZSBhbmQgdGhlcmVmb3Jl' } }
有人见过这个吗?这是一个错误吗?或者有没有办法将其解码为JavaScript对象?
以下是演示此问题的代码段:
var Speech = require('@google-cloud/speech')({
projectId: 'my project name',
keyFilename: '<key file name>.json'
});
var opName='';
var config = {
encoding: 'LINEAR16',
sampleRateHertz: 48000,
languageCode: 'en-US',
maxAlternatives: 10
};
asyncGoogleASR('gs://file-location',config);
function asyncGoogleASR(googleCloudURI,request) {
Speech.startRecognition(googleCloudURI, request,async_callback);
}
function async_callback(err, operation, apiResponse) {
if (err) {
console.log(err);
}
opName=operation.latestResponse.name;
operation
.on('error', function(err) {
console.log("error");
console.log(err);
})
.on('complete', function(results) {
console.log(results); // this works okay
var op = Speech.operation(opName);
op
.on('error', function(err) {
console.log("error");
console.log(err);
})
.on('complete', function(results) {
console.log(results); // this prints garbage
});
});
}