我有此node.js代码将wav
文件上传到语音到文本。但它行不通。
我回到了这个
{"RecognitionStatus":"InitialSilenceTimeout","Offset":58100000,"Duration":0}
代码
var data = fse.readFileSync("assets/batman.wav");
data = data.toString();
var options = {
host : 'speech.platform.bing.com',
//port : 443,
path : '/speech/recognition/dictation/cognitiveservices/v1?language=en-US&format=simple',
method : 'POST',
headers : {
'Ocp-Apim-Subscription-Key' : 'my key',
'Content-type' : 'audio/wav; codec=audio/pcm; samplerate=16000'
}
};
var req = https.request(options, function(res) {
var buffer = "";
res.on('data', function(chunk) {
buffer += chunk;
});
res.on('end', function() {
var str = buffer.toString();
console.log("A", buffer);
//var json = JSON.parse(buffer.toString());
//console.log(json);
});
});
req.on('error', function(e) {
console.log('problem with request:', e.message);
});
// add data
req.write(data);
req.end();
有人知道怎么了吗?
谢谢
从认知服务REST API示例页面判断数据需要以RAW字节发送数据(即没有ToString(。