2016-07-11 38 views
4

我正在嘗試將bing語音用於來自Node的文本服務。流式傳輸.wav文件時出現以下錯誤。高度讚賞任何幫助。microsoft-cognitive:在NodeJS中獲取ECONNRESET錯誤的Bing語音到文本服務

events.js:154 
     throw er; // Unhandled 'error' event 
    ^
Error: read ECONNRESET 
    at exports._errnoException (util.js:890:11) 
    at TLSWrap.onread (net.js:550:26) 

的Http選項如下:

 var post_option = { 
      hostname: 'speech.platform.bing.com', 
      path: '/recognize', 
      method: 'POST' 
     }; 
     post_option.headers = { 
      'Content-Type': 'audio/wav; samplerate=16000', //'audio/wav; codec=」audio/wav」; samplerate=16000; sourcerate=8000; trustsourcerate=false', 
      // 'keepAlive': true, 
      // 'Content-Length' : waveData.length, 
      'Authorization': 'Bearer ' + OxfordAccessToken.access_token, 
      // "User-Agent": "TTSNodeJS", 
      'X-Search-AppId': '______', 
      'X-Search-ClientID': '______' 
     }; 

     post_option.qs = { 
      'scenarios': 'ulm', 
      'appid': '--------', // This magic value is required 
      'locale': 'en-US', 
      'device.os': 'wp7', 
      'version': '3.0', 
      'format': 'json', 
      'requestid': '------', // can be anything 
      'instanceid': '------' // can be anything 
     }; 

的NodeJS來電SpeechToText服務

  res.on('end', function(){ 
       OxfordAccessToken = eval ('(' + _data + ')');  
       var voiceStream = fs.createReadStream("voiceresponse.wav",{encoding: "binary"}); 
       var https = require('https'); 
       var post_req = https.request(getPostOptionsForSTT(OxfordAccessToken), (res) =>{ 
        if(err){ 
         console.log("Error during STT"); 
        } 
        var sttResponse; 
        res.on('data', function(buffer){ 
         sttResponse += buffer; 
        }); 
        console.log("STT Results : "+sttResponse); 
       }); 
       voiceStream.pipe(post_req,{ end: false }); 
+0

它不工作,因爲查詢字符串沒有通過URL傳遞;通過將選項中的查詢字符串附加到路徑來修復。 post_option = { 主機名: 'speech.platform.bing.com', 路徑: '/識別<<附加查詢字符串>>?', 方法: 'POST' }; – raserside

回答

0

raserside回答了這個問題他/她自己,但這裏的代碼,省下一點時間:

const querystring = require('querystring'); // or query-string, or qs 

var params = { 
    'scenarios': 'ulm', 
    'appid': 'D4D52672-91D7-4C74-8AD8-42B1D98141A5', 
    'locale': 'en-US', 
    'device.os': 'wp7', 
    'version': '3.0', 
    'format': 'json', 
    'requestid': '------', // can be anything 
    'instanceid': '------' // can be anything 
}; 

var post_option = { 
    hostname: 'speech.platform.bing.com', 
    path: '/recognize?' + querystring.stringify(params), 
    method: 'POST' 
}; 

post_option.headers = { 
    'Content-Type': 'audio/wav; samplerate=16000', // For example 
    'Authorization': 'Bearer ' + OxfordAccessToken.access_token 
}; 
相關問題