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) {
pushStream.write(arrayBuffer.buffer);
}).on('end', function() {
pushStream.close();
});
// 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.
recognizer.recognizeOnceAsync(
function (result) {
console.log(result);
recognizer.close();
recognizer = undefined;
},
function (err) {
console.trace("err - " + err);
recognizer.close();
recognizer = undefined;
});
@therowf - please edit the message remove your subscription key!
@wolfma61 It was only to see if the subscription key was correct. There I have got 2 keys. Like key1 and key2. Could you let me know which one should use? Although it is a test account and I will delete it after work.
Is a bug, because in the error detail: 'Unable to contact server. StatusCode: 1006, undefined Reason: ', instead of 'undefined' should be the requested URL.
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?
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.
Thanks.
Can you turn the logging up and run the sample again?
To turn the logging up, inject this code into the beginning of the JS file node will run:
var evtExport = require("./node_modules/microsoft-cognitiveservices-speech-sdk/distrib/lib/src/common/Exports");
var browserExport = require("./node_modules/microsoft-cognitiveservices-speech-sdk/distrib/lib/src/common.browser/Exports");
evtExport.Events.instance.attachListener(new browserExport.ConsoleLoggingListener(evtExport.EventType.Debug));
This will send more messages to the console. Please redact your key from the connection message with the URL in it.
undefined | undefined | privName: RecognitionTriggeredEvent | privEventId: 0A493DE014A94C09800867C8874F6469 | privEventTime: 2019-10-02T16:47:35.402Z | privEventType: 1 | privMetadata: {} | privRequestId: F9F6E95C155D4956A1D675A35A1CD140 | privSessionId:
undefined | undefined | privName: ConnectingToServiceEvent | privEventId: 53957C8900B342F69FEC5E5E371ABCB6 | privEventTime: 2019-10-02T16:47:35.403Z | privEventType: 1 | privMetadata: {} | privRequestId: F9F6E95C155D4956A1D675A35A1CD140 | privSessionId: 6540DDECCADA4178BCB7B7C3624827EF | privAuthFetchEventid: CFAC67AA34D44C4B81AA19C8520B18F3
undefined | undefined | privName: ConnectionStartEvent | privEventId: 5185C31F36ED4F0483D69FAC1A4912D5 | privEventTime: 2019-10-02T16:47:35.519Z | privEventType: 1 | privMetadata: {} | privConnectionId: 6540DDECCADA4178BCB7B7C3624827EF | privUri: wss://speech.platform.bing.com/speech/uswest/recognition/interactive/cognitiveservices/v1?format=simple&language=en-US&Ocp-Apim-Subscription-Key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&X-ConnectionId=6540DDECCADA4178BCB7B7C3624827EF | privHeaders:
undefined | undefined | privName: AudioStreamNodeAttachingEvent | privEventId: FF3B6798C67144F8B6B55205963A9CBB | privEventTime: 2019-10-02T16:47:35.521Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: 9F2483B4D6F544E48BE8394449A36238 | privAudioNodeId: 5A725224F7574D4DAAE357B0F7117283
undefined | undefined | privName: AudioSourceInitializingEvent | privEventId: BD5FC7425F3745CBB4F21E23BC856EA5 | privEventTime: 2019-10-02T16:47:35.522Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: 9F2483B4D6F544E48BE8394449A36238
undefined | undefined | privName: AudioSourceReadyEvent | privEventId: 54E220088BB6425B9F9C52EF5CBD778D | privEventTime: 2019-10-02T16:47:35.523Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: 9F2483B4D6F544E48BE8394449A36238
undefined | undefined | privName: AudioStreamNodeAttachedEvent | privEventId: 32F57226F28E42DC81A79B578A516014 | privEventTime: 2019-10-02T16:47:35.525Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: 9F2483B4D6F544E48BE8394449A36238 | privAudioNodeId: 5A725224F7574D4DAAE357B0F7117283
undefined | undefined | privName: ListeningStartedEvent | privEventId: 8C5692A1C82441649BA376813EB43135 | privEventTime: 2019-10-02T16:47:35.526Z | privEventType: 1 | privMetadata: {} | privRequestId: F9F6E95C155D4956A1D675A35A1CD140 | privSessionId: 6540DDECCADA4178BCB7B7C3624827EF | privAudioSourceId: 9F2483B4D6F544E48BE8394449A36238 | privAudioNodeId: 5A725224F7574D4DAAE357B0F7117283
closing pushStream ...
undefined | undefined | privName: AudioStreamNodeDetachedEvent | privEventId: F076CCDD921644A1BDD4FFB970378442 | privEventTime: 2019-10-02T16:47:50.061Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: 9F2483B4D6F544E48BE8394449A36238 | privAudioNodeId: 5A725224F7574D4DAAE357B0F7117283
undefined | undefined | privName: ConnectingToServiceEvent | privEventId: 5D8F9DC4CF3A475A80E96D59BC77DD47 | privEventTime: 2019-10-02T16:47:50.061Z | privEventType: 1 | privMetadata: {} | privRequestId: F9F6E95C155D4956A1D675A35A1CD140 | privSessionId: 71D29D1AF1B8430EB425FA466584113D | privAuthFetchEventid: EEE3372AF7A148DAA17FE10D5BCAE769
undefined | undefined | privName: ConnectionStartEvent | privEventId: 319F2DCA2A4640219F2B17AC1A57B3F2 | privEventTime: 2019-10-02T16:47:50.063Z | privEventType: 1 | privMetadata: {} | privConnectionId: 71D29D1AF1B8430EB425FA466584113D | privUri: wss://speech.platform.bing.com/speech/uswest/recognition/interactive/cognitiveservices/v1?format=simple&language=en-US&Ocp-Apim-Subscription-Key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&X-ConnectionId=71D29D1AF1B8430EB425FA466584113D | privHeaders:
(cancel) Reason: Error: Unable to contact server. StatusCode: 1006, undefined Reason:
C:\source\cognitive-services-speech-sdk-master\samples\js\node\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 (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:354:27)
at Sink.executeSuccessCallback (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:345:23)
at Sink.resolve (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:306:23)
at Deferred.resolve (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:277:28)
at WebSocket._this.privWebsocketClient.onclose (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common.browser\WebsocketMessageAdapter.js:107:59)
at WebSocket.onClose (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\ws\lib\event-target.js:124:16)
at WebSocket.emit (events.js:210:5)
at WebSocket.emitClose (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\ws\lib\websocket.js:184:12)
at Object.onceWrapper (events.js:299:28)
at ClientRequest.emit (events.js:210:5)
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.
Thanks, that log was helpful.
Are you buy chance using the IntentRecognizer with a Speech Recognition key?
IntentRecognition needs keys from Language Understanding and not Speech.
We're working to simplify that.
The IntentRecognizer takes a SpeechConfig and an AudioConfig. The speech config is initiated with the Speech subscription key. Below is the relevant code. Where do I set the IntentRecognizer key with a LUIS key?
//var intentConfig = sdk.SpeechConfig.fromSubscription(settings.luSubscriptionKey, settings.luServiceRegion);
var intentConfig = sdk.SpeechConfig.fromSubscription(settings.subscriptionKey, settings.serviceRegion);
var audioConfig = sdk.AudioConfig.fromStreamInput(audioStream);
// setting the recognition language to English.
intentConfig.speechRecognitionLanguage = settings.language;
// create the translation recognizer.
var recognizer = new sdk.IntentRecognizer(intentConfig, audioConfig);
// Set up a Language Understanding Model from Language Understanding Intelligent Service (LUIS).
// See https://www.luis.ai/home for more information on LUIS.
if (settings.luAppId !== "" && settings.luAppId !== "YourLanguageUnderstandingAppId") {
var lm = sdk.LanguageUnderstandingModel.fromAppId(settings.luAppId);
recognizer.addAllIntents(lm);
}
You use the LUIS key instead of the Speech key.
When I do that I get "unable to contact server".
Thanks for the help by the way.
undefined | undefined | privName: RecognitionTriggeredEvent | privEventId: 25A92A4602AB4C51ABC83A0B14A29D6E | privEventTime: 2019-10-02T19:08:33.439Z | privEventType: 1 | privMetadata: {} | privRequestId: 837751FF76054BEB909557AAB2F91BD8 | privSessionId:
undefined | undefined | privName: ConnectingToServiceEvent | privEventId: B8523D19E2834AEC95F9A01802AB45DF | privEventTime: 2019-10-02T19:08:33.440Z | privEventType: 1 | privMetadata: {} | privRequestId: 837751FF76054BEB909557AAB2F91BD8 | privSessionId: 4686F67EDF7149CA81012C77BAF2CE39 | privAuthFetchEventid: 1B55B75902AB44C98553F838B13C965E
undefined | undefined | privName: ConnectionStartEvent | privEventId: FC8CDA8235A946998CE395897C1D6BD5 | privEventTime: 2019-10-02T19:08:33.464Z | privEventType: 1 | privMetadata: {} | privConnectionId: 4686F67EDF7149CA81012C77BAF2CE39 | privUri: wss://speech.platform.bing.com/speech/uswest/recognition/interactive/cognitiveservices/v1?format=simple&language=en-US&Ocp-Apim-Subscription-Key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&X-ConnectionId=4686F67EDF7149CA81012C77BAF2CE39 | privHeaders:
undefined | undefined | privName: AudioStreamNodeAttachingEvent | privEventId: E2CBF806A4DB4E0F808071CF16E9E87B | privEventTime: 2019-10-02T19:08:33.466Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: AE851DFA346746BC8D7B9854CB156200 | privAudioNodeId: 35F86F321EB34C928EBADB3B6CA0D314
undefined | undefined | privName: AudioSourceInitializingEvent | privEventId: FBDC39C30BE04D208EE43DB0966B0C3F | privEventTime: 2019-10-02T19:08:33.467Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: AE851DFA346746BC8D7B9854CB156200
undefined | undefined | privName: AudioSourceReadyEvent | privEventId: 704FFCA4E0A74470A133ECDEF2C399D8 | privEventTime: 2019-10-02T19:08:33.468Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: AE851DFA346746BC8D7B9854CB156200
undefined | undefined | privName: AudioStreamNodeAttachedEvent | privEventId: C4D9079E72FD4283AA3D0606E6D9438F | privEventTime: 2019-10-02T19:08:33.469Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: AE851DFA346746BC8D7B9854CB156200 | privAudioNodeId: 35F86F321EB34C928EBADB3B6CA0D314
undefined | undefined | privName: ListeningStartedEvent | privEventId: AF7C87B98111414CB1E0172133E51309 | privEventTime: 2019-10-02T19:08:33.470Z | privEventType: 1 | privMetadata: {} | privRequestId: 837751FF76054BEB909557AAB2F91BD8 | privSessionId: 4686F67EDF7149CA81012C77BAF2CE39 | privAudioSourceId: AE851DFA346746BC8D7B9854CB156200 | privAudioNodeId: 35F86F321EB34C928EBADB3B6CA0D314
closing pushStream ...
undefined | undefined | privName: AudioStreamNodeDetachedEvent | privEventId: B93F267D5D794867A5E726F4DAC73331 | privEventTime: 2019-10-02T19:08:34.020Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: AE851DFA346746BC8D7B9854CB156200 | privAudioNodeId: 35F86F321EB34C928EBADB3B6CA0D314
undefined | undefined | privName: ConnectingToServiceEvent | privEventId: 5F611C0DDF254D28A3AB5F138FA443C4 | privEventTime: 2019-10-02T19:08:34.022Z | privEventType: 1 | privMetadata: {} | privRequestId: 837751FF76054BEB909557AAB2F91BD8 | privSessionId: 97285FDCB50040B0823E12B9F252D1F3 | privAuthFetchEventid: 88A162D99CA04BCF9BC8CC1E4D6FEA9D
undefined | undefined | privName: ConnectionStartEvent | privEventId: 8C3BE493979F48D8B61C6A9DE8827A42 | privEventTime: 2019-10-02T19:08:34.028Z | privEventType: 1 | privMetadata: {} | privConnectionId: 97285FDCB50040B0823E12B9F252D1F3 | privUri: wss://speech.platform.bing.com/speech/uswest/recognition/interactive/cognitiveservices/v1?format=simple&language=en-US&Ocp-Apim-Subscription-Key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&X-ConnectionId=97285FDCB50040B0823E12B9F252D1F3 | privHeaders:
(cancel) Reason: Error: Unable to contact server. StatusCode: 1006, undefined Reason:
C:\source\cognitive-services-speech-sdk-master\samples\js\node\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 (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:354:27)
at Sink.executeSuccessCallback (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:345:23)
at Sink.resolve (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:306:23)
at Deferred.resolve (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common\Promise.js:277:28)
at WebSocket._this.privWebsocketClient.onclose (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\microsoft-cognitiveservices-speech-sdk\distrib\lib\src\common.browser\WebsocketMessageAdapter.js:107:59)
at WebSocket.onClose (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\ws\lib\event-target.js:124:16)
at WebSocket.emit (events.js:210:5)
at WebSocket.emitClose (C:\source\cognitive-services-speech-sdk-master\samples\js\node\node_modules\ws\lib\websocket.js:184:12)
at Object.onceWrapper (events.js:299:28)
at ClientRequest.emit (events.js:210:5)
Just to be sure... It's a LUIS EndPoint key and not an authoring key?
The first part of this HowTo goes into the setup and key extraction steps:
https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/how-to-recognize-intents-from-speech-csharp
Glad to help, sorry this is so confusing and complicated.
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!
Maybe subKey was wrong
Closing the issue as resolved.
Most helpful comment
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?