diff --git a/src/common.speech/ServiceRecognizerBase.ts b/src/common.speech/ServiceRecognizerBase.ts index c283ebc8..5f4cd5a0 100644 --- a/src/common.speech/ServiceRecognizerBase.ts +++ b/src/common.speech/ServiceRecognizerBase.ts @@ -153,8 +153,14 @@ 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 === "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 ca3ea7aa..04b5fc17 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,21 @@ 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(); + 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; 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, }