cognitive-services-speech-sdk: Unable to contact server. StatusCode: 1006, undefined Reason

I just copied and pasted the node js code and replace the filename, key, and region but it throws the following error:

E:\Upwork\stt\stt-new\controllers>node microsoft.js Now recognizing from: m1561477818826.wav SpeechRecognitionResult { privResultId: ‘1530E7597EE7496E91747B86931F79F9’, privReason: 1, privText: undefined, privDuration: undefined, privOffset: undefined, privErrorDetails: 'Unable to contact server. StatusCode: 1006, undefined Reason: ', privJson: undefined, privProperties: PropertyCollection { privKeys: [ ‘CancellationErrorCode’ ], privValues: [ ‘ConnectionFailure’ ] } } Trace: err - Runtime error: Unable to contact server. StatusCode: 1006, undefined Reason: at E:\Upwork\stt\stt-new\controllers\microsoft.js:56:13 at E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\sdk\SpeechRecognizer.js:157:21 at E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\sdk\Recognizer.js:129:17 at Sink.executeErrorCallback (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:351:21) at Sink.reject (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:318:23) at Deferred.reject (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:281:28) at E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:193:46 at Sink.executeErrorCallback (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:351:21) at Sink.reject (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:318:23) at Deferred.reject (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:281:28) E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:354 throw new Error(“‘Unhandled callback error: " + e + ". InnerError: " + error + "’”); ^

Error: ‘Unhandled callback error: Error: ‘Cannot reject a completed promise’. InnerError: ‘Unhandled callback error: Error: ‘Cannot reject a completed promise’’’ at Sink.executeErrorCallback (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:354:27) at Sink.executeSuccessCallback (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:345:23) at Sink.resolve (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:306:23) at Deferred.resolve (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:277:28) at WebSocket._this.privWebsocketClient.onclose (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common.browser\WebsocketMessageAdapter.js:107:59) at WebSocket.onClose (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\node_modules\ws\lib\event-target.js:124:16) at WebSocket.emit (events.js:182:13) at WebSocket.emitClose (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\node_modules\ws\lib\websocket.js:182:12) at ClientRequest.req.on (E:\Upwork\stt\stt-new\node_modules\microsoft-cognitiveservices-speech-sdk\node_modules\ws\lib\websocket.js:569:15) at ClientRequest.emit (events.js:182:13)

Here is my code

var sdk = require("microsoft-cognitiveservices-speech-sdk");
var fs = require("fs");

// replace with your own subscription key,
// service region (e.g., "westus"), and
// the name of the file you want to run
// through the speech recognizer.
var subscriptionKey = "*****************";
var serviceRegion = "westus"; // e.g., "westus"
var filename = "m1561477818826.wav"; // 16000 Hz, Mono

// create the push stream we need for the speech sdk.
var pushStream = sdk.AudioInputStream.createPushStream();

// open the file and push it to the push stream.
fs.createReadStream(filename).on('data', function(arrayBuffer) {
}).on('end', function() {

// we are done with the setup
console.log("Now recognizing from: " + filename);

// now create the audio-config pointing to our stream and
// the speech config specifying the language.
var audioConfig = sdk.AudioConfig.fromStreamInput(pushStream);
var speechConfig = sdk.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);

// setting the recognition language to English.
speechConfig.speechRecognitionLanguage = "en-US";

// create the speech recognizer.
var recognizer = new sdk.SpeechRecognizer(speechConfig, audioConfig);

// start the recognizer and wait for a result.
  function (result) {

    recognizer = undefined;
  function (err) {
    console.trace("err - " + err);

    recognizer = undefined;

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (8 by maintainers)

Most upvoted comments

Has anybody come to a resolution on this? I am having the same issue. My subscription key and region are correct but still get the “Unable to contact server” message.


@therowf - please edit the message remove your subscription key!

I’m experiencing the same issue, but not on every call to speech recognition service.

It seems that this error message is triggered 120 seconds after trying to start a session with the recognize stram, as it would be a timeout from the server or the client.

@therowf Did you manage to solve this problem, or at least to understand the root cause?

I’m still getting this error “Unable to contact server. StatusCode: 1006, undefined Reason: undefined”

Have put the correct subscription key and region. I’m using the quickstart browser sample app “quickstart/javascript/browser/from-microphone/index.html”

Why is the reason undefined? Screenshot 2021-05-27 at 1 18 05 PM

My issue was resolved by waiting a second between requests 🤔 I think we are hitting the 20 request/minute limit in the free plan

I was using the Starter key. Creating a LUIS resource and assigning my app to the resource solved the issue. Thank you very much for the assist!

Please don’t post subscription keys. I would suggest to edit the message to remove the key and regenerate your key from the speech resource in the Azure portal.