From 4175b698d6f47a688bf2cee003ab540f37695379 Mon Sep 17 00:00:00 2001 From: glenn Date: Wed, 23 Aug 2023 12:04:25 -0400 Subject: [PATCH 1/2] Port 1.30.1 fix to master branch --- src/common.speech/ServiceRecognizerBase.ts | 3 ++- .../Transcription/ConversationTranslatorRecognizer.ts | 6 ++++-- src/sdk/PropertyId.ts | 9 ++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common.speech/ServiceRecognizerBase.ts b/src/common.speech/ServiceRecognizerBase.ts index c283ebc8..eb7ccde8 100644 --- a/src/common.speech/ServiceRecognizerBase.ts +++ b/src/common.speech/ServiceRecognizerBase.ts @@ -153,7 +153,8 @@ export abstract class ServiceRecognizerBase implements IDisposable { this.privDynamicGrammar = new DynamicGrammarBuilder(); this.privSpeechContext = new SpeechContext(this.privDynamicGrammar); this.privAgentConfig = new AgentConfig(); - if (typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") { + const webWorkerLoadType: string = this.privRecognizerConfig.parameters.getProperty(PropertyId.WebWorkerLoadType, "on").toLowerCase(); + if (webWorkerLoadType === "off" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") { this.privSetTimeout = Timeout.setTimeout; } diff --git a/src/common.speech/Transcription/ConversationTranslatorRecognizer.ts b/src/common.speech/Transcription/ConversationTranslatorRecognizer.ts index ca3ea7aa..4a7362b7 100644 --- a/src/common.speech/Transcription/ConversationTranslatorRecognizer.ts +++ b/src/common.speech/Transcription/ConversationTranslatorRecognizer.ts @@ -24,6 +24,7 @@ import { ConversationParticipantsChangedEventArgs, ConversationTranslationCanceledEventArgs, PropertyCollection, + PropertyId, Recognizer, SessionEventArgs, SpeechTranslationConfig @@ -77,8 +78,9 @@ export class ConversationTranslatorRecognizer extends Recognizer implements Conv this.privIsDisposed = false; this.privProperties = serviceConfigImpl.properties.clone(); this.privConnection = Connection.fromRecognizer(this); - this.privSetTimeout = (typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.setTimeout : setTimeout; - this.privClearTimeout = (typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.clearTimeout : clearTimeout; + const webWorkerLoadType: string = this.privProperties.getProperty(PropertyId.WebWorkerLoadType, "on").toLowerCase(); + this.privClearTimeout = (typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.clearTimeout : clearTimeout; this.privSetTimeout = (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.setTimeout : setTimeout; + this.privClearTimeout = (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.clearTimeout : clearTimeout; } public canceled: (sender: ConversationRecognizer, event: ConversationTranslationCanceledEventArgs) => void; diff --git a/src/sdk/PropertyId.ts b/src/sdk/PropertyId.ts index 2d7bfdf3..937b7087 100644 --- a/src/sdk/PropertyId.ts +++ b/src/sdk/PropertyId.ts @@ -481,5 +481,12 @@ export enum PropertyId { * Version of Speaker Recognition API to use. * Added in version 1.18.0 */ - SpeakerRecognition_Api_Version + SpeakerRecognition_Api_Version, + + /** + * Specifies whether to allow load of data URL for web worker + * Allowed values are "off" and "on". Default is "on". + * Added in version 1.32.0 + */ + WebWorkerLoadType, } From 9ebb48b866b7cdf99b3af23a06051e494172f9cd Mon Sep 17 00:00:00 2001 From: glenn Date: Wed, 23 Aug 2023 12:10:45 -0400 Subject: [PATCH 2/2] correctly bind timeout when webWorkerLoadType is off --- src/common.speech/ServiceRecognizerBase.ts | 7 ++++++- .../ConversationTranslatorRecognizer.ts | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/common.speech/ServiceRecognizerBase.ts b/src/common.speech/ServiceRecognizerBase.ts index eb7ccde8..5f4cd5a0 100644 --- a/src/common.speech/ServiceRecognizerBase.ts +++ b/src/common.speech/ServiceRecognizerBase.ts @@ -154,8 +154,13 @@ export abstract class ServiceRecognizerBase implements IDisposable { this.privSpeechContext = new SpeechContext(this.privDynamicGrammar); this.privAgentConfig = new AgentConfig(); const webWorkerLoadType: string = this.privRecognizerConfig.parameters.getProperty(PropertyId.WebWorkerLoadType, "on").toLowerCase(); - if (webWorkerLoadType === "off" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") { + if (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") { this.privSetTimeout = Timeout.setTimeout; + } else { + if (typeof window !== "undefined") { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + this.privSetTimeout = window.setTimeout.bind(window); + } } this.connectionEvents.attach((connectionEvent: ConnectionEvent): void => { diff --git a/src/common.speech/Transcription/ConversationTranslatorRecognizer.ts b/src/common.speech/Transcription/ConversationTranslatorRecognizer.ts index 4a7362b7..04b5fc17 100644 --- a/src/common.speech/Transcription/ConversationTranslatorRecognizer.ts +++ b/src/common.speech/Transcription/ConversationTranslatorRecognizer.ts @@ -79,8 +79,20 @@ export class ConversationTranslatorRecognizer extends Recognizer implements Conv this.privProperties = serviceConfigImpl.properties.clone(); this.privConnection = Connection.fromRecognizer(this); const webWorkerLoadType: string = this.privProperties.getProperty(PropertyId.WebWorkerLoadType, "on").toLowerCase(); - this.privClearTimeout = (typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.clearTimeout : clearTimeout; this.privSetTimeout = (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.setTimeout : setTimeout; - this.privClearTimeout = (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.clearTimeout : clearTimeout; + if (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") { + this.privSetTimeout = Timeout.setTimeout; + this.privClearTimeout = Timeout.clearTimeout; + } else { + if (typeof window !== "undefined") { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + this.privSetTimeout = window.setTimeout.bind(window); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + this.privClearTimeout = window.clearTimeout.bind(window); + } else { + this.privSetTimeout = setTimeout; + this.privClearTimeout = clearTimeout; + } + } } public canceled: (sender: ConversationRecognizer, event: ConversationTranslationCanceledEventArgs) => void;