web-speech-cognitive-services 8.0.1-main.8743165 → 8.1.1-main.3d23aad
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 +35 -20
- package/dist/web-speech-cognitive-services.d.ts +35 -20
- package/dist/web-speech-cognitive-services.development.js +843 -172
- package/dist/web-speech-cognitive-services.development.js.map +1 -1
- package/dist/web-speech-cognitive-services.js +141 -81
- package/dist/web-speech-cognitive-services.js.map +1 -1
- package/dist/web-speech-cognitive-services.mjs +147 -87
- 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 +4 -3
|
@@ -38,6 +38,12 @@ __export(src_exports, {
|
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(src_exports);
|
|
40
40
|
|
|
41
|
+
// src/SpeechServices/SpeechToText/createSpeechRecognitionPonyfill.ts
|
|
42
|
+
var import_microsoft_cognitiveservices_speech_sdk = require("microsoft-cognitiveservices-speech-sdk");
|
|
43
|
+
|
|
44
|
+
// src/SpeechServices/patchOptions.ts
|
|
45
|
+
var import_valibot8 = require("valibot");
|
|
46
|
+
|
|
41
47
|
// src/SpeechServices/resolveFunctionOrReturnValue.ts
|
|
42
48
|
function isFunction(value) {
|
|
43
49
|
return typeof value === "function";
|
|
@@ -46,97 +52,145 @@ function resolveFunctionOrReturnValue(fnOrValue) {
|
|
|
46
52
|
return isFunction(fnOrValue) ? fnOrValue() : fnOrValue;
|
|
47
53
|
}
|
|
48
54
|
|
|
55
|
+
// src/SpeechServices/SpeechSDK.ts
|
|
56
|
+
var import_microsoft_cognitiveservices_speech = require("microsoft-cognitiveservices-speech-sdk/distrib/lib/microsoft.cognitiveservices.speech.sdk");
|
|
57
|
+
var SpeechSDK_default = {
|
|
58
|
+
AudioConfig: import_microsoft_cognitiveservices_speech.AudioConfig,
|
|
59
|
+
OutputFormat: import_microsoft_cognitiveservices_speech.OutputFormat,
|
|
60
|
+
ResultReason: import_microsoft_cognitiveservices_speech.ResultReason,
|
|
61
|
+
SpeechConfig: import_microsoft_cognitiveservices_speech.SpeechConfig,
|
|
62
|
+
SpeechRecognizer: import_microsoft_cognitiveservices_speech.SpeechRecognizer
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/SpeechServices/SpeechToText/validation/credentialsSchema.ts
|
|
66
|
+
var import_valibot = require("valibot");
|
|
67
|
+
var credentialsSchema = (0, import_valibot.pipe)(
|
|
68
|
+
(0, import_valibot.intersect)([
|
|
69
|
+
(0, import_valibot.union)(
|
|
70
|
+
[
|
|
71
|
+
(0, import_valibot.object)({
|
|
72
|
+
authorizationToken: (0, import_valibot.string)(),
|
|
73
|
+
subscriptionKey: (0, import_valibot.optional)((0, import_valibot.undefined_)('"subscriptionKey" must be unset when "authorizationToken" is set.'))
|
|
74
|
+
}),
|
|
75
|
+
(0, import_valibot.object)({
|
|
76
|
+
authorizationToken: (0, import_valibot.optional)((0, import_valibot.undefined_)('"authorizationToken" must be unset when "subscriptionKey" is set.')),
|
|
77
|
+
subscriptionKey: (0, import_valibot.string)()
|
|
78
|
+
})
|
|
79
|
+
],
|
|
80
|
+
'The object must either have either "authorizationToken" or "subscriptionKey" set, but not both.'
|
|
81
|
+
),
|
|
82
|
+
(0, import_valibot.union)(
|
|
83
|
+
[
|
|
84
|
+
(0, import_valibot.object)({
|
|
85
|
+
customVoiceHostname: (0, import_valibot.optional)((0, import_valibot.undefined_)('"customVoiceHostname" must be unest when "region" is set.')),
|
|
86
|
+
region: (0, import_valibot.string)(),
|
|
87
|
+
speechRecognitionHostname: (0, import_valibot.optional)(
|
|
88
|
+
(0, import_valibot.undefined_)('"speechRecognitionHostname" must be unest when "region" is set.')
|
|
89
|
+
),
|
|
90
|
+
speechSynthesisHostname: (0, import_valibot.optional)((0, import_valibot.undefined_)('"speechSynthesisHostname" must be unest when "region" is set.'))
|
|
91
|
+
}),
|
|
92
|
+
(0, import_valibot.object)({
|
|
93
|
+
customVoiceHostname: (0, import_valibot.optional)((0, import_valibot.union)([(0, import_valibot.string)(), (0, import_valibot.undefined_)()])),
|
|
94
|
+
region: (0, import_valibot.optional)((0, import_valibot.undefined_)('"region" must be unset when "*Hostname" is set.')),
|
|
95
|
+
speechRecognitionHostname: (0, import_valibot.string)(),
|
|
96
|
+
speechSynthesisHostname: (0, import_valibot.string)()
|
|
97
|
+
})
|
|
98
|
+
],
|
|
99
|
+
'The object must either have either "region" or "*Hostname" set, but not both.'
|
|
100
|
+
)
|
|
101
|
+
]),
|
|
102
|
+
(0, import_valibot.readonly)()
|
|
103
|
+
);
|
|
104
|
+
var credentialsSchema_default = credentialsSchema;
|
|
105
|
+
|
|
106
|
+
// src/SpeechServices/SpeechToText/validation/enableTelemetrySchema.ts
|
|
107
|
+
var import_valibot2 = require("valibot");
|
|
108
|
+
var enableTelemetrySchema = (0, import_valibot2.optional)((0, import_valibot2.boolean)());
|
|
109
|
+
var enableTelemetrySchema_default = enableTelemetrySchema;
|
|
110
|
+
|
|
111
|
+
// src/SpeechServices/SpeechToText/validation/initialSilenceTimeoutSchema.ts
|
|
112
|
+
var import_valibot3 = require("valibot");
|
|
113
|
+
var initialSilenceTimeoutSchema = (0, import_valibot3.optional)((0, import_valibot3.pipe)((0, import_valibot3.number)(), (0, import_valibot3.minValue)(1), (0, import_valibot3.maxValue)(6e4)));
|
|
114
|
+
var initialSilenceTimeoutSchema_default = initialSilenceTimeoutSchema;
|
|
115
|
+
|
|
116
|
+
// src/SpeechServices/SpeechToText/validation/looseEventsSchema.ts
|
|
117
|
+
var import_valibot4 = require("valibot");
|
|
118
|
+
var looseEventsSchema = (0, import_valibot4.optional)((0, import_valibot4.boolean)(), false);
|
|
119
|
+
var looseEventsSchema_default = looseEventsSchema;
|
|
120
|
+
|
|
121
|
+
// src/SpeechServices/SpeechToText/validation/referenceGrammarsSchema.ts
|
|
122
|
+
var import_valibot5 = require("valibot");
|
|
123
|
+
var referenceGrammarsSchema = (0, import_valibot5.pipe)(
|
|
124
|
+
(0, import_valibot5.optional)((0, import_valibot5.array)((0, import_valibot5.string)()), []),
|
|
125
|
+
// any(),
|
|
126
|
+
// array(string()),
|
|
127
|
+
// transform<string[], readonly string[]>(value => (Object.isFrozen(value) ? value : Object.freeze([...value])))
|
|
128
|
+
(0, import_valibot5.transform)((value) => Object.isFrozen(value) ? value : Object.freeze([...value]))
|
|
129
|
+
);
|
|
130
|
+
var referenceGrammarsSchema_default = referenceGrammarsSchema;
|
|
131
|
+
|
|
132
|
+
// src/SpeechServices/SpeechToText/validation/speechRecognitionEndpointIdSchema.ts
|
|
133
|
+
var import_valibot6 = require("valibot");
|
|
134
|
+
var speechRecognitionEndpointIdSchema = (0, import_valibot6.optional)((0, import_valibot6.string)());
|
|
135
|
+
var speechRecognitionEndpointIdSchema_default = speechRecognitionEndpointIdSchema;
|
|
136
|
+
|
|
137
|
+
// src/SpeechServices/SpeechToText/validation/textNormalizationSchema.ts
|
|
138
|
+
var import_valibot7 = require("valibot");
|
|
139
|
+
var textNormalizationSchema = (0, import_valibot7.optional)(
|
|
140
|
+
(0, import_valibot7.enum_)({
|
|
141
|
+
display: "display",
|
|
142
|
+
itn: "itn",
|
|
143
|
+
lexical: "lexical",
|
|
144
|
+
maskeditn: "maskeditn"
|
|
145
|
+
}),
|
|
146
|
+
"display"
|
|
147
|
+
);
|
|
148
|
+
var textNormalizationSchema_default = textNormalizationSchema;
|
|
149
|
+
|
|
49
150
|
// src/SpeechServices/patchOptions.ts
|
|
151
|
+
var { AudioConfig: AudioConfig2 } = SpeechSDK_default;
|
|
50
152
|
var shouldWarnOnSubscriptionKey = true;
|
|
51
153
|
function patchOptions(init) {
|
|
52
154
|
const {
|
|
53
155
|
audioConfig,
|
|
54
|
-
|
|
156
|
+
credentials,
|
|
55
157
|
enableTelemetry,
|
|
158
|
+
initialSilenceTimeout,
|
|
56
159
|
looseEvent,
|
|
57
160
|
referenceGrammars,
|
|
58
|
-
region = "westus",
|
|
59
161
|
speechRecognitionEndpointId,
|
|
60
|
-
subscriptionKey,
|
|
61
162
|
textNormalization
|
|
62
163
|
} = init;
|
|
63
|
-
let {
|
|
164
|
+
let { looseEvents } = init;
|
|
64
165
|
if (typeof looseEvent !== "undefined") {
|
|
65
166
|
console.warn('web-speech-cognitive-services: The option "looseEvent" should be named as "looseEvents".');
|
|
66
167
|
looseEvents = looseEvent;
|
|
67
168
|
}
|
|
68
|
-
if (!credentials) {
|
|
69
|
-
if (!authorizationToken && !subscriptionKey) {
|
|
70
|
-
throw new Error("web-speech-cognitive-services: Credentials must be specified.");
|
|
71
|
-
} else {
|
|
72
|
-
console.warn(
|
|
73
|
-
"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."
|
|
74
|
-
);
|
|
75
|
-
credentials = async () => typeof init.authorizationToken !== "undefined" ? { authorizationToken: await resolveFunctionOrReturnValue(init.authorizationToken), region } : { region, subscriptionKey: await resolveFunctionOrReturnValue(init.subscriptionKey) };
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
169
|
return Object.freeze({
|
|
79
|
-
audioConfig,
|
|
80
|
-
|
|
170
|
+
audioConfig: audioConfig || AudioConfig2.fromDefaultMicrophoneInput(),
|
|
171
|
+
// We set telemetry to true to honor the default telemetry settings of Speech SDK
|
|
172
|
+
// https://github.com/Microsoft/cognitive-services-speech-sdk-js#data--telemetry
|
|
173
|
+
enableTelemetry: (0, import_valibot8.parse)(enableTelemetrySchema_default, enableTelemetry),
|
|
81
174
|
fetchCredentials: async () => {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
customVoiceHostname,
|
|
85
|
-
region: region2,
|
|
86
|
-
speechRecognitionHostname,
|
|
87
|
-
speechSynthesisHostname,
|
|
88
|
-
subscriptionKey: subscriptionKey2
|
|
89
|
-
} = await resolveFunctionOrReturnValue(credentials);
|
|
90
|
-
if (!authorizationToken2 && !subscriptionKey2 || authorizationToken2 && subscriptionKey2) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
'web-speech-cognitive-services: Either "authorizationToken" or "subscriptionKey" must be provided.'
|
|
93
|
-
);
|
|
94
|
-
} else if (!region2 && !(speechRecognitionHostname && speechSynthesisHostname)) {
|
|
95
|
-
throw new Error(
|
|
96
|
-
'web-speech-cognitive-services: Either "region" or "speechRecognitionHostname" and "speechSynthesisHostname" must be set.'
|
|
97
|
-
);
|
|
98
|
-
} else if (region2 && (customVoiceHostname || speechRecognitionHostname || speechSynthesisHostname)) {
|
|
99
|
-
throw new Error(
|
|
100
|
-
'web-speech-cognitive-services: Only either "region" or "customVoiceHostname", "speechRecognitionHostname" and "speechSynthesisHostname" can be set.'
|
|
101
|
-
);
|
|
102
|
-
} else if (authorizationToken2) {
|
|
103
|
-
if (typeof authorizationToken2 !== "string") {
|
|
104
|
-
throw new Error('web-speech-cognitive-services: "authorizationToken" must be a string.');
|
|
105
|
-
}
|
|
106
|
-
} else if (typeof subscriptionKey2 !== "string") {
|
|
107
|
-
throw new Error('web-speech-cognitive-services: "subscriptionKey" must be a string.');
|
|
108
|
-
}
|
|
109
|
-
if (shouldWarnOnSubscriptionKey && subscriptionKey2) {
|
|
175
|
+
const parsedCredentials = (0, import_valibot8.parse)(credentialsSchema_default, await resolveFunctionOrReturnValue(credentials));
|
|
176
|
+
if (shouldWarnOnSubscriptionKey && parsedCredentials.subscriptionKey) {
|
|
110
177
|
console.warn(
|
|
111
178
|
"web-speech-cognitive-services: In production environment, subscription key should not be used, authorization token should be used instead."
|
|
112
179
|
);
|
|
113
180
|
shouldWarnOnSubscriptionKey = false;
|
|
114
181
|
}
|
|
115
|
-
return
|
|
116
|
-
...typeof authorizationToken2 !== "undefined" ? { authorizationToken: authorizationToken2 } : { subscriptionKey: subscriptionKey2 },
|
|
117
|
-
...typeof region2 !== "undefined" ? { region: region2 } : {
|
|
118
|
-
customVoiceHostname,
|
|
119
|
-
speechRecognitionHostname,
|
|
120
|
-
speechSynthesisHostname
|
|
121
|
-
}
|
|
122
|
-
};
|
|
182
|
+
return parsedCredentials;
|
|
123
183
|
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
184
|
+
initialSilenceTimeout: (0, import_valibot8.parse)(initialSilenceTimeoutSchema_default, initialSilenceTimeout),
|
|
185
|
+
looseEvents: (0, import_valibot8.parse)(looseEventsSchema_default, looseEvents),
|
|
186
|
+
referenceGrammars: (0, import_valibot8.parse)(referenceGrammarsSchema_default, referenceGrammars),
|
|
187
|
+
speechRecognitionEndpointId: (0, import_valibot8.parse)(speechRecognitionEndpointIdSchema_default, speechRecognitionEndpointId),
|
|
188
|
+
textNormalization: (0, import_valibot8.parse)(textNormalizationSchema_default, textNormalization)
|
|
128
189
|
});
|
|
129
190
|
}
|
|
130
191
|
|
|
131
|
-
// src/SpeechServices/
|
|
132
|
-
var
|
|
133
|
-
var SpeechSDK_default = {
|
|
134
|
-
AudioConfig: import_microsoft_cognitiveservices_speech.AudioConfig,
|
|
135
|
-
OutputFormat: import_microsoft_cognitiveservices_speech.OutputFormat,
|
|
136
|
-
ResultReason: import_microsoft_cognitiveservices_speech.ResultReason,
|
|
137
|
-
SpeechConfig: import_microsoft_cognitiveservices_speech.SpeechConfig,
|
|
138
|
-
SpeechRecognizer: import_microsoft_cognitiveservices_speech.SpeechRecognizer
|
|
139
|
-
};
|
|
192
|
+
// src/SpeechServices/SpeechToText/createSpeechRecognitionPonyfillFromRecognizer.ts
|
|
193
|
+
var import_valibot9 = require("valibot");
|
|
140
194
|
|
|
141
195
|
// ../../node_modules/p-defer/index.js
|
|
142
196
|
function pDefer() {
|
|
@@ -191,16 +245,16 @@ var SpeechRecognitionAlternative = class {
|
|
|
191
245
|
|
|
192
246
|
// src/SpeechServices/SpeechToText/private/FakeArray.ts
|
|
193
247
|
var FakeArray = class {
|
|
194
|
-
constructor(
|
|
195
|
-
if (!
|
|
248
|
+
constructor(array2) {
|
|
249
|
+
if (!array2) {
|
|
196
250
|
throw new Error("array must be set.");
|
|
197
251
|
}
|
|
198
|
-
this.#array =
|
|
199
|
-
for (const key in
|
|
252
|
+
this.#array = array2;
|
|
253
|
+
for (const key in array2) {
|
|
200
254
|
Object.defineProperty(this, key, {
|
|
201
255
|
enumerable: true,
|
|
202
256
|
get() {
|
|
203
|
-
return
|
|
257
|
+
return array2[key];
|
|
204
258
|
}
|
|
205
259
|
});
|
|
206
260
|
}
|
|
@@ -291,8 +345,8 @@ var import_AudioSourceEvents = require("microsoft-cognitiveservices-speech-sdk/d
|
|
|
291
345
|
|
|
292
346
|
// src/SpeechServices/SpeechToText/private/averageAmplitude.ts
|
|
293
347
|
function averageAmplitude(arrayBuffer) {
|
|
294
|
-
const
|
|
295
|
-
return
|
|
348
|
+
const array2 = Array.from(new Int16Array(arrayBuffer));
|
|
349
|
+
return array2.reduce((averageAmplitude2, amplitude) => averageAmplitude2 + Math.abs(amplitude), 0) / array2.length;
|
|
296
350
|
}
|
|
297
351
|
|
|
298
352
|
// src/SpeechServices/SpeechToText/private/prepareAudioConfig.ts
|
|
@@ -440,6 +494,7 @@ var SpeechRecognitionEvent = class extends Event {
|
|
|
440
494
|
|
|
441
495
|
// src/SpeechServices/SpeechToText/createSpeechRecognitionPonyfillFromRecognizer.ts
|
|
442
496
|
var { ResultReason: ResultReason2, SpeechRecognizer: SpeechRecognizer2 } = SpeechSDK_default;
|
|
497
|
+
var enableTelemetrySchema2 = (0, import_valibot9.union)([(0, import_valibot9.boolean)(), (0, import_valibot9.undefined_)()]);
|
|
443
498
|
function createSpeechRecognitionPonyfillFromRecognizer({
|
|
444
499
|
createRecognizer,
|
|
445
500
|
enableTelemetry,
|
|
@@ -447,7 +502,12 @@ function createSpeechRecognitionPonyfillFromRecognizer({
|
|
|
447
502
|
referenceGrammars,
|
|
448
503
|
textNormalization
|
|
449
504
|
}) {
|
|
450
|
-
|
|
505
|
+
createRecognizer = (0, import_valibot9.parse)((0, import_valibot9.function_)(), createRecognizer);
|
|
506
|
+
enableTelemetry = (0, import_valibot9.parse)(enableTelemetrySchema2, enableTelemetry);
|
|
507
|
+
looseEvents = (0, import_valibot9.parse)((0, import_valibot9.boolean)(), looseEvents);
|
|
508
|
+
referenceGrammars = (0, import_valibot9.parse)(referenceGrammarsSchema_default, referenceGrammars);
|
|
509
|
+
textNormalization = (0, import_valibot9.parse)(textNormalizationSchema_default, textNormalization);
|
|
510
|
+
typeof enableTelemetry !== "undefined" && SpeechRecognizer2.enableTelemetry(enableTelemetry);
|
|
451
511
|
class SpeechRecognition extends EventTarget {
|
|
452
512
|
#continuous = false;
|
|
453
513
|
#eventListenerMap = new EventListenerMap(this);
|
|
@@ -817,18 +877,17 @@ function createSpeechRecognitionPonyfillFromRecognizer({
|
|
|
817
877
|
}
|
|
818
878
|
|
|
819
879
|
// src/SpeechServices/SpeechToText/createSpeechRecognitionPonyfill.ts
|
|
820
|
-
var {
|
|
880
|
+
var { OutputFormat: OutputFormat2, SpeechConfig: SpeechConfig2, SpeechRecognizer: SpeechRecognizer3 } = SpeechSDK_default;
|
|
821
881
|
function createSpeechRecognitionPonyfill(options) {
|
|
822
882
|
const {
|
|
823
|
-
audioConfig
|
|
824
|
-
|
|
825
|
-
// https://github.com/Microsoft/cognitive-services-speech-sdk-js#data--telemetry
|
|
826
|
-
enableTelemetry = true,
|
|
883
|
+
audioConfig,
|
|
884
|
+
enableTelemetry,
|
|
827
885
|
fetchCredentials,
|
|
886
|
+
initialSilenceTimeout,
|
|
828
887
|
looseEvents,
|
|
829
888
|
referenceGrammars,
|
|
830
889
|
speechRecognitionEndpointId,
|
|
831
|
-
textNormalization
|
|
890
|
+
textNormalization
|
|
832
891
|
} = patchOptions(options);
|
|
833
892
|
if (!audioConfig && (!window.navigator.mediaDevices || !window.navigator.mediaDevices.getUserMedia)) {
|
|
834
893
|
throw new Error(
|
|
@@ -839,7 +898,7 @@ function createSpeechRecognitionPonyfill(options) {
|
|
|
839
898
|
const credentials = await fetchCredentials();
|
|
840
899
|
let speechConfig;
|
|
841
900
|
if (typeof credentials.speechRecognitionHostname !== "undefined") {
|
|
842
|
-
const host = new URL("wss://
|
|
901
|
+
const host = new URL("wss://localhost:443");
|
|
843
902
|
host.hostname = credentials.speechRecognitionHostname;
|
|
844
903
|
if (credentials.authorizationToken) {
|
|
845
904
|
speechConfig = SpeechConfig2.fromHost(host);
|
|
@@ -855,6 +914,7 @@ function createSpeechRecognitionPonyfill(options) {
|
|
|
855
914
|
}
|
|
856
915
|
speechConfig.outputFormat = OutputFormat2.Detailed;
|
|
857
916
|
speechConfig.speechRecognitionLanguage = lang || "en-US";
|
|
917
|
+
typeof initialSilenceTimeout === "number" && speechConfig.setProperty(import_microsoft_cognitiveservices_speech_sdk.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, "" + initialSilenceTimeout);
|
|
858
918
|
return new SpeechRecognizer3(speechConfig, audioConfig);
|
|
859
919
|
};
|
|
860
920
|
return createSpeechRecognitionPonyfillFromRecognizer({
|
|
@@ -1396,7 +1456,7 @@ function createSpeechServicesPonyfill(options = {}) {
|
|
|
1396
1456
|
}
|
|
1397
1457
|
var meta = document.createElement("meta");
|
|
1398
1458
|
meta.setAttribute("name", "web-speech-cognitive-services");
|
|
1399
|
-
meta.setAttribute("content", `version=${"8.
|
|
1459
|
+
meta.setAttribute("content", `version=${"8.1.1-main.3d23aad"}`);
|
|
1400
1460
|
document.head.appendChild(meta);
|
|
1401
1461
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1402
1462
|
0 && (module.exports = {
|