Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal Invocation Error When Using Speech SDK in Cloudflare Workers Environment #810

Closed
sonbs21 opened this issue Apr 9, 2024 · 5 comments · Fixed by #811
Closed

Illegal Invocation Error When Using Speech SDK in Cloudflare Workers Environment #810

sonbs21 opened this issue Apr 9, 2024 · 5 comments · Fixed by #811
Assignees
Labels
bug Something isn't working

Comments

@sonbs21
Copy link

sonbs21 commented Apr 9, 2024

What happened?

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();

Version

1.36.0 (Latest)

What browser/platform are you seeing the problem on?

Node, Other

Relevant log output

No response

@sonbs21 sonbs21 added the bug Something isn't working label Apr 9, 2024
@glharper
Copy link
Member

glharper commented Apr 9, 2024

@sonbs21 Thank you for using JS Speech SDK, and writing this issue up. Any chance you could gather logs on this issue, and help us understand what exactly was "illegally invoked"?

(To enable logging, use the following code before starting recognition:

sdk.Diagnostics.SetLoggingLevel(sdk.LogLevel.Debug);
sdk.Diagnostics.SetLogOutputPath("LogfilePathAndName");

@sonbs21
Copy link
Author

sonbs21 commented Apr 10, 2024

X [ERROR] Error: throwIfNullOrUndefined: 

  File System access not available       
      at Contracts.throwIfNullOrUndefined
  (file:///D:/Dicamon/cory/cory-be/node_modules/microsoft-cognitiveservices-speech-sdk/distrib/lib/src/sdk/src/sdk/Contracts.ts:11:19)
      at set logPath
  (file:///D:/Dicamon/cory/cory-be/node_modules/microsoft-cognitiveservices-speech-sdk/distrib/lib/src/common.browser/src/common.browser/ConsoleLoggingListener.ts:22:19)
      at Diagnostics2.SetLogOutputPath
  (file:///D:/Dicamon/cory/cory-be/node_modules/microsoft-cognitiveservices-speech-sdk/distrib/lib/src/sdk/src/sdk/Diagnostics.ts:39:35)
      at SpeechService.speechToText
  (file:///D:/Dicamon/cory/cory-be/src/service/speech.service.ts:206:23)
      at app.openapi.c.json.message (file:///D:/Dicamon/cory/cory-be/src/index.ts:398:26)
      at dispatch (file:///D:/Dicamon/cory/cory-be/node_modules/hono/dist/compose.js:29:23)
      at null.<anonymous> (file:///D:/Dicamon/cory/cory-be/node_modules/hono/dist/compose.js:30:20)
      at timing2
  (file:///D:/Dicamon/cory/cory-be/node_modules/hono/dist/middleware/timing/index.js:28:11)
      at dispatch (file:///D:/Dicamon/cory/cory-be/node_modules/hono/dist/compose.js:29:23)
      at null.<anonymous> (file:///D:/Dicamon/cory/cory-be/node_modules/hono/dist/compose.js:6:12)


2024-04-10T02:41:32.693Z | RecognitionTriggeredEvent | privName: RecognitionTriggeredEvent | privEventId: AB9EEBF836F644BB960CD0898507DB46 | privEventTime: 2024-04-10T02:41:32.693Z | privEventType: 1 | privMetadata: {} | privRequestId: 486F5D1E168648F082CDFCDF21DA2FAA | privSessionId: <NULL> | privAudioSourceId: 97FD998CE8B643FEB8B589DF8491321D | privAudioNodeId: 4A45AE9DAB28416D845AC2F7D389B819
2024-04-10T02:41:32.696Z | ConnectingToServiceEvent | privName: ConnectingToServiceEvent | privEventId: AB51EDBD6FC44BDBB9AEA221508CD9F2 | privEventTime: 2024-04-10T02:41:32.696Z | privEventType: 1 | privMetadata: {} | privRequestId: 486F5D1E168648F082CDFCDF21DA2FAA | privSessionId: FC5DA4F4CE9A4812BC46800FD6DA7002 | privAuthFetchEventid: 06EE9F9D315F4EACBA791B445F5502F7
2024-04-10T02:41:32.697Z | AudioStreamNodeAttachingEvent | privName: AudioStreamNodeAttachingEvent | privEventId: 9AF876D974834A339754089685A7B576 | privEventTime: 2024-04-10T02:41:32.697Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: 97FD998CE8B643FEB8B589DF8491321D | privAudioNodeId: 4A45AE9DAB28416D845AC2F7D389B819
2024-04-10T02:41:32.698Z | AudioSourceInitializingEvent | privName: AudioSourceInitializingEvent | privEventId: 7667D3B8197C45F2B65A51028AD9EE8C | privEventTime: 2024-04-10T02:41:32.698Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: 97FD998CE8B643FEB8B589DF8491321D
2024-04-10T02:41:32.698Z | AudioSourceReadyEvent | privName: AudioSourceReadyEvent | privEventId: 4C8122D9C3D64F2FAEFAB84B399A6BCB | privEventTime: 2024-04-10T02:41:32.698Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: 97FD998CE8B643FEB8B589DF8491321D
2024-04-10T02:41:32.699Z | AudioStreamNodeAttachedEvent | privName: AudioStreamNodeAttachedEvent | privEventId: F5CB0C07BA0D49649DA20BB7AB576CFA | privEventTime: 2024-04-10T02:41:32.699Z | privEventType: 1 | privMetadata: {} | privAudioSourceId: 97FD998CE8B643FEB8B589DF8491321D | privAudioNodeId: 4A45AE9DAB28416D845AC2F7D389B8192024-04-10T02:41:32.702Z | ConnectionStartEvent | privName: ConnectionStartEvent | privEventId: 5B905977E4574953B4C3BF3A42DCB185 | privEventTime: 2024-04-10T02:41:32.702Z | privEventType: 1 | privMetadata: {} | privConnectionId: FC5DA4F4CE9A4812BC46800FD6DA7002 | privUri: wss://southeastasia.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=en-US&format=simple&endSilenceTimeoutMs=3000&Ocp-Apim-Subscription-Key=97184de55f084905a3471be3cddd7cd6&X-ConnectionId=FC5DA4F4CE9A4812BC46800FD6DA7002 | privHeaders: <NULL>
2024-04-10T02:41:32.703Z | ListeningStartedEvent | privName: ListeningStartedEvent | privEventId: DA15895F421A418FB081E8C1B7D6E1FE | privEventTime: 2024-04-10T02:41:32.703Z | privEventType: 1 | privMetadata: {} | privRequestId: 486F5D1E168648F082CDFCDF21DA2FAA | privSessionId: FC5DA4F4CE9A4812BC46800FD6DA7002 | privAudioSourceId: 97FD998CE8B643FEB8B589DF8491321D | privAudioNodeId: 4A45AE9DAB28416D845AC2F7D389B819

@sonbs21
Copy link
Author

sonbs21 commented Apr 10, 2024

return new Promise((resolve: () => void): number => this.privSetTimeout(resolve, delayMs));

When this.prevSetTimeout in the delay function is called, an error will appear Illegal Invocation

@glharper
Copy link
Member

@sonbs21 If you could pull the branch in the PR above and test it with your cloudflare deployment to see that addresses the issue, I'd appreciate it.

@sonbs21
Copy link
Author

sonbs21 commented Apr 11, 2024

I've just tested and it looks like the issue has been resolved. Thank you for you help!😄

glharper added a commit that referenced this issue Apr 18, 2024
* test globalThis binding

* eslint escape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants