noopkat / ms-bing-speech-service

NodeJS service wrapper for Microsoft Speech API and Custom Speech Service
MIT License
82 stars 17 forks source link

Error Handling #34

Closed hs7772667 closed 5 years ago

hs7772667 commented 5 years ago

Hi noopkat,

I get the below error quite often, I believe it is because of cris endpoint was unable to connect, The problem is I run a loop of audios, and this error seem to be coming in between and terminate the whole service.

Error: could not send: connection to service not open
    at BingSpeechService._sendToSocketServer (/apps/cris/node_modules/ms-bing-speech-service/dist/BingSpeechServiceNode.js:84:53)
    at BingSpeechService.sendChunk (/apps/cris/node_modules/ms-bing-speech-service/dist/BingSpeechServiceNode.js:91:14)
    at emitOne (events.js:116:13)
    at IncomingMessage.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at IncomingMessage.Readable.push (_stream_readable.js:208:10)
    at HTTPParser.parserOnBody (_http_common.js:140:22)
    at TLSSocket.socketOnData (_http_client.js:440:20)
    at emitOne (events.js:116:13)

I tried adding a try catch block and also used catch with the promises, I would like to know how to catch this error, so that I can retry and skip if exceeds maximum retires.

Here is my current try catch block code:

try{
    const recognizer = new speechService(options);
    await recognizer.start().catch((err)=>{
        reject(err)
    });

    recognizer.on('recognition', (e) => {
        if (e.RecognitionStatus === 'Success'){
            finalString += e.DisplayText + " ";
        } 
    });

    recognizer.on('error', (error) => {
        reject(error)
    })

    recognizer.on('turn.end', async (e) => {
        await recognizer.stop();
        resolve(finalString.trim());
    });  
    await recognizer.sendStream(audio);
}catch(err){
    reject(err)
}            
noopkat commented 5 years ago

Hi @hs7772667,

Sorry for not getting back to you on this or solving the issue. I did investigate this but just didn't get time to complete it.

Since then, there's been a new official version of a NodeJS and browser supported SDK for the unified Microsoft Speech Services (formally Bing Speech Service). I'd recommend checking that out instead, if you still have need for a library such as this: https://github.com/Azure-Samples/cognitive-services-speech-sdk

Therefore I'll respectfully close this issue and will be deprecating / archive this repo 🙇‍♀ Thanks again for your contribution.