2
votes

When I trying to execute the code below, I get the following error:

(node:3784) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Voice recognition failed miserably: socket hang up

var fs = require('fs');
var bing = require('bingspeech-api-client');

var audioStream = fs.createReadStream('d:\\node.wav'); 
var subscriptionKey = 'xxxxxxxxxxxxxxxxx';

var client = new bing.BingSpeechClient(subscriptionKey);
client.recognizeStream(audioStream)
      .then(response => console.log(response.results[0].name));

Please help me.

4
Hi Adhit, do you have any update?Gary Liu
I completed the module with ibm watson. Today i'm gng to look into these things i ill let u knw asap.Lokesh Avichetty
still same error GaryLokesh Avichetty

4 Answers

1
votes

I tried with your code snippet and the example audio file in the repository at https://github.com/palmerabollo/bingspeech-api-client/tree/master/examples. It works fine on my side.

Dived into the source code, I found the error message is thrown by
throw new Error(`Voice recognition failed miserably: ${err.message}`);
at https://github.com/palmerabollo/bingspeech-api-client/blob/master/src/client.ts#L129

Usually it's an Internet issue, please double check your internet work, or you can try to ping url https://api.cognitive.microsoft.com/sts/v1.0/issueToken to check whether you have a problem connect to the API.

0
votes

Came across the issue while playing with the service and it was due to the timeout settings hardcoded in bingspeech-api-client in Line 110:

open_timeout: 5000,

Full code here.

You might want to try to set higher values based on your internet connection.

0
votes

if you are behind a proxy server, try setting the proxy in the node_modules\bingspeech-api-client\lib\client.js file using

https-proxy-agent

in option of all the http request, include issue token.

0
votes

The below code works for me

const { BingSpeechClient, VoiceRecognitionResponse } = require('bingspeech-api-client');
const fs = require('fs');
let audioStream = fs.createReadStream("audiowav.wav"); 

// Bing Speech Key (https://www.microsoft.com/cognitive-services/en-us/subscriptions)
let subscriptionKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';         
let client = new BingSpeechClient(subscriptionKey);

          client.recognizeStream(audioStream).then(function(response)
          {
            console.log("response is ",response);
            console.log("-------------------------------------------------");
            console.log("response is ",response.results[0]);
          }).catch(function(error)
          {
            console.log("error occured is ",error);
          });

I think you need to import both BingSpeechClient, VoiceRecognitionResponse from bingspeech-api-client. Here is the reference bingspeech-api-client