Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to contact server. StatusCode: 1006, undefined Reason: Unexpected server response: 200 #235

Closed
bivas6 opened this issue Aug 31, 2020 · 9 comments
Assignees
Labels
bug Something isn't working in review Acknowledged and being looked at now

Comments

@bivas6
Copy link
Contributor

bivas6 commented Aug 31, 2020

Hi,

I'm trying to use the sdk as described here, but I'm getting this weird error: Unable to contact server. StatusCode: 1006, undefined Reason: Unexpected server response: 200

I followed this guide to connect existing Bot with existing Cognitive Service.

code:

const sdk = require('microsoft-cognitiveservices-speech-sdk');
const fs = require('fs');
const Throttle = require('throttle');

async function main() {
  console.log('start')
  const fileName = 'test-message-16k.wav'
  const audioStream = fs.createReadStream(fileName);
  const pushStream = sdk.AudioInputStream.createPushStream();
  const handleData = (buf) => {
    pushStream.write(buf.slice());
    console.log('data')
  };

  audioStream.pipe(new Throttle(16384))
    .on('data', handleData)
    .once('close', () => {
      console.log('close')
      pushStream.close();
      audioStream.removeListener('data', handleData);
    });
  const audioConfig = sdk.AudioConfig.fromStreamInput(pushStream)
  const botConfig = sdk.BotFrameworkConfig.fromSubscription('subscription-key', 'region')
  const reco = new sdk.DialogServiceConnector(botConfig, audioConfig)
  reco.recognizing = (_s, event) => {
    console.log('hypothesis', {
      text: event.result.text
    });
  };

  reco.recognized = (_s, event) => {
    ... <some code here>
    }
  };

  reco.canceled = (_s, event) => {
    ... <some code here>
  };

  // Signals that a new session has started with the speech service
  reco.sessionStarted = (_s, event) => {
    ... <some code here>
  };

  // Signals the end of a session with the speech service.
  reco.sessionStopped = (_s, event) => {
    ... <some code here>
  };

  // Signals that the speech service has started to detect speech.
  reco.speechStartDetected = (_s, event) => {
    ... <some code here>
  };

  // Signals that the speech service has detected that speech has stopped.
  reco.speechEndDetected = (_s, event) => {
    ... <some code here>
  };
  console.log('connect')
  reco.connect()
  reco.listenOnceAsync(undefined,
    (e) => {
      console.error('error')
      console.error(e)
    }
  );
  console.log('end')
}
main().catch((r) => console.error(r))

output is somthing like:

data
data
...
reco
connect
end
data
data
....
error
Unable to contact server. StatusCode: 1006, undefined Reason:  Unexpected server response: 200
data
data

This 'subscription-key', 'region' are in used in other parts of our code to connect azure speech sdk and direct line and it works as expected.

Please advise.

Thanks

cc: @orgads

@nisheetjain
Copy link
Member

Thanks orgads for the sharing the issue with us.

To make sure the setup is right, can you confirm if you have enabled the channel correctly in Azure bot service following this page?

@orgads
Copy link
Contributor

orgads commented Sep 2, 2020

We did.

@compulim
Copy link
Contributor

compulim commented Sep 3, 2020

FYI, this could be similar to #221, we are also seeing HTTP 200 immediately after Web Socket connection established. Only on Mac though.

@glharper
Copy link
Member

glharper commented Sep 9, 2020

(Edited to add reco.close() call when listenOnceAsync finishes)

Hi @bivas6,
One thing that comes to mind, connect() is async. Try this block at the end.

  reco.connect(
    function () {
      reco.listenOnceAsync(
        function (result) {
          // Handled by recognizing/recognized callback
          reco.close();
          reco = undefined;
        },
        function (err) {
          console.log(err);
          reco.close();
          reco = undefined;
        });
    },
    function (err) {
        console.log("Connect error:");
        console.log(err);
    });

Also, I'm setting the language for the botConfig and using sdk pushStreams for the audio input:

  // 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.slice());
  }).on('end', function() {
    pushStream.close();
  })
  
  var audioConfig = sdk.AudioConfig.fromStreamInput(pushStream);
  
  var botConfig = sdk.BotFrameworkConfig.fromSubscription(subscriptionKey, serviceRegion);
  
  botConfig.speechRecognitionLanguage = "en-US";

Could you try that in your code?

Thanks,
Glenn

@bivas6
Copy link
Contributor Author

bivas6 commented Sep 10, 2020

Thanks @glharper, but it didn't works.

There is no Unable to contact server error, but no any other response as well.

BTW, If this is the way to connect the server, DialogServiceConnector.d.ts needs update:

    /**
     * Starts a connection to the service.
     * Users can optionally call connect() to manually set up a connection in advance, before starting interactions.
     *
     * Note: On return, the connection might not be ready yet. Please subscribe to the Connected event to
     * be notified when the connection is established.
     * @member DialogServiceConnector.prototype.connect
     * @function
     * @public
     */
    connect(): void;

Thanks!

@glharper
Copy link
Member

glharper commented Sep 10, 2020

@bivas6 Giving it some thought, why are you calling connect() at all? listenOnceAsync() handles all the connection setup already, and double connecting could introduce issues like this one. Try:

  reco.listenOnceAsync(
    function (result) {
      reco.close();
      reco = undefined;
    },
    function (err) {
      console.log(err);
      reco.close();
      reco = undefined;
    });

without any call to connect() in the code.

Thanks. :-)

@trrwilson trrwilson added bug Something isn't working in review Acknowledged and being looked at now labels Sep 10, 2020
@bivas6
Copy link
Contributor Author

bivas6 commented Sep 13, 2020

@glharper It gives Unable to contact server. StatusCode: 1006, undefined Reason: Unexpected server response: 200.

Thanks for trying.

@glharper
Copy link
Member

@bivas6 I'm attaching a simple html page that triggers listenOnceAsync() on a given wav file. Using my creds for westus2, I've been unable to repro this issue, but if I could, I can look at fiddler and at least see where in the process this issue is happening. If you can modify this code to repro the issue, or have a key/region pair that reliably causes this, please update this or ping me on teams.

Thanks,
Glenn
bot_test_github.zip

@bivas6
Copy link
Contributor Author

bivas6 commented Sep 16, 2020

Hi @glharper,
we have changed the cognitive service account in the direct line speech channel, and now it works.

Thanks for the help!

@bivas6 bivas6 closed this as completed Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in review Acknowledged and being looked at now
Projects
None yet
Development

No branches or pull requests

6 participants