Illegal Invocation Error When Using Speech SDK in Cloudflare Workers Environment

SonBs 0 Reputation points
2024-04-09T04:47:20.11+00:00

I am encountering an Illegal invocation error when trying to use microsoft-cognitiveservices-speech-sdk within a Cloudflare Workers environment. The same code works as expected in a Node.js environment, but it fails when deployed to Cloudflare Workers.

     let audioStream = sdk.AudioInputStream.createPushStream();

     const res = await fetch("https://cdn.openai.com/API/docs/audio/alloy.wav");
     const arrayBuffer= await res.arrayBuffer();

     audioStream.write(arrBuf);
    audioStream.close();
        
    var audioConfig = sdk.AudioConfig.fromStreamInput(audioStream);
    var speechConfig = sdk.SpeechConfig.fromSubscription( "","");

        speechConfig.speechRecognitionLanguage = "en-US";
        var reco = new sdk.SpeechRecognizer(speechConfig, audioConfig);

        reco.recognizing = (s, e) => {
          var str = 
            "(recognizing) Reason: " +
            sdk.ResultReason[e.result.reason] +
            " Text: " +
            e.result.text;
          console.log(str);
        };

        reco.recognized = (s, e) => {
          var str =
            "(recognized) Reason: " +
            sdk.ResultReason[e.result.reason] +
            " Text: " +
            e.result.text;
          console.log(str);
        };

        reco.canceled = (s, e) => {
          var str = "(cancel) Reason: " + sdk.CancellationReason[e.reason];
          if (e.reason === sdk.CancellationReason.Error) {
            str += ": " + e.errorDetails;
          }

          console.log("(cancel) Error Details:" + e.errorDetails);
          console.log(
            "(cancel) Reason Error Code:" +
              sdk.CancellationErrorCode[e.errorCode]
          );
          console.log("(cancel) Reason:" + e.reason);
        };

        reco.sessionStarted = (s, e) => {
          var str = "(sessionStarted) SessionId: " + e.sessionId;
          console.log(str);
        };

        reco.sessionStopped = (s, e) => {
          var str = "(sessionStopped) SessionId: " + e.sessionId;
          console.log(str);
        };

        reco.speechStartDetected = (s, e) => {
          var str = "(speechStartDetected) SessionId: " + e.sessionId;
          console.log(str);
        };

        reco.speechEndDetected = (s, e) => {
          var str = "(speechStartDetected) SessionId: " + e.sessionId;
          console.log(str);
          reco.stopContinuousRecognitionAsync();
        };

        reco.speechEndDetected = (s, e) => {
          var str = "(speechEndDetected) SessionId: " + e.sessionId;
          console.log(str);
        };

        reco.startContinuousRecognitionAsync();

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
2,061 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. VasaviLankipalle-MSFT 18,676 Reputation points Moderator
    2024-04-09T20:18:07.3833333+00:00

    Hello @SonBs , Thanks for using Microsoft Q&A Platform.

    Generally, using containers you can implement a subset of the Speech service features within your own environment. For details on the available Speech containers in the Microsoft Container Registry (MCR), you can refer to the documentation. Try to implement this.

    If you still face issues, please raise this here : https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues

    I hope this helps.

    Regards,
    Vasavi

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.