0

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. enter image description here enter image description here

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?

SkySoft
  • 133
  • 7
  • This post says that 1007 may be due to exceeding the limits of a free plan on Azure Cognitive Services. Are you using a paid plan or a free plan? https://stackoverflow.com/questions/66543065/azure-text-to-speech-throttled-due-to-too-many-requests-websocket-error-code-10 – jassent Jul 15 '23 at 20:45
  • Yes I am on the free plan. I can test it with standard plan. – SkySoft Jul 16 '23 at 03:22
  • Seems to still have the error. I will try to see if theres other ways to fix it. And will post an update if I find something. – SkySoft Jul 26 '23 at 07:42
  • Did you find what was the issue? If you still have the problem, could you please provide a log? https://learn.microsoft.com/en-us/azure/ai-services/speech-service/how-to-use-logging – jhakulin Aug 29 '23 at 00:57
  • @jhakulin Haven't had any problems after I upgraded. I think it wasn't working before was probably because it takes some time for the upgrade to take effect. – SkySoft Aug 31 '23 at 08:35

0 Answers0