I'm trying to connect the Watson Speech to Text API, however I'm getting the following error for Firefox and Chrome. Note: It was working fine before, maybe some updates in the websocket terms. I appreciate your help!
var token = "{{payload}}";
var model = "en-US_BroadbandModel"; // Change to your own model
var wsURI = 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=' +
token + '&model=' + model;
var ws = new WebSocket(wsURI);
the error is being identified in this line:
var ws = new WebSocket(wsURI);
Browsers console errors:
Firefox: "SyntaxError: An invalid or illegal string was specified"
Chrome: "Uncaught DOMException: Failed to construct 'WebSocket': The
URL contains a fragment identifier ('x3D;&model=en-US_BroadbandModel').
Fragment identifiers are not allowed in WebSocket URLs."
Maybe you need to escape the token, have you tried that?
btw. have you tried the Watson Javascript SDK https://github.com/watson-developer-cloud/speech-javascript-sdk ? it deals with these lower level details for you.