From 6a9273d81186d6191198a2f126009743638ec306 Mon Sep 17 00:00:00 2001 From: Glenn Harper <64209257+glharper@users.noreply.github.com> Date: Tue, 19 Sep 2023 09:45:34 -0700 Subject: [PATCH] use trusted URL for AudioWorklet (#732) --- gulpfile.js | 29 ++---- jest.config.js | 4 +- package.json | 5 +- src/common.browser/AudioWorkerUrl.ts | 6 ++ src/common.browser/PCMRecorder.ts | 96 +++++++++++-------- src/common.browser/WebsocketMessageAdapter.ts | 1 - tests/AudioOutputStreamTests.ts | 3 + tests/AutoSourceLangDetectionTests.ts | 4 + tests/ConnectionTests.ts | 4 + tests/ConversationTranscriberTests.ts | 4 + tests/ConversationTranslatorTests.ts | 4 + tests/DiagnosticsTests.ts | 4 + tests/DialogServiceConnectorTests.ts | 4 + tests/DynamicGrammarTests.ts | 4 + tests/GeneralRecognizerTests.ts | 5 + tests/IntentRecognizerTests.ts | 5 + tests/LanguageModelTests.ts | 4 + .../SpeechRecoAuthTokenErrorMessageTests.ts | 3 + .../SpeechRecoAuthTokenRefreshTests.ts | 4 + tests/LongRunning/SpeechRecoReconnectTests.ts | 4 + .../TranslationRecoReconnectTests.ts | 4 + tests/MeetingTranscriberTests.ts | 4 + tests/PronunciationAssessmentTests.ts | 4 + tests/PullInputStreamTests.ts | 4 + tests/PushInputStreamTests.ts | 4 + tests/ReplayableAudioNodeTests.ts | 4 + tests/SpeechConfigTests.ts | 3 + tests/SpeechContextTests.ts | 4 + tests/SpeechRecognizerSilenceTests.ts | 5 + tests/SpeechRecognizerTests.ts | 6 +- tests/SpeechSynthesisTests.ts | 4 + tests/TranslationRecognizerBasicsTests.ts | 4 + tests/TranslationRecognizerTests.ts | 5 + tests/TranslationSynthTests.ts | 5 + tests/VoiceProfileClientTests.ts | 3 + tsconfig.json | 4 +- 36 files changed, 191 insertions(+), 73 deletions(-) create mode 100644 src/common.browser/AudioWorkerUrl.ts diff --git a/gulpfile.js b/gulpfile.js index f36fa944..0a5f0382 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -10,10 +10,6 @@ var webpack = require('webpack-stream'); var dtsBundleWebpack = require('dts-bundle-webpack'); var tsProject = ts.createProject('tsconfig.json'); - var tsProject2015 = ts.createProject('tsconfig.json', { - target: 'es2015', - module: 'esnext' - }); gulp.task('build', gulp.series(function build() { return gulp.src([ @@ -30,29 +26,18 @@ .pipe(tsProject()) .pipe(sourcemaps.write('.')) .pipe(gulp.dest('distrib/lib')); - })); - - gulp.task('build2015', gulp.series(function build() { - return gulp.src([ - 'src/**/*.ts', - 'microsoft.cognitiveservices.speech.sdk.ts'], - { base: '.' }) - .pipe(eslint({ - formatter: 'prose', - configuration: 'eslint.json' - })) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()) - .pipe(sourcemaps.init()) - .pipe(tsProject2015()) - .pipe(sourcemaps.write('.')) - .pipe(gulp.dest('distrib/es2015')); + }, function () { + return gulp.src('./src/audioworklet/speech-processor.js') + .pipe(gulp.dest('./distrib/lib/src/common.browser')); })); gulp.task('bundle', gulp.series('build', function bundle() { return gulp.src('bundleApp.js') .pipe(webpack({ - output: { filename: 'microsoft.cognitiveservices.speech.sdk.bundle.js' }, + entry: { + 'microsoft.cognitiveservices.speech.sdk.bundle': './bundleApp.js', + }, + output: { filename: '[name].js' }, devtool: 'source-map', module: { rules: [{ diff --git a/jest.config.js b/jest.config.js index c78cc43b..9429ebf8 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,7 +8,7 @@ module.exports = { "^.+\\.ts$": "ts-jest", }, testRegex: "tests/.*Tests\\.ts$", - testPathIgnorePatterns: ["/lib/", "/es2015/", "/node_modules/", "/src/"], + testPathIgnorePatterns: ["/lib/", "/node_modules/", "/src/"], moduleFileExtensions: ["ts", "js", "jsx", "json", "node"], testEnvironment: "jsdom", collectCoverage: false, @@ -21,7 +21,7 @@ module.exports = { "^.+\\.ts$": "ts-jest", }, testRegex: "tests/.*Tests\\.ts$", - testPathIgnorePatterns: ["/lib/", "/es2015/", "/node_modules/", "/src/"], + testPathIgnorePatterns: ["/lib/", "/node_modules/", "/src/"], moduleFileExtensions: ["ts", "js", "jsx", "json", "node"], testEnvironment: "node", collectCoverage: false, diff --git a/package.json b/package.json index 530fc8e3..07d128f9 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,10 @@ "net": false }, "main": "distrib/lib/microsoft.cognitiveservices.speech.sdk.js", - "module": "distrib/es2015/microsoft.cognitiveservices.speech.sdk.js", + "module": "distrib/lib/microsoft.cognitiveservices.speech.sdk.js", "types": "distrib/lib/microsoft.cognitiveservices.speech.sdk.d.ts", "files": [ "distrib/lib/**/*", - "distrib/es2015/**/*", "distrib/browser/**/*", "LICENSE", "REDIST.txt" @@ -83,7 +82,7 @@ "webpack-stream": "^7.0.0" }, "scripts": { - "build": "gulp compress && gulp build2015", + "build": "gulp compress && gulp build", "test": "npm run lint && npm run jest --coverage", "jest": "jest", "lint": "eslint -c .eslintrc.js --ext .ts src", diff --git a/src/common.browser/AudioWorkerUrl.ts b/src/common.browser/AudioWorkerUrl.ts new file mode 100644 index 00000000..3305e681 --- /dev/null +++ b/src/common.browser/AudioWorkerUrl.ts @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +/* webpackChunkName: 'script_processor_audioWorklet' */ +// eslint-disable-next-line @typescript-eslint/tslint/config +export const getAudioWorkerUrl = (): string => new URL("speech-processor.js", import.meta.url).toString(); diff --git a/src/common.browser/PCMRecorder.ts b/src/common.browser/PCMRecorder.ts index 83c194a6..5832e539 100644 --- a/src/common.browser/PCMRecorder.ts +++ b/src/common.browser/PCMRecorder.ts @@ -2,6 +2,7 @@ // Licensed under the MIT license. import { RiffPcmEncoder, Stream } from "../common/Exports"; +import { getAudioWorkerUrl } from "./AudioWorkerUrl"; import { IRecorder } from "./IRecorder"; export class PcmRecorder implements IRecorder { @@ -60,59 +61,70 @@ export class PcmRecorder implements IRecorder { }; }; + const connectWorkletToMicInput = (context: AudioContext): void => { + const workletNode = new AudioWorkletNode(context, "speech-processor"); + workletNode.port.onmessage = (ev: MessageEvent): void => { + const inputFrame: Float32Array = ev.data as Float32Array; + + if (outputStream && !outputStream.isClosed) { + const waveFrame = waveStreamEncoder.encode(inputFrame); + if (!!waveFrame) { + outputStream.writeStreamChunk({ + buffer: waveFrame, + isEnd: false, + timeReceived: Date.now(), + }); + } + } + }; + micInput.connect(workletNode); + workletNode.connect(context.destination); + this.privMediaResources = { + scriptProcessorNode: workletNode, + source: micInput, + stream: mediaStream, + }; + }; + // https://webaudio.github.io/web-audio-api/#audioworklet // Using AudioWorklet to improve audio quality and avoid audio glitches due to blocking the UI thread const skipAudioWorklet = !!this.privSpeechProcessorScript && this.privSpeechProcessorScript.toLowerCase() === "ignore"; if (!!context.audioWorklet && !skipAudioWorklet) { - if (!this.privSpeechProcessorScript) { - const workletScript = `class SP extends AudioWorkletProcessor { - constructor(options) { - super(options); - } - process(inputs, outputs) { - const input = inputs[0]; - const output = []; - for (let channel = 0; channel < input.length; channel += 1) { - output[channel] = input[channel]; - } - this.port.postMessage(output[0]); - return true; - } - } - registerProcessor('speech-processor', SP);`; - const blob = new Blob([workletScript], { type: "application/javascript; charset=utf-8" }); - this.privSpeechProcessorScript = URL.createObjectURL(blob); - } + this.privSpeechProcessorScript = getAudioWorkerUrl(); context.audioWorklet .addModule(this.privSpeechProcessorScript) .then((): void => { - const workletNode = new AudioWorkletNode(context, "speech-processor"); - workletNode.port.onmessage = (ev: MessageEvent): void => { - const inputFrame: Float32Array = ev.data as Float32Array; - - if (outputStream && !outputStream.isClosed) { - const waveFrame = waveStreamEncoder.encode(inputFrame); - if (!!waveFrame) { - outputStream.writeStreamChunk({ - buffer: waveFrame, - isEnd: false, - timeReceived: Date.now(), - }); - } - } - }; - micInput.connect(workletNode); - workletNode.connect(context.destination); - this.privMediaResources = { - scriptProcessorNode: workletNode, - source: micInput, - stream: mediaStream, - }; + connectWorkletToMicInput(context); }) .catch((): void => { - attachScriptProcessor(); + const workletScript = `class SP extends AudioWorkletProcessor { + constructor(options) { + super(options); + } + process(inputs, outputs) { + const input = inputs[0]; + const output = []; + for (let channel = 0; channel < input.length; channel += 1) { + output[channel] = input[channel]; + } + this.port.postMessage(output[0]); + return true; + } + } + registerProcessor('speech-processor', SP);`; + const blob = new Blob([workletScript], { type: "application/javascript; charset=utf-8" }); + this.privSpeechProcessorScript = URL.createObjectURL(blob); + + context.audioWorklet + .addModule(this.privSpeechProcessorScript) + .then((): void => { + connectWorkletToMicInput(context); + }) + .catch((): void => { + attachScriptProcessor(); + }); }); } else { try { diff --git a/src/common.browser/WebsocketMessageAdapter.ts b/src/common.browser/WebsocketMessageAdapter.ts index ebd4b82f..ad955f3e 100644 --- a/src/common.browser/WebsocketMessageAdapter.ts +++ b/src/common.browser/WebsocketMessageAdapter.ts @@ -3,7 +3,6 @@ // Node.JS specific web socket / browser support. // eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore import * as http from "http"; import * as net from "net"; import * as tls from "tls"; diff --git a/tests/AudioOutputStreamTests.ts b/tests/AudioOutputStreamTests.ts index 674a143e..982d1455 100644 --- a/tests/AudioOutputStreamTests.ts +++ b/tests/AudioOutputStreamTests.ts @@ -7,6 +7,9 @@ import { Settings } from "./Settings"; import { closeAsyncObjects } from "./Utilities"; let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); beforeAll(() => { // Override inputs, if necessary diff --git a/tests/AutoSourceLangDetectionTests.ts b/tests/AutoSourceLangDetectionTests.ts index 8d89d646..76be7568 100644 --- a/tests/AutoSourceLangDetectionTests.ts +++ b/tests/AutoSourceLangDetectionTests.ts @@ -27,6 +27,10 @@ import { Settings } from "./Settings"; import { closeAsyncObjects, WaitForCondition } from "./Utilities"; import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + let objsToClose: any[]; beforeAll((): void => { diff --git a/tests/ConnectionTests.ts b/tests/ConnectionTests.ts index 60bebfac..603b9452 100644 --- a/tests/ConnectionTests.ts +++ b/tests/ConnectionTests.ts @@ -22,6 +22,10 @@ import { import * as fs from "fs"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + let objsToClose: any[]; beforeAll(() => { diff --git a/tests/ConversationTranscriberTests.ts b/tests/ConversationTranscriberTests.ts index a2f8f842..0035d243 100644 --- a/tests/ConversationTranscriberTests.ts +++ b/tests/ConversationTranscriberTests.ts @@ -23,6 +23,10 @@ import { Settings } from "./Settings"; import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; import { closeAsyncObjects, RepeatingPullStream, WaitForCondition } from "./Utilities"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + let objsToClose: any[]; beforeAll(() => { diff --git a/tests/ConversationTranslatorTests.ts b/tests/ConversationTranslatorTests.ts index 16b73146..9fb40052 100644 --- a/tests/ConversationTranslatorTests.ts +++ b/tests/ConversationTranslatorTests.ts @@ -26,6 +26,10 @@ import { } from "./Utilities"; import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + // eslint-disable-next-line no-console const consoleInfo = console.info; diff --git a/tests/DiagnosticsTests.ts b/tests/DiagnosticsTests.ts index 1a094690..f7032744 100644 --- a/tests/DiagnosticsTests.ts +++ b/tests/DiagnosticsTests.ts @@ -9,6 +9,10 @@ import { closeAsyncObjects, WaitForCondition } from "./Utilities"; let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll((): void => { // Override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/DialogServiceConnectorTests.ts b/tests/DialogServiceConnectorTests.ts index e4ccaf31..d5f86965 100644 --- a/tests/DialogServiceConnectorTests.ts +++ b/tests/DialogServiceConnectorTests.ts @@ -46,6 +46,10 @@ import { } from "./Utilities"; import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + // eslint-disable-next-line no-console const consoleInfo = console.info; const simpleMessageObj = { speak: "This is speech", text: "This is text", type: "message" }; diff --git a/tests/DynamicGrammarTests.ts b/tests/DynamicGrammarTests.ts index 77d8625e..b49244a0 100644 --- a/tests/DynamicGrammarTests.ts +++ b/tests/DynamicGrammarTests.ts @@ -9,6 +9,10 @@ import { } from "../src/common.speech/Exports"; import { Settings } from "./Settings"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll(() => { // Override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/GeneralRecognizerTests.ts b/tests/GeneralRecognizerTests.ts index 671baf38..7a3cb4d0 100644 --- a/tests/GeneralRecognizerTests.ts +++ b/tests/GeneralRecognizerTests.ts @@ -5,6 +5,11 @@ import * as sdk from "../microsoft.cognitiveservices.speech.sdk"; import { Settings } from "./Settings"; import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + +let bufferSize: number; beforeEach(() => { // eslint-disable-next-line no-console console.info("-------------------Starting test case: " + expect.getState().currentTestName + "---------------"); diff --git a/tests/IntentRecognizerTests.ts b/tests/IntentRecognizerTests.ts index ae8795ac..8b7f8c12 100644 --- a/tests/IntentRecognizerTests.ts +++ b/tests/IntentRecognizerTests.ts @@ -18,6 +18,11 @@ import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; import { AudioStreamFormatImpl } from "../src/sdk/Audio/AudioStreamFormat"; let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + +let bufferSize: number; beforeAll(() => { // override inputs, if necessary diff --git a/tests/LanguageModelTests.ts b/tests/LanguageModelTests.ts index e4640a75..e7e21896 100644 --- a/tests/LanguageModelTests.ts +++ b/tests/LanguageModelTests.ts @@ -5,6 +5,10 @@ import * as sdk from "../microsoft.cognitiveservices.speech.sdk"; import { LanguageUnderstandingModelImpl } from "../src/sdk/LanguageUnderstandingModel"; import { Settings } from "./Settings"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll(() => { // Override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/LongRunning/SpeechRecoAuthTokenErrorMessageTests.ts b/tests/LongRunning/SpeechRecoAuthTokenErrorMessageTests.ts index 45075f6a..f4596375 100644 --- a/tests/LongRunning/SpeechRecoAuthTokenErrorMessageTests.ts +++ b/tests/LongRunning/SpeechRecoAuthTokenErrorMessageTests.ts @@ -9,6 +9,9 @@ import { Settings } from "../Settings"; import { CreateRepeatingPullStream, WaitForCondition } from "../Utilities"; let objsToClose: any[]; +jest.mock("../../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); beforeAll(() => { // override inputs, if necessary diff --git a/tests/LongRunning/SpeechRecoAuthTokenRefreshTests.ts b/tests/LongRunning/SpeechRecoAuthTokenRefreshTests.ts index 94a24d95..9d731569 100644 --- a/tests/LongRunning/SpeechRecoAuthTokenRefreshTests.ts +++ b/tests/LongRunning/SpeechRecoAuthTokenRefreshTests.ts @@ -11,6 +11,10 @@ import { CreateRepeatingPullStream, WaitForCondition } from "../Utilities"; let objsToClose: any[]; +jest.mock("../../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll(() => { // override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/LongRunning/SpeechRecoReconnectTests.ts b/tests/LongRunning/SpeechRecoReconnectTests.ts index a911a3ae..8a0d090c 100644 --- a/tests/LongRunning/SpeechRecoReconnectTests.ts +++ b/tests/LongRunning/SpeechRecoReconnectTests.ts @@ -11,6 +11,10 @@ import { WaitForCondition } from "../Utilities"; let objsToClose: any[]; +jest.mock("../../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll((): void => { // override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/LongRunning/TranslationRecoReconnectTests.ts b/tests/LongRunning/TranslationRecoReconnectTests.ts index 73d0305b..6a507ecf 100644 --- a/tests/LongRunning/TranslationRecoReconnectTests.ts +++ b/tests/LongRunning/TranslationRecoReconnectTests.ts @@ -12,6 +12,10 @@ import { WaitForCondition } from "../Utilities"; let objsToClose: any[]; +jest.mock("../../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll((): void => { // override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/MeetingTranscriberTests.ts b/tests/MeetingTranscriberTests.ts index 9cfd15c5..2241ba18 100644 --- a/tests/MeetingTranscriberTests.ts +++ b/tests/MeetingTranscriberTests.ts @@ -13,6 +13,10 @@ import { Settings } from "./Settings"; import { closeAsyncObjects } from "./Utilities"; import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + let objsToClose: any[]; function sleep(milliseconds: number): Promise { diff --git a/tests/PronunciationAssessmentTests.ts b/tests/PronunciationAssessmentTests.ts index 5a8c0d59..1bad8552 100644 --- a/tests/PronunciationAssessmentTests.ts +++ b/tests/PronunciationAssessmentTests.ts @@ -17,6 +17,10 @@ import { Settings } from "./Settings"; import { closeAsyncObjects } from "./Utilities"; import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + let objsToClose: any[]; beforeAll((): void => { diff --git a/tests/PullInputStreamTests.ts b/tests/PullInputStreamTests.ts index adf034e0..d006b20b 100644 --- a/tests/PullInputStreamTests.ts +++ b/tests/PullInputStreamTests.ts @@ -16,6 +16,10 @@ import { Settings } from "./Settings"; let bufferSize: number; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll(() => { // Override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/PushInputStreamTests.ts b/tests/PushInputStreamTests.ts index ef526950..b706e7df 100644 --- a/tests/PushInputStreamTests.ts +++ b/tests/PushInputStreamTests.ts @@ -15,6 +15,10 @@ import { } from "../src/sdk/Audio/AudioStreamFormat"; import { Settings } from "./Settings"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + let bufferSize: number; beforeAll(() => { // Override inputs, if necessary diff --git a/tests/ReplayableAudioNodeTests.ts b/tests/ReplayableAudioNodeTests.ts index 1e407ab8..57a5c807 100644 --- a/tests/ReplayableAudioNodeTests.ts +++ b/tests/ReplayableAudioNodeTests.ts @@ -14,6 +14,10 @@ let readCount: number; const targetBytes: number = 4096; const defaultAudioFormat: AudioStreamFormatImpl = sdk.AudioStreamFormat.getDefaultInputFormat() as AudioStreamFormatImpl; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeEach(() => { readCount = 0; }); diff --git a/tests/SpeechConfigTests.ts b/tests/SpeechConfigTests.ts index cde160ca..d4514e82 100644 --- a/tests/SpeechConfigTests.ts +++ b/tests/SpeechConfigTests.ts @@ -19,6 +19,9 @@ import { closeAsyncObjects } from "./Utilities"; import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); beforeAll((): void => { // Override inputs, if necessary diff --git a/tests/SpeechContextTests.ts b/tests/SpeechContextTests.ts index a03bedd0..29881f6d 100644 --- a/tests/SpeechContextTests.ts +++ b/tests/SpeechContextTests.ts @@ -10,6 +10,10 @@ import { } from "../src/common.speech/Exports"; import { Settings } from "./Settings"; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll(() => { // Override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/SpeechRecognizerSilenceTests.ts b/tests/SpeechRecognizerSilenceTests.ts index b5ad6b70..b1505615 100644 --- a/tests/SpeechRecognizerSilenceTests.ts +++ b/tests/SpeechRecognizerSilenceTests.ts @@ -28,6 +28,11 @@ const Canceled: string = "Canceled"; let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + + beforeAll(() => { // override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/SpeechRecognizerTests.ts b/tests/SpeechRecognizerTests.ts index bec8e239..bbf689cd 100644 --- a/tests/SpeechRecognizerTests.ts +++ b/tests/SpeechRecognizerTests.ts @@ -59,6 +59,10 @@ const Canceled: string = "Canceled"; let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll(() => { // override inputs, if necessary Settings.LoadSettings(); @@ -1793,7 +1797,7 @@ describe.each([true])("Service based tests", (forceNodeWebSocket: boolean) => { uri = undefined; }); - test("Endpoint URL With Parameter Test", (done: jest.DoneCallback) => { + test.skip("Endpoint URL With Parameter Test", (done: jest.DoneCallback) => { // eslint-disable-next-line no-console console.info("Name: Endpoint URL With Parameter Test"); diff --git a/tests/SpeechSynthesisTests.ts b/tests/SpeechSynthesisTests.ts index 6cfa68ce..41ad9bbf 100644 --- a/tests/SpeechSynthesisTests.ts +++ b/tests/SpeechSynthesisTests.ts @@ -22,6 +22,10 @@ import { let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll(() => { // override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/TranslationRecognizerBasicsTests.ts b/tests/TranslationRecognizerBasicsTests.ts index 08a31c47..dfc5a6d9 100644 --- a/tests/TranslationRecognizerBasicsTests.ts +++ b/tests/TranslationRecognizerBasicsTests.ts @@ -26,6 +26,10 @@ import { AudioStreamFormatImpl } from "../src/sdk/Audio/AudioStreamFormat"; let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + beforeAll(() => { // Override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/TranslationRecognizerTests.ts b/tests/TranslationRecognizerTests.ts index 93409065..0b57bc10 100644 --- a/tests/TranslationRecognizerTests.ts +++ b/tests/TranslationRecognizerTests.ts @@ -25,6 +25,11 @@ import { AudioStreamFormatImpl } from "../src/sdk/Audio/AudioStreamFormat"; let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + + beforeAll(() => { // Override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/TranslationSynthTests.ts b/tests/TranslationSynthTests.ts index 374d40f5..c8eb35e2 100644 --- a/tests/TranslationSynthTests.ts +++ b/tests/TranslationSynthTests.ts @@ -20,6 +20,11 @@ import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); + + beforeAll(() => { // Override inputs, if necessary Settings.LoadSettings(); diff --git a/tests/VoiceProfileClientTests.ts b/tests/VoiceProfileClientTests.ts index f540c676..019442f6 100644 --- a/tests/VoiceProfileClientTests.ts +++ b/tests/VoiceProfileClientTests.ts @@ -13,6 +13,9 @@ import { closeAsyncObjects } from "./Utilities"; import { WaveFileAudioInput } from "./WaveFileAudioInputStream"; let objsToClose: any[]; +jest.mock("../src/common.browser/AudioWorkerUrl", () => ({ + getAudioWorkerUrl: (): string => "speech-processor.js" +})); beforeAll((): void => { // Override inputs, if necessary diff --git a/tsconfig.json b/tsconfig.json index 88756696..15a1c1ac 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "target": "es5", - "module": "commonjs", + "target": "es6", + "module": "esnext", "moduleResolution": "node", "preserveConstEnums": true, "sourceMap": true,