web-speech-cognitive-services 8.0.0-main.5903868 → 8.0.0-main.6cbf0fb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web-speech-cognitive-services.d.mts +217 -65
- package/dist/web-speech-cognitive-services.d.ts +217 -65
- package/dist/web-speech-cognitive-services.development.js +240 -199
- package/dist/web-speech-cognitive-services.development.js.map +1 -1
- package/dist/web-speech-cognitive-services.js +238 -194
- package/dist/web-speech-cognitive-services.js.map +1 -1
- package/dist/web-speech-cognitive-services.mjs +238 -194
- package/dist/web-speech-cognitive-services.mjs.map +1 -1
- package/dist/web-speech-cognitive-services.production.min.js +12 -12
- package/dist/web-speech-cognitive-services.production.min.js.map +1 -1
- package/package.json +2 -2
|
@@ -792,7 +792,7 @@
|
|
|
792
792
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
793
793
|
exports.AudioStreamNodeErrorEvent = exports.AudioStreamNodeDetachedEvent = exports.AudioStreamNodeAttachedEvent = exports.AudioStreamNodeAttachingEvent = exports.AudioStreamNodeEvent = exports.AudioSourceErrorEvent = exports.AudioSourceOffEvent = exports.AudioSourceReadyEvent = exports.AudioSourceInitializingEvent = exports.AudioSourceEvent = void 0;
|
|
794
794
|
var PlatformEvent_js_1 = require_PlatformEvent();
|
|
795
|
-
var
|
|
795
|
+
var AudioSourceEvent2 = class extends PlatformEvent_js_1.PlatformEvent {
|
|
796
796
|
constructor(eventName, audioSourceId, eventType = PlatformEvent_js_1.EventType.Info) {
|
|
797
797
|
super(eventName, eventType);
|
|
798
798
|
this.privAudioSourceId = audioSourceId;
|
|
@@ -801,26 +801,26 @@
|
|
|
801
801
|
return this.privAudioSourceId;
|
|
802
802
|
}
|
|
803
803
|
};
|
|
804
|
-
exports.AudioSourceEvent =
|
|
805
|
-
var AudioSourceInitializingEvent = class extends
|
|
804
|
+
exports.AudioSourceEvent = AudioSourceEvent2;
|
|
805
|
+
var AudioSourceInitializingEvent = class extends AudioSourceEvent2 {
|
|
806
806
|
constructor(audioSourceId) {
|
|
807
807
|
super("AudioSourceInitializingEvent", audioSourceId);
|
|
808
808
|
}
|
|
809
809
|
};
|
|
810
810
|
exports.AudioSourceInitializingEvent = AudioSourceInitializingEvent;
|
|
811
|
-
var AudioSourceReadyEvent = class extends
|
|
811
|
+
var AudioSourceReadyEvent = class extends AudioSourceEvent2 {
|
|
812
812
|
constructor(audioSourceId) {
|
|
813
813
|
super("AudioSourceReadyEvent", audioSourceId);
|
|
814
814
|
}
|
|
815
815
|
};
|
|
816
816
|
exports.AudioSourceReadyEvent = AudioSourceReadyEvent;
|
|
817
|
-
var AudioSourceOffEvent = class extends
|
|
817
|
+
var AudioSourceOffEvent = class extends AudioSourceEvent2 {
|
|
818
818
|
constructor(audioSourceId) {
|
|
819
819
|
super("AudioSourceOffEvent", audioSourceId);
|
|
820
820
|
}
|
|
821
821
|
};
|
|
822
822
|
exports.AudioSourceOffEvent = AudioSourceOffEvent;
|
|
823
|
-
var AudioSourceErrorEvent = class extends
|
|
823
|
+
var AudioSourceErrorEvent = class extends AudioSourceEvent2 {
|
|
824
824
|
constructor(audioSourceId, error) {
|
|
825
825
|
super("AudioSourceErrorEvent", audioSourceId, PlatformEvent_js_1.EventType.Error);
|
|
826
826
|
this.privError = error;
|
|
@@ -830,7 +830,7 @@
|
|
|
830
830
|
}
|
|
831
831
|
};
|
|
832
832
|
exports.AudioSourceErrorEvent = AudioSourceErrorEvent;
|
|
833
|
-
var AudioStreamNodeEvent = class extends
|
|
833
|
+
var AudioStreamNodeEvent = class extends AudioSourceEvent2 {
|
|
834
834
|
constructor(eventName, audioSourceId, audioNodeId) {
|
|
835
835
|
super(eventName, audioSourceId);
|
|
836
836
|
this.privAudioNodeId = audioNodeId;
|
|
@@ -6920,7 +6920,7 @@
|
|
|
6920
6920
|
var Exports_js_2 = require_Exports();
|
|
6921
6921
|
var Contracts_js_1 = require_Contracts();
|
|
6922
6922
|
var Exports_js_3 = require_Exports3();
|
|
6923
|
-
var
|
|
6923
|
+
var SpeechRecognizer4 = class _SpeechRecognizer extends Exports_js_3.Recognizer {
|
|
6924
6924
|
/**
|
|
6925
6925
|
* SpeechRecognizer constructor.
|
|
6926
6926
|
* @constructor
|
|
@@ -7123,7 +7123,7 @@
|
|
|
7123
7123
|
return new Exports_js_1.SpeechServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);
|
|
7124
7124
|
}
|
|
7125
7125
|
};
|
|
7126
|
-
exports.SpeechRecognizer =
|
|
7126
|
+
exports.SpeechRecognizer = SpeechRecognizer4;
|
|
7127
7127
|
}
|
|
7128
7128
|
});
|
|
7129
7129
|
|
|
@@ -23432,41 +23432,6 @@
|
|
|
23432
23432
|
}
|
|
23433
23433
|
});
|
|
23434
23434
|
|
|
23435
|
-
// ../../node_modules/p-defer/index.js
|
|
23436
|
-
function pDefer() {
|
|
23437
|
-
const deferred = {};
|
|
23438
|
-
deferred.promise = new Promise((resolve, reject) => {
|
|
23439
|
-
deferred.resolve = resolve;
|
|
23440
|
-
deferred.reject = reject;
|
|
23441
|
-
});
|
|
23442
|
-
return deferred;
|
|
23443
|
-
}
|
|
23444
|
-
|
|
23445
|
-
// src/Util/createPromiseQueue.js
|
|
23446
|
-
function createPromiseQueue_default() {
|
|
23447
|
-
let shiftDeferred;
|
|
23448
|
-
const queue = [];
|
|
23449
|
-
const push = (value) => {
|
|
23450
|
-
if (shiftDeferred) {
|
|
23451
|
-
const { resolve } = shiftDeferred;
|
|
23452
|
-
shiftDeferred = null;
|
|
23453
|
-
resolve(value);
|
|
23454
|
-
} else {
|
|
23455
|
-
queue.push(value);
|
|
23456
|
-
}
|
|
23457
|
-
};
|
|
23458
|
-
const shift = () => {
|
|
23459
|
-
if (queue.length) {
|
|
23460
|
-
return Promise.resolve(queue.shift());
|
|
23461
|
-
}
|
|
23462
|
-
return (shiftDeferred || (shiftDeferred = pDefer())).promise;
|
|
23463
|
-
};
|
|
23464
|
-
return {
|
|
23465
|
-
push,
|
|
23466
|
-
shift
|
|
23467
|
-
};
|
|
23468
|
-
}
|
|
23469
|
-
|
|
23470
23435
|
// src/SpeechServices/resolveFunctionOrReturnValue.ts
|
|
23471
23436
|
function isFunction(value) {
|
|
23472
23437
|
return typeof value === "function";
|
|
@@ -23475,17 +23440,21 @@
|
|
|
23475
23440
|
return isFunction(fnOrValue) ? fnOrValue() : fnOrValue;
|
|
23476
23441
|
}
|
|
23477
23442
|
|
|
23478
|
-
// src/SpeechServices/patchOptions.
|
|
23443
|
+
// src/SpeechServices/patchOptions.ts
|
|
23479
23444
|
var shouldWarnOnSubscriptionKey = true;
|
|
23480
|
-
function patchOptions({
|
|
23481
|
-
|
|
23482
|
-
|
|
23483
|
-
|
|
23484
|
-
|
|
23485
|
-
|
|
23486
|
-
|
|
23487
|
-
|
|
23488
|
-
|
|
23445
|
+
function patchOptions(init) {
|
|
23446
|
+
const {
|
|
23447
|
+
audioConfig,
|
|
23448
|
+
authorizationToken,
|
|
23449
|
+
enableTelemetry,
|
|
23450
|
+
looseEvent,
|
|
23451
|
+
referenceGrammars,
|
|
23452
|
+
region = "westus",
|
|
23453
|
+
speechRecognitionEndpointId,
|
|
23454
|
+
subscriptionKey,
|
|
23455
|
+
textNormalization
|
|
23456
|
+
} = init;
|
|
23457
|
+
let { credentials, looseEvents } = init;
|
|
23489
23458
|
if (typeof looseEvent !== "undefined") {
|
|
23490
23459
|
console.warn('web-speech-cognitive-services: The option "looseEvent" should be named as "looseEvents".');
|
|
23491
23460
|
looseEvents = looseEvent;
|
|
@@ -23497,11 +23466,12 @@
|
|
|
23497
23466
|
console.warn(
|
|
23498
23467
|
"web-speech-cognitive-services: We are deprecating authorizationToken, region, and subscriptionKey. Please use credentials instead. The deprecated option will be removed on or after 2020-11-14."
|
|
23499
23468
|
);
|
|
23500
|
-
credentials = async () => authorizationToken ? { authorizationToken: await resolveFunctionOrReturnValue(authorizationToken), region } : { region, subscriptionKey: await resolveFunctionOrReturnValue(subscriptionKey) };
|
|
23469
|
+
credentials = async () => typeof init.authorizationToken !== "undefined" ? { authorizationToken: await resolveFunctionOrReturnValue(init.authorizationToken), region } : { region, subscriptionKey: await resolveFunctionOrReturnValue(init.subscriptionKey) };
|
|
23501
23470
|
}
|
|
23502
23471
|
}
|
|
23503
|
-
return {
|
|
23504
|
-
|
|
23472
|
+
return Object.freeze({
|
|
23473
|
+
audioConfig,
|
|
23474
|
+
enableTelemetry,
|
|
23505
23475
|
fetchCredentials: async () => {
|
|
23506
23476
|
const {
|
|
23507
23477
|
authorizationToken: authorizationToken2,
|
|
@@ -23536,21 +23506,23 @@
|
|
|
23536
23506
|
);
|
|
23537
23507
|
shouldWarnOnSubscriptionKey = false;
|
|
23538
23508
|
}
|
|
23539
|
-
|
|
23540
|
-
|
|
23541
|
-
|
|
23542
|
-
|
|
23543
|
-
|
|
23544
|
-
|
|
23545
|
-
|
|
23546
|
-
}
|
|
23547
|
-
return resolvedCredentials;
|
|
23509
|
+
return {
|
|
23510
|
+
...typeof authorizationToken2 !== "undefined" ? { authorizationToken: authorizationToken2 } : { subscriptionKey: subscriptionKey2 },
|
|
23511
|
+
...typeof region2 !== "undefined" ? { region: region2 } : {
|
|
23512
|
+
customVoiceHostname,
|
|
23513
|
+
speechRecognitionHostname,
|
|
23514
|
+
speechSynthesisHostname
|
|
23515
|
+
}
|
|
23516
|
+
};
|
|
23548
23517
|
},
|
|
23549
|
-
looseEvents
|
|
23550
|
-
|
|
23518
|
+
looseEvents: !!looseEvents,
|
|
23519
|
+
referenceGrammars: referenceGrammars && Object.freeze([...referenceGrammars]),
|
|
23520
|
+
speechRecognitionEndpointId,
|
|
23521
|
+
textNormalization
|
|
23522
|
+
});
|
|
23551
23523
|
}
|
|
23552
23524
|
|
|
23553
|
-
// src/SpeechServices/SpeechSDK.
|
|
23525
|
+
// src/SpeechServices/SpeechSDK.ts
|
|
23554
23526
|
var import_microsoft_cognitiveservices_speech = __toESM(require_microsoft_cognitiveservices_speech_sdk());
|
|
23555
23527
|
var SpeechSDK_default = {
|
|
23556
23528
|
AudioConfig: import_microsoft_cognitiveservices_speech.AudioConfig,
|
|
@@ -23560,6 +23532,41 @@
|
|
|
23560
23532
|
SpeechRecognizer: import_microsoft_cognitiveservices_speech.SpeechRecognizer
|
|
23561
23533
|
};
|
|
23562
23534
|
|
|
23535
|
+
// ../../node_modules/p-defer/index.js
|
|
23536
|
+
function pDefer() {
|
|
23537
|
+
const deferred = {};
|
|
23538
|
+
deferred.promise = new Promise((resolve, reject) => {
|
|
23539
|
+
deferred.resolve = resolve;
|
|
23540
|
+
deferred.reject = reject;
|
|
23541
|
+
});
|
|
23542
|
+
return deferred;
|
|
23543
|
+
}
|
|
23544
|
+
|
|
23545
|
+
// src/Util/createPromiseQueue.js
|
|
23546
|
+
function createPromiseQueue_default() {
|
|
23547
|
+
let shiftDeferred;
|
|
23548
|
+
const queue = [];
|
|
23549
|
+
const push = (value) => {
|
|
23550
|
+
if (shiftDeferred) {
|
|
23551
|
+
const { resolve } = shiftDeferred;
|
|
23552
|
+
shiftDeferred = null;
|
|
23553
|
+
resolve(value);
|
|
23554
|
+
} else {
|
|
23555
|
+
queue.push(value);
|
|
23556
|
+
}
|
|
23557
|
+
};
|
|
23558
|
+
const shift = () => {
|
|
23559
|
+
if (queue.length) {
|
|
23560
|
+
return Promise.resolve(queue.shift());
|
|
23561
|
+
}
|
|
23562
|
+
return (shiftDeferred || (shiftDeferred = pDefer())).promise;
|
|
23563
|
+
};
|
|
23564
|
+
return {
|
|
23565
|
+
push,
|
|
23566
|
+
shift
|
|
23567
|
+
};
|
|
23568
|
+
}
|
|
23569
|
+
|
|
23563
23570
|
// src/SpeechServices/SpeechToText/SpeechRecognitionAlternative.ts
|
|
23564
23571
|
var SpeechRecognitionAlternative = class {
|
|
23565
23572
|
constructor({ confidence, transcript }) {
|
|
@@ -23576,7 +23583,7 @@
|
|
|
23576
23583
|
}
|
|
23577
23584
|
};
|
|
23578
23585
|
|
|
23579
|
-
// src/SpeechServices/SpeechToText/FakeArray.ts
|
|
23586
|
+
// src/SpeechServices/SpeechToText/private/FakeArray.ts
|
|
23580
23587
|
var FakeArray = class {
|
|
23581
23588
|
constructor(array) {
|
|
23582
23589
|
if (!array) {
|
|
@@ -23644,7 +23651,15 @@
|
|
|
23644
23651
|
return new SpeechRecognitionResult({ isFinal: false, results: [] });
|
|
23645
23652
|
}
|
|
23646
23653
|
|
|
23647
|
-
// src/SpeechServices/SpeechToText/
|
|
23654
|
+
// src/SpeechServices/SpeechToText/cognitiveServicesAsyncToPromise.ts
|
|
23655
|
+
function cognitiveServicesAsyncToPromise(fn, context = void 0) {
|
|
23656
|
+
return (...args) => (
|
|
23657
|
+
// eslint-disable-next-line prefer-spread
|
|
23658
|
+
new Promise((resolve, reject) => fn.apply(context, [...args, resolve, reject]))
|
|
23659
|
+
);
|
|
23660
|
+
}
|
|
23661
|
+
|
|
23662
|
+
// src/SpeechServices/SpeechToText/private/EventListenerMap.ts
|
|
23648
23663
|
var EventListenerMap = class {
|
|
23649
23664
|
constructor(eventTarget) {
|
|
23650
23665
|
this.#eventTarget = eventTarget;
|
|
@@ -23665,22 +23680,90 @@
|
|
|
23665
23680
|
}
|
|
23666
23681
|
};
|
|
23667
23682
|
|
|
23668
|
-
// src/SpeechServices/SpeechToText/
|
|
23669
|
-
var
|
|
23683
|
+
// src/SpeechServices/SpeechToText/private/prepareAudioConfig.ts
|
|
23684
|
+
var import_AudioSourceEvents = __toESM(require_AudioSourceEvents());
|
|
23685
|
+
|
|
23686
|
+
// src/SpeechServices/SpeechToText/private/averageAmplitude.ts
|
|
23687
|
+
function averageAmplitude(arrayBuffer) {
|
|
23688
|
+
const array = Array.from(new Int16Array(arrayBuffer));
|
|
23689
|
+
return array.reduce((averageAmplitude2, amplitude) => averageAmplitude2 + Math.abs(amplitude), 0) / array.length;
|
|
23690
|
+
}
|
|
23691
|
+
|
|
23692
|
+
// src/SpeechServices/SpeechToText/private/prepareAudioConfig.ts
|
|
23693
|
+
function prepareAudioConfig(audioConfig) {
|
|
23694
|
+
const audioConfigImpl = audioConfig;
|
|
23695
|
+
const originalAttach = audioConfigImpl.attach;
|
|
23696
|
+
const boundOriginalAttach = audioConfigImpl.attach.bind(audioConfigImpl);
|
|
23697
|
+
let firstChunk = false;
|
|
23698
|
+
let muted = false;
|
|
23699
|
+
audioConfigImpl.attach = async () => {
|
|
23700
|
+
const reader = await boundOriginalAttach("");
|
|
23701
|
+
return {
|
|
23702
|
+
...reader,
|
|
23703
|
+
read: async () => {
|
|
23704
|
+
const chunk = await reader.read();
|
|
23705
|
+
if (!firstChunk && averageAmplitude(chunk.buffer) > 150) {
|
|
23706
|
+
audioConfigImpl.events.onEvent(new import_AudioSourceEvents.AudioSourceEvent("FirstAudibleChunk", ""));
|
|
23707
|
+
firstChunk = true;
|
|
23708
|
+
}
|
|
23709
|
+
if (muted) {
|
|
23710
|
+
return { buffer: new ArrayBuffer(0), isEnd: true, timeReceived: Date.now() };
|
|
23711
|
+
}
|
|
23712
|
+
return chunk;
|
|
23713
|
+
}
|
|
23714
|
+
};
|
|
23715
|
+
};
|
|
23716
|
+
return {
|
|
23717
|
+
audioConfig,
|
|
23718
|
+
pause: () => {
|
|
23719
|
+
muted = true;
|
|
23720
|
+
},
|
|
23721
|
+
unprepare: () => {
|
|
23722
|
+
audioConfigImpl.attach = originalAttach;
|
|
23723
|
+
}
|
|
23724
|
+
};
|
|
23725
|
+
}
|
|
23726
|
+
|
|
23727
|
+
// src/SpeechServices/SpeechToText/private/serializeRecognitionResult.ts
|
|
23728
|
+
function serializeRecognitionResult({
|
|
23729
|
+
duration,
|
|
23730
|
+
errorDetails,
|
|
23731
|
+
json,
|
|
23732
|
+
offset,
|
|
23733
|
+
properties,
|
|
23734
|
+
reason,
|
|
23735
|
+
resultId,
|
|
23736
|
+
text
|
|
23737
|
+
}) {
|
|
23738
|
+
return Object.freeze({
|
|
23739
|
+
duration,
|
|
23740
|
+
errorDetails,
|
|
23741
|
+
json: json && JSON.parse(json),
|
|
23742
|
+
offset,
|
|
23743
|
+
properties,
|
|
23744
|
+
reason,
|
|
23745
|
+
resultId,
|
|
23746
|
+
text
|
|
23747
|
+
});
|
|
23748
|
+
}
|
|
23749
|
+
|
|
23750
|
+
// src/SpeechServices/SpeechToText/SpeechGrammarList.ts
|
|
23751
|
+
var SpeechGrammarList = class {
|
|
23670
23752
|
constructor() {
|
|
23671
|
-
this
|
|
23753
|
+
this.#phrases = [];
|
|
23672
23754
|
}
|
|
23673
23755
|
addFromString() {
|
|
23674
23756
|
throw new Error("JSGF is not supported");
|
|
23675
23757
|
}
|
|
23758
|
+
#phrases;
|
|
23676
23759
|
get phrases() {
|
|
23677
|
-
return this
|
|
23760
|
+
return this.#phrases;
|
|
23678
23761
|
}
|
|
23679
23762
|
set phrases(value) {
|
|
23680
23763
|
if (Array.isArray(value)) {
|
|
23681
|
-
this
|
|
23764
|
+
this.#phrases = Object.freeze([...value]);
|
|
23682
23765
|
} else if (typeof value === "string") {
|
|
23683
|
-
this
|
|
23766
|
+
this.#phrases = Object.freeze([value]);
|
|
23684
23767
|
} else {
|
|
23685
23768
|
throw new Error(`The provided value is not an array or of type 'string'`);
|
|
23686
23769
|
}
|
|
@@ -23702,6 +23785,9 @@
|
|
|
23702
23785
|
get message() {
|
|
23703
23786
|
return this.#message;
|
|
23704
23787
|
}
|
|
23788
|
+
get type() {
|
|
23789
|
+
return "error";
|
|
23790
|
+
}
|
|
23705
23791
|
};
|
|
23706
23792
|
|
|
23707
23793
|
// src/SpeechServices/SpeechToText/SpeechRecognitionResultList.ts
|
|
@@ -23732,61 +23818,13 @@
|
|
|
23732
23818
|
get results() {
|
|
23733
23819
|
return this.#results;
|
|
23734
23820
|
}
|
|
23821
|
+
get type() {
|
|
23822
|
+
return super.type;
|
|
23823
|
+
}
|
|
23735
23824
|
};
|
|
23736
23825
|
|
|
23737
|
-
// src/SpeechServices/SpeechToText/
|
|
23738
|
-
var {
|
|
23739
|
-
function serializeRecognitionResult({ duration, errorDetails, json, offset, properties, reason, resultId, text }) {
|
|
23740
|
-
return {
|
|
23741
|
-
duration,
|
|
23742
|
-
errorDetails,
|
|
23743
|
-
json: JSON.parse(json),
|
|
23744
|
-
offset,
|
|
23745
|
-
properties,
|
|
23746
|
-
reason,
|
|
23747
|
-
resultId,
|
|
23748
|
-
text
|
|
23749
|
-
};
|
|
23750
|
-
}
|
|
23751
|
-
function averageAmplitude(arrayBuffer) {
|
|
23752
|
-
const array = new Int16Array(arrayBuffer);
|
|
23753
|
-
return [].reduce.call(array, (averageAmplitude2, amplitude) => averageAmplitude2 + Math.abs(amplitude), 0) / array.length;
|
|
23754
|
-
}
|
|
23755
|
-
function cognitiveServicesAsyncToPromise(fn) {
|
|
23756
|
-
return (...args) => new Promise((resolve, reject) => fn(...args, resolve, reject));
|
|
23757
|
-
}
|
|
23758
|
-
function prepareAudioConfig(audioConfig) {
|
|
23759
|
-
const originalAttach = audioConfig.attach;
|
|
23760
|
-
const boundOriginalAttach = audioConfig.attach.bind(audioConfig);
|
|
23761
|
-
let firstChunk;
|
|
23762
|
-
let muted;
|
|
23763
|
-
audioConfig.attach = async () => {
|
|
23764
|
-
const reader = await boundOriginalAttach();
|
|
23765
|
-
return {
|
|
23766
|
-
...reader,
|
|
23767
|
-
read: async () => {
|
|
23768
|
-
const chunk = await reader.read();
|
|
23769
|
-
if (!firstChunk && averageAmplitude(chunk.buffer) > 150) {
|
|
23770
|
-
audioConfig.events.onEvent({ name: "FirstAudibleChunk" });
|
|
23771
|
-
firstChunk = true;
|
|
23772
|
-
}
|
|
23773
|
-
if (muted) {
|
|
23774
|
-
return { buffer: new ArrayBuffer(0), isEnd: true, timeReceived: Date.now() };
|
|
23775
|
-
}
|
|
23776
|
-
return chunk;
|
|
23777
|
-
}
|
|
23778
|
-
};
|
|
23779
|
-
};
|
|
23780
|
-
return {
|
|
23781
|
-
audioConfig,
|
|
23782
|
-
pause: () => {
|
|
23783
|
-
muted = true;
|
|
23784
|
-
},
|
|
23785
|
-
unprepare: () => {
|
|
23786
|
-
audioConfig.attach = originalAttach;
|
|
23787
|
-
}
|
|
23788
|
-
};
|
|
23789
|
-
}
|
|
23826
|
+
// src/SpeechServices/SpeechToText/createSpeechRecognitionPonyfillFromRecognizer.ts
|
|
23827
|
+
var { ResultReason: ResultReason2, SpeechRecognizer: SpeechRecognizer2 } = SpeechSDK_default;
|
|
23790
23828
|
function createSpeechRecognitionPonyfillFromRecognizer({
|
|
23791
23829
|
createRecognizer,
|
|
23792
23830
|
enableTelemetry,
|
|
@@ -23796,17 +23834,13 @@
|
|
|
23796
23834
|
}) {
|
|
23797
23835
|
SpeechRecognizer2.enableTelemetry(enableTelemetry !== false);
|
|
23798
23836
|
class SpeechRecognition extends EventTarget {
|
|
23799
|
-
|
|
23800
|
-
|
|
23801
|
-
|
|
23802
|
-
|
|
23803
|
-
|
|
23804
|
-
|
|
23805
|
-
|
|
23806
|
-
this.#eventListenerMap = new EventListenerMap(this);
|
|
23807
|
-
}
|
|
23808
|
-
/** @type { import('./SpeechRecognitionEventListenerMap').SpeechRecognitionEventListenerMap } */
|
|
23809
|
-
#eventListenerMap;
|
|
23837
|
+
#continuous = false;
|
|
23838
|
+
#eventListenerMap = new EventListenerMap(this);
|
|
23839
|
+
#grammars = new SpeechGrammarList();
|
|
23840
|
+
#interimResults = false;
|
|
23841
|
+
#lang = typeof window !== "undefined" ? window.document.documentElement.getAttribute("lang") || window.navigator.language : "en-US";
|
|
23842
|
+
// eslint-disable-next-line no-magic-numbers
|
|
23843
|
+
#maxAlternatives = 1;
|
|
23810
23844
|
emitCognitiveServices(type, event) {
|
|
23811
23845
|
this.dispatchEvent(
|
|
23812
23846
|
new SpeechRecognitionEvent("cognitiveservices", {
|
|
@@ -23818,40 +23852,39 @@
|
|
|
23818
23852
|
);
|
|
23819
23853
|
}
|
|
23820
23854
|
get continuous() {
|
|
23821
|
-
return this
|
|
23855
|
+
return this.#continuous;
|
|
23822
23856
|
}
|
|
23823
23857
|
set continuous(value) {
|
|
23824
|
-
this
|
|
23858
|
+
this.#continuous = value;
|
|
23825
23859
|
}
|
|
23826
23860
|
get grammars() {
|
|
23827
|
-
return this
|
|
23861
|
+
return this.#grammars;
|
|
23828
23862
|
}
|
|
23829
23863
|
set grammars(value) {
|
|
23830
|
-
if (value instanceof
|
|
23831
|
-
this
|
|
23864
|
+
if (value instanceof SpeechGrammarList) {
|
|
23865
|
+
this.#grammars = value;
|
|
23832
23866
|
} else {
|
|
23833
23867
|
throw new Error(`The provided value is not of type 'SpeechGrammarList'`);
|
|
23834
23868
|
}
|
|
23835
23869
|
}
|
|
23836
23870
|
get interimResults() {
|
|
23837
|
-
return this
|
|
23871
|
+
return this.#interimResults;
|
|
23838
23872
|
}
|
|
23839
23873
|
set interimResults(value) {
|
|
23840
|
-
this
|
|
23874
|
+
this.#interimResults = value;
|
|
23841
23875
|
}
|
|
23842
23876
|
get maxAlternatives() {
|
|
23843
|
-
return this
|
|
23877
|
+
return this.#maxAlternatives;
|
|
23844
23878
|
}
|
|
23845
23879
|
set maxAlternatives(value) {
|
|
23846
|
-
this
|
|
23880
|
+
this.#maxAlternatives = value;
|
|
23847
23881
|
}
|
|
23848
23882
|
get lang() {
|
|
23849
|
-
return this
|
|
23883
|
+
return this.#lang;
|
|
23850
23884
|
}
|
|
23851
23885
|
set lang(value) {
|
|
23852
|
-
this
|
|
23886
|
+
this.#lang = value;
|
|
23853
23887
|
}
|
|
23854
|
-
/** @type { ((event: SpeechRecognitionEvent<'audioend'>) => void) | undefined } */
|
|
23855
23888
|
get onaudioend() {
|
|
23856
23889
|
return this.#eventListenerMap.getProperty("audioend");
|
|
23857
23890
|
}
|
|
@@ -23879,7 +23912,7 @@
|
|
|
23879
23912
|
set onend(value) {
|
|
23880
23913
|
this.#eventListenerMap.setProperty("end", value);
|
|
23881
23914
|
}
|
|
23882
|
-
/** @type { ((event:
|
|
23915
|
+
/** @type { ((event: SpeechRecognitionErrorEvent) => void) | undefined } */
|
|
23883
23916
|
get onerror() {
|
|
23884
23917
|
return this.#eventListenerMap.getProperty("error");
|
|
23885
23918
|
}
|
|
@@ -23928,6 +23961,8 @@
|
|
|
23928
23961
|
set onstart(value) {
|
|
23929
23962
|
this.#eventListenerMap.setProperty("start", value);
|
|
23930
23963
|
}
|
|
23964
|
+
abort;
|
|
23965
|
+
stop;
|
|
23931
23966
|
start() {
|
|
23932
23967
|
this._startOnce().catch((err) => {
|
|
23933
23968
|
this.dispatchEvent(
|
|
@@ -23937,22 +23972,24 @@
|
|
|
23937
23972
|
}
|
|
23938
23973
|
async _startOnce() {
|
|
23939
23974
|
const recognizer = await createRecognizer(this.lang);
|
|
23940
|
-
const { pause, unprepare } = prepareAudioConfig(recognizer
|
|
23975
|
+
const { pause, unprepare } = prepareAudioConfig(recognizer["audioConfig"]);
|
|
23941
23976
|
try {
|
|
23942
23977
|
const queue = createPromiseQueue_default();
|
|
23943
23978
|
let soundStarted;
|
|
23944
23979
|
let speechStarted;
|
|
23945
23980
|
let stopping;
|
|
23946
|
-
const { detach: detachAudioConfigEvent } = recognizer
|
|
23947
|
-
|
|
23948
|
-
|
|
23949
|
-
|
|
23950
|
-
|
|
23951
|
-
|
|
23952
|
-
|
|
23953
|
-
|
|
23981
|
+
const { detach: detachAudioConfigEvent } = recognizer["audioConfig"].events.attach(
|
|
23982
|
+
(event) => {
|
|
23983
|
+
const { name } = event;
|
|
23984
|
+
if (name === "AudioSourceReadyEvent") {
|
|
23985
|
+
queue.push({ audioSourceReady: {} });
|
|
23986
|
+
} else if (name === "AudioSourceOffEvent") {
|
|
23987
|
+
queue.push({ audioSourceOff: {} });
|
|
23988
|
+
} else if (name === "FirstAudibleChunk") {
|
|
23989
|
+
queue.push({ firstAudibleChunk: {} });
|
|
23990
|
+
}
|
|
23954
23991
|
}
|
|
23955
|
-
|
|
23992
|
+
);
|
|
23956
23993
|
recognizer.canceled = (_, { errorDetails, offset, reason, sessionId }) => {
|
|
23957
23994
|
queue.push({
|
|
23958
23995
|
canceled: {
|
|
@@ -23994,18 +24031,18 @@
|
|
|
23994
24031
|
queue.push({ speechEndDetected: { sessionId } });
|
|
23995
24032
|
};
|
|
23996
24033
|
const { phrases } = this.grammars;
|
|
23997
|
-
const { dynamicGrammar } = recognizer
|
|
23998
|
-
referenceGrammars && referenceGrammars.length && dynamicGrammar.addReferenceGrammar(referenceGrammars);
|
|
23999
|
-
phrases && phrases.length && dynamicGrammar.addPhrase(phrases);
|
|
24000
|
-
await cognitiveServicesAsyncToPromise(recognizer.startContinuousRecognitionAsync
|
|
24001
|
-
if (recognizer.stopContinuousRecognitionAsync) {
|
|
24034
|
+
const { dynamicGrammar } = recognizer["privReco"];
|
|
24035
|
+
referenceGrammars && referenceGrammars.length && dynamicGrammar.addReferenceGrammar([...referenceGrammars]);
|
|
24036
|
+
phrases && phrases.length && dynamicGrammar.addPhrase([...phrases]);
|
|
24037
|
+
await cognitiveServicesAsyncToPromise(recognizer.startContinuousRecognitionAsync, recognizer)();
|
|
24038
|
+
if (typeof recognizer.stopContinuousRecognitionAsync === "function") {
|
|
24002
24039
|
this.abort = () => queue.push({ abort: {} });
|
|
24003
24040
|
this.stop = () => queue.push({ stop: {} });
|
|
24004
24041
|
} else {
|
|
24005
24042
|
this.abort = this.stop = void 0;
|
|
24006
24043
|
}
|
|
24007
24044
|
let audioStarted;
|
|
24008
|
-
let finalEvent;
|
|
24045
|
+
let finalEvent = void 0;
|
|
24009
24046
|
let finalizedResults = [];
|
|
24010
24047
|
for (let loop = 0; !stopping || audioStarted; loop++) {
|
|
24011
24048
|
const event = await queue.shift();
|
|
@@ -24048,7 +24085,7 @@
|
|
|
24048
24085
|
stopping = "stop";
|
|
24049
24086
|
}
|
|
24050
24087
|
if (abort && recognizer.stopContinuousRecognitionAsync) {
|
|
24051
|
-
await cognitiveServicesAsyncToPromise(recognizer.stopContinuousRecognitionAsync
|
|
24088
|
+
await cognitiveServicesAsyncToPromise(recognizer.stopContinuousRecognitionAsync, recognizer)();
|
|
24052
24089
|
}
|
|
24053
24090
|
} else if (audioSourceReady) {
|
|
24054
24091
|
this.dispatchEvent(new SpeechRecognitionEvent("audiostart"));
|
|
@@ -24065,8 +24102,13 @@
|
|
|
24065
24102
|
} else if (stopping !== "abort") {
|
|
24066
24103
|
if (recognized && recognized.result && recognized.result.reason === ResultReason2.NoMatch) {
|
|
24067
24104
|
if (!this.continuous || stopping === "stop") {
|
|
24068
|
-
finalEvent = new SpeechRecognitionEvent("result", {
|
|
24069
|
-
|
|
24105
|
+
finalEvent = new SpeechRecognitionEvent("result", {
|
|
24106
|
+
results: new SpeechRecognitionResultList(finalizedResults)
|
|
24107
|
+
});
|
|
24108
|
+
recognizer.stopContinuousRecognitionAsync && await cognitiveServicesAsyncToPromise(
|
|
24109
|
+
recognizer.stopContinuousRecognitionAsync,
|
|
24110
|
+
recognizer
|
|
24111
|
+
)();
|
|
24070
24112
|
break;
|
|
24071
24113
|
}
|
|
24072
24114
|
} else if (recognized || recognizing) {
|
|
@@ -24087,7 +24129,7 @@
|
|
|
24087
24129
|
maxAlternatives: this.maxAlternatives,
|
|
24088
24130
|
textNormalization
|
|
24089
24131
|
});
|
|
24090
|
-
const recognizable = !!result[0]
|
|
24132
|
+
const recognizable = !!result[0]?.transcript;
|
|
24091
24133
|
if (recognizable) {
|
|
24092
24134
|
finalizedResults = [...finalizedResults, result];
|
|
24093
24135
|
this.continuous && this.dispatchEvent(
|
|
@@ -24104,7 +24146,7 @@
|
|
|
24104
24146
|
});
|
|
24105
24147
|
}
|
|
24106
24148
|
if ((!this.continuous || stopping === "stop") && recognizer.stopContinuousRecognitionAsync) {
|
|
24107
|
-
await cognitiveServicesAsyncToPromise(recognizer.stopContinuousRecognitionAsync
|
|
24149
|
+
await cognitiveServicesAsyncToPromise(recognizer.stopContinuousRecognitionAsync, recognizer)();
|
|
24108
24150
|
}
|
|
24109
24151
|
if (looseEvents && finalEvent && recognizable) {
|
|
24110
24152
|
this.dispatchEvent(finalEvent);
|
|
@@ -24148,17 +24190,20 @@
|
|
|
24148
24190
|
throw err;
|
|
24149
24191
|
} finally {
|
|
24150
24192
|
unprepare();
|
|
24151
|
-
recognizer
|
|
24193
|
+
recognizer["dispose"](false);
|
|
24152
24194
|
}
|
|
24153
24195
|
}
|
|
24154
24196
|
}
|
|
24155
24197
|
return {
|
|
24156
|
-
SpeechGrammarList
|
|
24198
|
+
SpeechGrammarList,
|
|
24157
24199
|
SpeechRecognition,
|
|
24158
24200
|
SpeechRecognitionEvent
|
|
24159
24201
|
};
|
|
24160
24202
|
}
|
|
24161
|
-
|
|
24203
|
+
|
|
24204
|
+
// src/SpeechServices/SpeechToText/createSpeechRecognitionPonyfill.ts
|
|
24205
|
+
var { AudioConfig: AudioConfig2, OutputFormat: OutputFormat2, SpeechConfig: SpeechConfig2, SpeechRecognizer: SpeechRecognizer3 } = SpeechSDK_default;
|
|
24206
|
+
function createSpeechRecognitionPonyfill(options) {
|
|
24162
24207
|
const {
|
|
24163
24208
|
audioConfig = AudioConfig2.fromDefaultMicrophoneInput(),
|
|
24164
24209
|
// We set telemetry to true to honor the default telemetry settings of Speech SDK
|
|
@@ -24171,44 +24216,40 @@
|
|
|
24171
24216
|
textNormalization = "display"
|
|
24172
24217
|
} = patchOptions(options);
|
|
24173
24218
|
if (!audioConfig && (!window.navigator.mediaDevices || !window.navigator.mediaDevices.getUserMedia)) {
|
|
24174
|
-
|
|
24175
|
-
"web-speech-cognitive-services: This browser does not support
|
|
24219
|
+
throw new Error(
|
|
24220
|
+
"web-speech-cognitive-services: This browser does not support Media Capture and Streams API and it will not work with Cognitive Services Speech Services."
|
|
24176
24221
|
);
|
|
24177
|
-
return {};
|
|
24178
24222
|
}
|
|
24179
24223
|
const createRecognizer = async (lang) => {
|
|
24180
|
-
const
|
|
24224
|
+
const credentials = await fetchCredentials();
|
|
24181
24225
|
let speechConfig;
|
|
24182
|
-
if (speechRecognitionHostname) {
|
|
24183
|
-
const host =
|
|
24184
|
-
|
|
24226
|
+
if (typeof credentials.speechRecognitionHostname !== "undefined") {
|
|
24227
|
+
const host = new URL("wss://hostname:443");
|
|
24228
|
+
host.hostname = credentials.speechRecognitionHostname;
|
|
24229
|
+
if (credentials.authorizationToken) {
|
|
24185
24230
|
speechConfig = SpeechConfig2.fromHost(host);
|
|
24186
|
-
speechConfig.authorizationToken = authorizationToken;
|
|
24231
|
+
speechConfig.authorizationToken = credentials.authorizationToken;
|
|
24187
24232
|
} else {
|
|
24188
|
-
speechConfig = SpeechConfig2.fromHost(host, subscriptionKey);
|
|
24233
|
+
speechConfig = SpeechConfig2.fromHost(host, credentials.subscriptionKey);
|
|
24189
24234
|
}
|
|
24190
24235
|
} else {
|
|
24191
|
-
speechConfig = authorizationToken ? SpeechConfig2.fromAuthorizationToken(authorizationToken, region) : SpeechConfig2.fromSubscription(subscriptionKey, region);
|
|
24236
|
+
speechConfig = typeof credentials.authorizationToken !== "undefined" ? SpeechConfig2.fromAuthorizationToken(credentials.authorizationToken, credentials.region) : SpeechConfig2.fromSubscription(credentials.subscriptionKey, credentials.region);
|
|
24192
24237
|
}
|
|
24193
24238
|
if (speechRecognitionEndpointId) {
|
|
24194
24239
|
speechConfig.endpointId = speechRecognitionEndpointId;
|
|
24195
24240
|
}
|
|
24196
24241
|
speechConfig.outputFormat = OutputFormat2.Detailed;
|
|
24197
24242
|
speechConfig.speechRecognitionLanguage = lang || "en-US";
|
|
24198
|
-
return new
|
|
24243
|
+
return new SpeechRecognizer3(speechConfig, audioConfig);
|
|
24199
24244
|
};
|
|
24200
24245
|
return createSpeechRecognitionPonyfillFromRecognizer({
|
|
24201
|
-
audioConfig,
|
|
24202
24246
|
createRecognizer,
|
|
24203
24247
|
enableTelemetry,
|
|
24204
24248
|
looseEvents,
|
|
24205
24249
|
referenceGrammars,
|
|
24206
24250
|
textNormalization
|
|
24207
24251
|
});
|
|
24208
|
-
}
|
|
24209
|
-
|
|
24210
|
-
// src/SpeechServices/SpeechToText.js
|
|
24211
|
-
var SpeechToText_default = createSpeechRecognitionPonyfill_default;
|
|
24252
|
+
}
|
|
24212
24253
|
|
|
24213
24254
|
// ../../node_modules/event-target-shim/index.mjs
|
|
24214
24255
|
function assertType(condition, message, ...args) {
|
|
@@ -25675,16 +25716,16 @@
|
|
|
25675
25716
|
// src/SpeechServices/TextToSpeech.js
|
|
25676
25717
|
var TextToSpeech_default = createSpeechSynthesisPonyfill_default;
|
|
25677
25718
|
|
|
25678
|
-
// src/SpeechServices.
|
|
25679
|
-
function createSpeechServicesPonyfill(options = {}
|
|
25719
|
+
// src/SpeechServices.ts
|
|
25720
|
+
function createSpeechServicesPonyfill(options = {}) {
|
|
25680
25721
|
return {
|
|
25681
|
-
...
|
|
25682
|
-
...TextToSpeech_default(options
|
|
25722
|
+
...createSpeechRecognitionPonyfill(options),
|
|
25723
|
+
...TextToSpeech_default(options)
|
|
25683
25724
|
};
|
|
25684
25725
|
}
|
|
25685
25726
|
var meta = document.createElement("meta");
|
|
25686
25727
|
meta.setAttribute("name", "web-speech-cognitive-services");
|
|
25687
|
-
meta.setAttribute("content", `version=${"8.0.0-main.
|
|
25728
|
+
meta.setAttribute("content", `version=${"8.0.0-main.6cbf0fb"}`);
|
|
25688
25729
|
document.head.appendChild(meta);
|
|
25689
25730
|
|
|
25690
25731
|
// src/index.umd.js
|