[英]difference between api call and on postman
我正在使用Azure Speech Rest API。 我在邮递员上尝试了一个.wav文件,并成功返回了结果。 但是,当我从node.js代码调用api时。 即使我给出相同的音频文件,它也总是返回不支持的音频格式。 谁能告诉我他们有什么区别? 还是邮递员做了什么使它起作用?
以下是我如何通过node.js调用语音API。
'use strict';
const request = require('request');
const subscriptionKey = 'MYSUBSCRIPTIONKEY';
const uriBase = 'https://westus.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=en-US';
const options = {
uri: uriBase,
body: 'speech.wav',
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key' : subscriptionKey,
'Transfer-Encoding': 'chunked',
'Expect': '100-continue',
'Content-type':'audio/wav; codec=audio/pcm; samplerate=16000'
}
};
request.post(options, (error, response, body) => {
if (error) {
console.log('Error: ', error);
return;
}
let jsonResponse = JSON.stringify(JSON.parse(body), null, ' ');
console.log('JSON Response\n');
console.log(jsonResponse);
});
你可以试试这个
fs.readFile('/path/to/my/audiofile.wav', function (err, data) { if (err) throw err; var options = { host: 'https://westus.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=en-US', method: 'POST', headers: { 'Content-Type': 'audio/wav' } }; var req = http.request(options, function(res) { // Handle a successful response here... }); req.on('error', function(e) { // Handle an error response here... }); // Write the audio data in the request body. req.write(data); req.end(); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.