如何使用microsoft认知API对文本进行语音处理?

时间:2018-02-20 23:54:23

标签: node.js api speech-recognition speech-to-text microsoft-cognitive

我有这个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();

任何人都知道什么是错的?

由于

1 个答案:

答案 0 :(得分:0)

cognitive services REST API example page判断数据需要作为原始字节发送(即没有toString)。