Closed xxxxlr closed 5 years ago
Hi there,
Sorry to hear you're having issues with using this library. I just created a brand new Bing Speech Service API key in my Azure account and tried it with one of the examples in this repo and I didn't run into any errors.
Could you please include the code you're running in this issue so I can try to reproduce from there?
Thanks!
Thanks for looking into this.
So, if in your test it works fine, then I think it's from my side. Here is the example code I tested with.
const path = require('path');
const speechService = require('ms-bing-speech-service');
let sentTwice = false;
const file = path.join(__dirname, 'samples', 'future-of-flying.wav');
const options = {
format: 'simple',
language: 'en-us',
subscriptionKey: 'your_api_key',
//with or without issueTokenUrl, I got different messages but neither got connected.
// issueTokenUrl: 'https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken',
debug: true
}
const recognizer = new speechService(options);
recognizer.start()
.then(() => {
console.log('service started');
recognizer.on('recognition', (e) => {
if (e.RecognitionStatus === 'Success') console.log(e);
});
// optional telemetry events to listen to
recognizer.on('speech.startDetected', () => console.log('speech start detected'));
recognizer.on('speech.endDetected', () => console.log('speech end detected'));
recognizer.on('turn.start', () => console.log('speech turn started', recognizer.turn.active));
// turn end means another audio sample can be sent if desired
recognizer.on('turn.end', () => {
console.log('speech turn ended');
// send file again to demonstrate how to start another turn of audio streaming
if (!sentTwice) {
recognizer.sendFile(file);
sentTwice = true;
}
});
recognizer.sendFile(file);
}).catch((error) => console.error('could not start service:', error));
And the error message caught is:
could not start service: _Event {
type: 'close',
isTrusted: false,
_yaeti: true,
code: 1006,
reason: 'connection failed',
wasClean: false,
target:
W3CWebSocket {
_listeners: {},
addEventListener: [Function: _addEventListener],
removeEventListener: [Function: _removeEventListener],
dispatchEvent: [Function: _dispatchEvent],
_url: 'wss://speech.platform.bing.com/speech/recognition/conversation/cognitiveservices/v1?language=en-us&format=simple&Authorization=Bearer%20%7B%20%22statusCode%22:%20401,%20%22message%22:%20%22Access%20denied%20due%20to%20invalid%20subscription%20key.%20Make%20sure%20to%20provide%20a%20valid%20key%20for%20an%20active%20subscription.%22%20%7D&XConnectionId=4047bff2a3fd4eca636cfdc799e64ff',
_readyState: 3,
_protocol: undefined,
_extensions: '',
_bufferedAmount: 0,
_binaryType: 'arraybuffer',
_connection: undefined,
_client:
WebSocketClient {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
config: [Object],
_req: null,
protocols: [],
origin: null,
url: [Object],
secure: true,
base64nonce: 'CS5ZKv6nS/UJNaO8gA==' },
onmessage: [Function: bound onMessage],
onerror: [Function],
onclose: [Function],
onopen: [Function] },
cancelable: true,
stopImmediatePropagation: [Function] }
So I don't think my problem is related to this repo at this point. My api key is really invalid?
@xxxxlr in my case it works only with 7-days trial, which does not have region prefix. 30-days trial comes with westus prefix and does not work.
@pavelsc , thanks for the info! I think you are right. and maybe @noopkat can confirm if she was using a 7-days or 30-days trial in her test, thanks in advance.
Do @pavelsc you happened to know how to get a 7-days trial instead of a 30-days trial? Because I am not seeing the option for 7-days trial anymore from yesterday when I was applying. I had to click on 'Add' to add the 'Speech services' and that was the 30-days trial which does not work in this case for some reason .
From MS official github(https://github.com/Azure-Samples/SpeechToText-WebSockets-Javascript) page:
NOTE: The content of this repository is supporting the Bing Speech Service, not the new Unified Speech Service.
I think the 30-days is for the 'new Unified Speech Service' and it's also the API key I got that was not working in this case. It's not for Bing Speech Serivice which is this lib for. So can I assume this lib is not compitable with the 'new Unified Speech Service' ? Or I just need to make some modification? Regardless it's an awesome lib!
Additional info:
The following option contains the given the token url, but still got connection failed, but error message is different now. Nothing about API key which is different from previous error message when not assigning this url.
const options = {
format: 'simple',
language: 'en-us',
subscriptionKey: 'your_api_key',
//NOTE: Assign the token url still got connection failed, but error message is different now. Nothin about API key which is different from previous code when not assigning this url.
issueTokenUrl: 'https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken',
debug: true
}
output message:
could not start service: _Event {
type: 'close',
isTrusted: false,
_yaeti: true,
code: 1006,
reason: 'connection failed',
wasClean: false,
target:
W3CWebSocket {
_listeners: {},
addEventListener: [Function: _addEventListener],
removeEventListener: [Function: _removeEventListener],
dispatchEvent: [Function: _dispatchEvent],
_url: 'wss://speech.platform.bing.com/speech/recognition/conversation/cognitiveservices/v1?language=en-us&format=simple&Authorization=Bearer%20eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1cm46bXMuY29nbml0aXZlc2VydmljZXMiLCJleHAiOiIxNTM4MDE4MTg0IiwicmVnaW9uIjoid2VzdHVzIiwic3Vic2NyaXB0aW9uLWlkIjoiZTY3ZGJkZGIzZjM4NDQxOGFkYmQxNWRiZmQOTkzYzQiLCJwcm9kdWN0LWlkIjoiU3BlZWNoU2VydmljZXMuRnJlZSIsImNvZ25pdGl2ZS1zZXJ2aWNlcy1lbmRwb2ludCI6Imh0dHBzOi8vYXBpLmNvZ25pdGl2ZS5taWNyb3NvZnQuY29tL2ludGVybmFsL3YxLAvIiwiYXp1cmUtcmVzb3VyY2UtaWQiOiIiLCJzY29wZSI6InNwZWVjaHNlcnZpY2VzIiwiYXVkIjoidXJuOm1zLnNwZWVjaHNlcnZpY2VzLndlc3R1cyJ9.M0EGAX_5vdXExUFu57-ZHTbFjI0QS89s7-IqEdkac8&XConnectionId=4b1eb9e3d6cd405189f9f6cca7c234e',
_readyState: 3,
_protocol: undefined,
_extensions: '',
_bufferedAmount: 0,
_binaryType: 'arraybuffer',
_connection: undefined,
_client:
WebSocketClient {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
config: [Object],
_req: null,
protocols: [],
origin: null,
url: [Object],
secure: true,
base64nonce: 'C9jiRS3a8lN1SzZLH+cg==' },
onmessage: [Function: bound onMessage],
onerror: [Function],
onclose: [Function],
onopen: [Function] },
cancelable: true,
stopImmediatePropagation: [Function] }
After comparing Bing speech service and the Unified speech service, it seems like the websocket url is different and after assigning the following serviceUrl in the option, it works fine.
const options = {
format: 'simple',
language: 'en-us',
subscriptionKey: 'your_api_key',
issueTokenUrl: 'https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken',
serviceUrl:`wss://westus.stt.speech.microsoft.com/speech/recognition/${_this.options.mode}/cognitiveservices/v1?format=simple&language=${_this.options.language}`
debug: true
}
Thanks everyone for helping out.
Hey, I got the API key today as free trial. But for some reason, I am keep getting the following authentication failure. I am wondering if it's from MS's protocal change or something? I am wondering if anyone is experienceing the same issue?