I have been trying to setup live transcription with Twilio and Azure Cognitive service. But I keep getting the Error from the speech recogniser function: "Quota exceeded (cid) : Websocket error code 1007". This error happens randomly and is not predictable. I can get live transcribed text for a while and then it just fails with the error.
Following is my code:
let pushStream: PushAudioInputStream | null = null;
let speechRecognizer: SpeechRecognizer | null = null;
// Websocket for listening to Twilio Stream
ws.on("message", (message) => {
const msg = JSON.parse(message.toString());
switch (msg.event) {
case "start": {
// Triggered when the websocket is opened to listen to Twilio Stream
// create speech config
const config = SpeechConfig.fromSubscription(
process.env.AZURE_SPEECH_KEY ?? "",
process.env.AZURE_SPEECH_REGION ?? ""
);
config.speechRecognitionLanguage = "en-US";
config.setProfanity(ProfanityOption.Raw);
config.setProperty(
PropertyId.SpeechServiceResponse_PostProcessingOption,
"TrueText"
);
// create a push stream for audio input that takes in mulaw
pushStream = AudioInputStream.createPushStream(
AudioStreamFormat.getWaveFormat(8000, 16, 1, AudioFormatTag.MuLaw)
);
// create azure speech recongiser for speech to text recognition
speechRecognizer = new SpeechRecognizer(
config,
AudioConfig.fromStreamInput(pushStream)
);
// Attach callback to log out result on speech end
speechRecognizer.recognized = async (s, e) => {
if (e.result.reason === ResultReason.RecognizedSpeech) {
const recognizedText = e.result.text;
console.log("recognizedText: ", recognizedText);
}
};
// Attach callback to log out reason for canelling speech recognizition
speechRecognizer.canceled = (s, e) => {
if (e.reason === CancellationReason.Error) {
console.log("Recognition cancelled: ", e); // <<---- Here is where the error keeps popping up
}
};
speechRecognizer.startContinuousRecognitionAsync();
break;
}
case "media": {
// Triggered when Twilio stream sends data packets in Mulaw format
// We write the data directly into the Azure stream
pushStream?.write(Buffer.from(msg.media.payload,"base64"));
break;
}
case "stop": {
// Triggered when Twilio stops Streaming
// Clean up Azure Speech recognizer
pushStream?.close();
pushStream = null;
speechRecognizer?.stopContinuousRecognitionAsync();
speechRecognizer = null;
break;
}
default:
}
});
No usage data indicating quota has been exceeded
I have looked through my Azure portal and see that there is no usage data for my subscription. And no usage was exceeded.
Websocket error code 1007
This error from the Azure docs means the recognizer has "received data inconsistent with the message type". But from my code I did not modify the payload from Twilio so I'm not sure how this is related to inconsistent data. And if its problem with data the error should be thrown right at the beginning of the transcription. But I get the error after a few transcriptions.
Question
I couldn't find anything information on this error. Has anyone encountered anything similar and know what could be the cause of this problem?