I encountered the same issue, where I was able to successfully connect and return audio when using the SDK Text-to-Speech service, but when I tried Speech-to-Text, I got the following connection error:
CANCELED: Reason=0
CANCELED: ErrorCode=4
CANCELED: ErrorDetails=Unable to contact server. StatusCode: 1006, undefined Reason: connect ETIMEDOUT 20.195.72.247:443
CANCELED: Did you set the speech resource key and region values?
I'm certain that the resource key and region values are set correctly, and the network connection should be fine, as the Text-to-Speech service is working normally. The related code is as follows:
let speechConfig = sdk.SpeechConfig.fromSubscription(process.env.SPEECH_KEY, process.env.SPEECH_REGION);
let audioConfig = sdk.AudioConfig.fromWavFileInput(buffer2)
speechConfig.speechRecognitionLanguage = "en-US";
let speechRecognizer = new sdk.SpeechRecognizer(speechConfig, audioConfig);
let text = '';
speechRecognizer.recognizing = (s, e) => {
console.log(`RECOGNIZING: Text=${e.result.text}`);
};
speechRecognizer.recognized = (s, e) => {
if (e.result.reason == sdk.ResultReason.RecognizedSpeech) {
console.log(`RECOGNIZED: Text=${e.result.text}`);
text = text + e.result.text
} else if (e.result.reason == sdk.ResultReason.NoMatch) {
console.log("NOMATCH: Speech could not be recognized.");
}
};
speechRecognizer.canceled = (s, e) => {
console.log(`CANCELED: Reason=${e.reason}`);
if (e.reason == sdk.CancellationReason.Error) {
console.log(`"CANCELED: ErrorCode=${e.errorCode}`);
console.log(`"CANCELED: ErrorDetails=${e.errorDetails}`);
console.log("CANCELED: Did you set the speech resource key and region values?");
}
speechRecognizer.stopContinuousRecognitionAsync();
};
speechRecognizer.sessionStopped = (s, e) => {
console.log("\n Session stopped event.");
speechRecognizer.stopContinuousRecognitionAsync();
};
speechRecognizer.startContinuousRecognitionAsync();