speechstate 2.0.0-beta.4 → 2.0.0-beta.6
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/README.org +12 -9
- package/dist/asr.d.ts +66 -3
- package/dist/asr.d.ts.map +1 -1
- package/dist/asr.js +185 -81
- package/dist/speechstate.d.ts +3 -1
- package/dist/speechstate.d.ts.map +1 -1
- package/dist/speechstate.js +4 -1
- package/dist/tts.js +1 -1
- package/dist/types.d.ts +16 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +53 -51
package/README.org
CHANGED
|
@@ -19,16 +19,19 @@
|
|
|
19
19
|
#+end_src
|
|
20
20
|
|
|
21
21
|
#+begin_src typescript
|
|
22
|
-
interface AzureCredentials {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
22
|
+
interface AzureCredentials {
|
|
23
|
+
endpoint: string;
|
|
24
|
+
key: string;
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
interface Settings {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
interface Settings {
|
|
28
|
+
locale?: string;
|
|
29
|
+
azureCredentials: string | AzureCredentials;
|
|
30
|
+
asrDefaultCompleteTimeout?: number;
|
|
31
|
+
asrDefaultNoInputTimeout?: number;
|
|
32
|
+
ttsDefaultVoice?: string;
|
|
33
|
+
speechRecognitionEndpointId?: string;
|
|
34
|
+
}
|
|
32
35
|
#+end_src
|
|
33
36
|
|
|
34
37
|
|
package/dist/asr.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="webspeechapi" />
|
|
2
|
-
import { RecogniseParameters, Hypothesis,
|
|
2
|
+
import { RecogniseParameters, Hypothesis, AzureSpeechCredentials, AzureLanguageCredentials } from "./types";
|
|
3
3
|
interface MySpeechRecognition extends SpeechRecognition {
|
|
4
4
|
new (): any;
|
|
5
5
|
}
|
|
@@ -40,6 +40,7 @@ interface ASRContext extends ASRInit {
|
|
|
40
40
|
wsaASRinstance?: MySpeechRecognition;
|
|
41
41
|
wsaGrammarList?: MySpeechGrammarList;
|
|
42
42
|
result?: Hypothesis[];
|
|
43
|
+
nluResult?: any;
|
|
43
44
|
params?: RecogniseParameters;
|
|
44
45
|
}
|
|
45
46
|
interface ASRInit {
|
|
@@ -47,8 +48,70 @@ interface ASRInit {
|
|
|
47
48
|
asrDefaultNoInputTimeout: number;
|
|
48
49
|
locale: string;
|
|
49
50
|
audioContext: AudioContext;
|
|
50
|
-
azureCredentials: string |
|
|
51
|
+
azureCredentials: string | AzureSpeechCredentials;
|
|
52
|
+
speechRecognitionEndpointId?: string;
|
|
53
|
+
azureLanguageCredentials?: AzureLanguageCredentials;
|
|
51
54
|
}
|
|
52
|
-
export declare const asrMachine: import("xstate").StateMachine<ASRContext, ASREvent,
|
|
55
|
+
export declare const asrMachine: import("xstate").StateMachine<ASRContext, ASREvent, {
|
|
56
|
+
[x: string]: import("xstate").ActorRef<import("xstate").CallbackSnapshot<{}>, import("xstate").EventObject> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<string, any>, {
|
|
57
|
+
[k: string]: unknown;
|
|
58
|
+
type: string;
|
|
59
|
+
}> | import("xstate").ActorRef<import("xstate").CallbackSnapshot<any>, import("xstate").EventObject> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<any, AzureLanguageCredentials & {
|
|
60
|
+
query: string;
|
|
61
|
+
}>, {
|
|
62
|
+
[k: string]: unknown;
|
|
63
|
+
type: string;
|
|
64
|
+
}>;
|
|
65
|
+
}, {
|
|
66
|
+
src: "getToken";
|
|
67
|
+
logic: import("xstate").PromiseActorLogic<string, any>;
|
|
68
|
+
id: string;
|
|
69
|
+
} | {
|
|
70
|
+
src: "ponyfill";
|
|
71
|
+
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, {}>;
|
|
72
|
+
id: string;
|
|
73
|
+
} | {
|
|
74
|
+
src: "recStart";
|
|
75
|
+
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, any>;
|
|
76
|
+
id: string;
|
|
77
|
+
} | {
|
|
78
|
+
src: "nluPromise";
|
|
79
|
+
logic: import("xstate").PromiseActorLogic<any, AzureLanguageCredentials & {
|
|
80
|
+
query: string;
|
|
81
|
+
}>;
|
|
82
|
+
id: string;
|
|
83
|
+
}, {
|
|
84
|
+
type: "recStop";
|
|
85
|
+
params: unknown;
|
|
86
|
+
}, {
|
|
87
|
+
type: string;
|
|
88
|
+
params: {};
|
|
89
|
+
}, string, "GetToken" | "Ready" | "Fail" | "Ponyfill" | "Pause" | {
|
|
90
|
+
Recognising?: "WaitForRecogniser" | "NoInput" | "InProgress" | "Match" | "NLURequest";
|
|
91
|
+
}, string, ASRInit, {}, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, ASREvent, {
|
|
92
|
+
src: "getToken";
|
|
93
|
+
logic: import("xstate").PromiseActorLogic<string, any>;
|
|
94
|
+
id: string;
|
|
95
|
+
} | {
|
|
96
|
+
src: "ponyfill";
|
|
97
|
+
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, {}>;
|
|
98
|
+
id: string;
|
|
99
|
+
} | {
|
|
100
|
+
src: "recStart";
|
|
101
|
+
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, any>;
|
|
102
|
+
id: string;
|
|
103
|
+
} | {
|
|
104
|
+
src: "nluPromise";
|
|
105
|
+
logic: import("xstate").PromiseActorLogic<any, AzureLanguageCredentials & {
|
|
106
|
+
query: string;
|
|
107
|
+
}>;
|
|
108
|
+
id: string;
|
|
109
|
+
}, {
|
|
110
|
+
type: "recStop";
|
|
111
|
+
params: unknown;
|
|
112
|
+
}, {
|
|
113
|
+
type: string;
|
|
114
|
+
params: {};
|
|
115
|
+
}, string, string>>;
|
|
53
116
|
export {};
|
|
54
117
|
//# sourceMappingURL=asr.d.ts.map
|
package/dist/asr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asr.d.ts","sourceRoot":"","sources":["../src/asr.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"asr.d.ts","sourceRoot":"","sources":["../src/asr.ts"],"names":[],"mappings":";AAcA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,UAAU,mBAAoB,SAAQ,iBAAiB;IACrD,YAAO;CACR;AACD,UAAU,mBAAoB,SAAQ,iBAAiB;IACrD,YAAO;CACR;AAED,KAAK,QAAQ,GACT;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE;QACL,MAAM,EAAE,mBAAmB,CAAC;QAC5B,cAAc,EAAE,mBAAmB,CAAC;KACrC,CAAC;CACH,GACD;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,mBAAmB,CAAC;CAC7B,GACD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE;QAAE,cAAc,EAAE,mBAAmB,CAAA;KAAE,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,GACtB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC;AAE5C,UAAU,UAAW,SAAQ,OAAO;IAClC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B;AAED,UAAU,OAAO;IACf,yBAAyB,EAAE,MAAM,CAAC;IAClC,wBAAwB,EAAE,MAAM,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,gBAAgB,EAAE,MAAM,GAAG,sBAAsB,CAAC;IAClD,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;CACrD;AAED,eAAO,MAAM,UAAU;;;;;eAiF8C,MAAM;;;;;;;;;;;;;;;;;;;;eAAN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;eAAN,MAAM;;;;;;;;;mBA0RzE,CAAC"}
|
package/dist/asr.js
CHANGED
|
@@ -1,19 +1,133 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.asrMachine = void 0;
|
|
4
13
|
const xstate_1 = require("xstate");
|
|
5
14
|
const getToken_1 = require("./getToken");
|
|
6
15
|
const SpeechToText_1 = require("web-speech-cognitive-services/lib/SpeechServices/SpeechToText");
|
|
7
16
|
const REGION = "northeurope";
|
|
8
|
-
exports.asrMachine = (0, xstate_1.
|
|
17
|
+
exports.asrMachine = (0, xstate_1.setup)({
|
|
18
|
+
types: {
|
|
19
|
+
context: {},
|
|
20
|
+
events: {},
|
|
21
|
+
input: {},
|
|
22
|
+
},
|
|
23
|
+
actions: {
|
|
24
|
+
recStop: ({ context }) => {
|
|
25
|
+
context.wsaASRinstance.abort();
|
|
26
|
+
console.debug("[ASR] stopped");
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
actors: {
|
|
30
|
+
getToken: getToken_1.getToken,
|
|
31
|
+
ponyfill: (0, xstate_1.fromCallback)(({ sendBack, input }) => {
|
|
32
|
+
const { SpeechGrammarList, SpeechRecognition } = (0, SpeechToText_1.default)({
|
|
33
|
+
audioContext: input.audioContext,
|
|
34
|
+
speechRecognitionEndpointId: input
|
|
35
|
+
.speechRecognitionEndpointId,
|
|
36
|
+
credentials: {
|
|
37
|
+
region: REGION, // TODO
|
|
38
|
+
authorizationToken: input.azureAuthorizationToken,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
sendBack({
|
|
42
|
+
type: "READY",
|
|
43
|
+
value: {
|
|
44
|
+
wsaASR: SpeechRecognition,
|
|
45
|
+
wsaGrammarList: SpeechGrammarList,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
console.debug("[ASR] READY", input);
|
|
49
|
+
}),
|
|
50
|
+
recStart: (0, xstate_1.fromCallback)(({ sendBack, input }) => {
|
|
51
|
+
let asr = new input.wsaASR();
|
|
52
|
+
asr.grammars = new input.wsaGrammarList();
|
|
53
|
+
asr.grammars.phrases = input.phrases || [];
|
|
54
|
+
asr.lang = input.locale;
|
|
55
|
+
asr.continuous = true;
|
|
56
|
+
asr.interimResults = true;
|
|
57
|
+
asr.onresult = function (event) {
|
|
58
|
+
if (event.results[event.results.length - 1].isFinal) {
|
|
59
|
+
const transcript = event.results
|
|
60
|
+
.map((x) => x[0].transcript.replace(/\.$/, ""))
|
|
61
|
+
.join(" ");
|
|
62
|
+
const confidence = event.results
|
|
63
|
+
.map((x) => x[0].confidence)
|
|
64
|
+
.reduce((a, b) => a + b) / event.results.length;
|
|
65
|
+
const res = [
|
|
66
|
+
{
|
|
67
|
+
utterance: transcript,
|
|
68
|
+
confidence: confidence,
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
sendBack({
|
|
72
|
+
type: "RESULT",
|
|
73
|
+
value: res,
|
|
74
|
+
});
|
|
75
|
+
console.debug("[ASR] RESULT (pre-final)", res);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
sendBack({ type: "STARTSPEECH" });
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
asr.addEventListener("start", () => {
|
|
82
|
+
sendBack({ type: "STARTED", value: { wsaASRinstance: asr } });
|
|
83
|
+
});
|
|
84
|
+
// receive((event) => {
|
|
85
|
+
// console.debug("bla");
|
|
86
|
+
// if (event.type === "STOP") {
|
|
87
|
+
// asr.abort();
|
|
88
|
+
// }
|
|
89
|
+
// });
|
|
90
|
+
asr.start();
|
|
91
|
+
}),
|
|
92
|
+
nluPromise: (0, xstate_1.fromPromise)(({ input }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
+
const response = yield fetch(new Request(input.endpoint, {
|
|
94
|
+
method: "POST",
|
|
95
|
+
headers: {
|
|
96
|
+
"Ocp-Apim-Subscription-Key": input.key,
|
|
97
|
+
"Content-Type": "application/json",
|
|
98
|
+
},
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
kind: "Conversation",
|
|
101
|
+
analysisInput: {
|
|
102
|
+
conversationItem: {
|
|
103
|
+
id: "PARTICIPANT_ID_HERE",
|
|
104
|
+
text: input.query,
|
|
105
|
+
modality: "text",
|
|
106
|
+
language: "en-US", // TODO
|
|
107
|
+
participantId: "PARTICIPANT_ID_HERE",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
parameters: {
|
|
111
|
+
projectName: input.projectName,
|
|
112
|
+
verbose: true,
|
|
113
|
+
deploymentName: input.deploymentName,
|
|
114
|
+
stringIndexType: "TextElement_V8",
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
}));
|
|
118
|
+
return response.json();
|
|
119
|
+
})),
|
|
120
|
+
},
|
|
121
|
+
}).createMachine({
|
|
9
122
|
id: "asr",
|
|
10
|
-
types: {},
|
|
11
123
|
context: ({ input }) => ({
|
|
12
124
|
asrDefaultCompleteTimeout: input.asrDefaultCompleteTimeout || 0,
|
|
13
125
|
asrDefaultNoInputTimeout: input.asrDefaultNoInputTimeout || 5000,
|
|
14
126
|
locale: input.locale || "en-US",
|
|
15
127
|
audioContext: input.audioContext,
|
|
16
128
|
azureCredentials: input.azureCredentials,
|
|
129
|
+
azureLanguageCredentials: input.azureLanguageCredentials,
|
|
130
|
+
speechRecognitionEndpointId: input.speechRecognitionEndpointId,
|
|
17
131
|
}),
|
|
18
132
|
initial: "GetToken",
|
|
19
133
|
on: {
|
|
@@ -61,15 +175,21 @@ exports.asrMachine = (0, xstate_1.createMachine)({
|
|
|
61
175
|
],
|
|
62
176
|
target: ".Match",
|
|
63
177
|
},
|
|
64
|
-
RECOGNISED:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
178
|
+
RECOGNISED: [
|
|
179
|
+
{
|
|
180
|
+
target: ".NLURequest",
|
|
181
|
+
guard: ({ context }) => !!(context.params.nlu && context.azureLanguageCredentials),
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
target: "Ready",
|
|
185
|
+
actions: [
|
|
186
|
+
(0, xstate_1.sendParent)(({ context }) => ({
|
|
187
|
+
type: "RECOGNISED",
|
|
188
|
+
value: context.result,
|
|
189
|
+
})),
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
],
|
|
73
193
|
CONTROL: {
|
|
74
194
|
target: "Pause",
|
|
75
195
|
},
|
|
@@ -122,6 +242,58 @@ exports.asrMachine = (0, xstate_1.createMachine)({
|
|
|
122
242
|
}),
|
|
123
243
|
],
|
|
124
244
|
},
|
|
245
|
+
NLURequest: {
|
|
246
|
+
invoke: {
|
|
247
|
+
src: "nluPromise",
|
|
248
|
+
input: ({ context }) => {
|
|
249
|
+
let c;
|
|
250
|
+
typeof context.params.nlu === "boolean"
|
|
251
|
+
? (c = context.azureLanguageCredentials)
|
|
252
|
+
: (c = context.params.nlu);
|
|
253
|
+
return {
|
|
254
|
+
endpoint: c.endpoint,
|
|
255
|
+
key: c.key,
|
|
256
|
+
projectName: c.projectName,
|
|
257
|
+
deploymentName: c.deploymentName,
|
|
258
|
+
query: context.result[0].utterance,
|
|
259
|
+
};
|
|
260
|
+
},
|
|
261
|
+
onDone: [
|
|
262
|
+
{
|
|
263
|
+
actions: [
|
|
264
|
+
({ event }) => console.error("[ASR] no NLU prediction", event.output),
|
|
265
|
+
(0, xstate_1.sendParent)(({ context }) => ({
|
|
266
|
+
type: "RECOGNISED",
|
|
267
|
+
value: context.result,
|
|
268
|
+
})),
|
|
269
|
+
],
|
|
270
|
+
target: "#asr.Ready",
|
|
271
|
+
guard: ({ event }) => !(event.output.result || {}).prediction,
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
actions: [
|
|
275
|
+
({ event }) => console.debug("[ASR] NLU result", event.output.result.prediction),
|
|
276
|
+
(0, xstate_1.sendParent)(({ context, event }) => ({
|
|
277
|
+
type: "RECOGNISED",
|
|
278
|
+
value: context.result,
|
|
279
|
+
nluValue: event.output.result.prediction,
|
|
280
|
+
})),
|
|
281
|
+
],
|
|
282
|
+
target: "#asr.Ready",
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
onError: {
|
|
286
|
+
actions: [
|
|
287
|
+
({ event }) => console.error("[ASR]", event.error),
|
|
288
|
+
(0, xstate_1.sendParent)(({ context }) => ({
|
|
289
|
+
type: "RECOGNISED",
|
|
290
|
+
value: context.result,
|
|
291
|
+
})),
|
|
292
|
+
],
|
|
293
|
+
target: "#asr.Ready",
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
125
297
|
},
|
|
126
298
|
},
|
|
127
299
|
Pause: {
|
|
@@ -158,6 +330,7 @@ exports.asrMachine = (0, xstate_1.createMachine)({
|
|
|
158
330
|
],
|
|
159
331
|
},
|
|
160
332
|
onError: {
|
|
333
|
+
actions: ({ event }) => console.error("[ASR]", event.error),
|
|
161
334
|
target: "Fail",
|
|
162
335
|
},
|
|
163
336
|
},
|
|
@@ -170,78 +343,9 @@ exports.asrMachine = (0, xstate_1.createMachine)({
|
|
|
170
343
|
audioContext: context.audioContext,
|
|
171
344
|
azureAuthorizationToken: context.azureAuthorizationToken,
|
|
172
345
|
locale: context.locale,
|
|
346
|
+
speechRecognitionEndpointId: context.speechRecognitionEndpointId,
|
|
173
347
|
}),
|
|
174
348
|
},
|
|
175
349
|
},
|
|
176
350
|
},
|
|
177
|
-
}, {
|
|
178
|
-
actions: {
|
|
179
|
-
recStop: ({ context }) => {
|
|
180
|
-
context.wsaASRinstance.abort();
|
|
181
|
-
console.debug("[ASR] stopped");
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
actors: {
|
|
185
|
-
getToken: getToken_1.getToken,
|
|
186
|
-
ponyfill: (0, xstate_1.fromCallback)(({ sendBack, input }) => {
|
|
187
|
-
const { SpeechGrammarList, SpeechRecognition } = (0, SpeechToText_1.default)({
|
|
188
|
-
audioContext: input.audioContext,
|
|
189
|
-
credentials: {
|
|
190
|
-
region: REGION,
|
|
191
|
-
authorizationToken: input.azureAuthorizationToken,
|
|
192
|
-
},
|
|
193
|
-
});
|
|
194
|
-
sendBack({
|
|
195
|
-
type: "READY",
|
|
196
|
-
value: {
|
|
197
|
-
wsaASR: SpeechRecognition,
|
|
198
|
-
wsaGrammarList: SpeechGrammarList,
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
console.debug("[ASR] READY");
|
|
202
|
-
}),
|
|
203
|
-
recStart: (0, xstate_1.fromCallback)(({ sendBack, input }) => {
|
|
204
|
-
let asr = new input.wsaASR();
|
|
205
|
-
asr.grammars = new input.wsaGrammarList();
|
|
206
|
-
asr.grammars.phrases = input.phrases || [];
|
|
207
|
-
asr.lang = input.locale;
|
|
208
|
-
asr.continuous = true;
|
|
209
|
-
asr.interimResults = true;
|
|
210
|
-
asr.onresult = function (event) {
|
|
211
|
-
if (event.results[event.results.length - 1].isFinal) {
|
|
212
|
-
const transcript = event.results
|
|
213
|
-
.map((x) => x[0].transcript.replace(/\.$/, ""))
|
|
214
|
-
.join(" ");
|
|
215
|
-
const confidence = event.results
|
|
216
|
-
.map((x) => x[0].confidence)
|
|
217
|
-
.reduce((a, b) => a + b) /
|
|
218
|
-
event.results.length;
|
|
219
|
-
const res = [
|
|
220
|
-
{
|
|
221
|
-
utterance: transcript,
|
|
222
|
-
confidence: confidence,
|
|
223
|
-
},
|
|
224
|
-
];
|
|
225
|
-
sendBack({
|
|
226
|
-
type: "RESULT",
|
|
227
|
-
value: res,
|
|
228
|
-
});
|
|
229
|
-
console.debug("[ASR] RESULT (pre-final)", res);
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
sendBack({ type: "STARTSPEECH" });
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
asr.addEventListener("start", () => {
|
|
236
|
-
sendBack({ type: "STARTED", value: { wsaASRinstance: asr } });
|
|
237
|
-
});
|
|
238
|
-
// receive((event) => {
|
|
239
|
-
// console.debug("bla");
|
|
240
|
-
// if (event.type === "STOP") {
|
|
241
|
-
// asr.abort();
|
|
242
|
-
// }
|
|
243
|
-
// });
|
|
244
|
-
asr.start();
|
|
245
|
-
}),
|
|
246
|
-
},
|
|
247
351
|
});
|
package/dist/speechstate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Settings, Agenda, Hypothesis } from "./types";
|
|
1
|
+
import { Settings, Agenda, Hypothesis, RecogniseParameters } from "./types";
|
|
2
2
|
interface SSContext {
|
|
3
3
|
settings: Settings;
|
|
4
4
|
audioContext?: AudioContext;
|
|
@@ -26,6 +26,7 @@ type SSEvent = {
|
|
|
26
26
|
type: "ASR_READY";
|
|
27
27
|
} | {
|
|
28
28
|
type: "LISTEN";
|
|
29
|
+
value: RecogniseParameters;
|
|
29
30
|
} | {
|
|
30
31
|
type: "ASR_STARTED";
|
|
31
32
|
} | {
|
|
@@ -33,6 +34,7 @@ type SSEvent = {
|
|
|
33
34
|
} | {
|
|
34
35
|
type: "RECOGNISED";
|
|
35
36
|
value: Hypothesis[];
|
|
37
|
+
nluValue?: any;
|
|
36
38
|
};
|
|
37
39
|
declare const speechstate: import("xstate").StateMachine<SSContext, SSEvent, Record<string, import("xstate").AnyActorRef>, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, import("xstate").StateValue, string, Settings, {}, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, SSEvent, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, string>>;
|
|
38
40
|
export { speechstate };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speechstate.d.ts","sourceRoot":"","sources":["../src/speechstate.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"speechstate.d.ts","sourceRoot":"","sources":["../src/speechstate.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC5E,UAAU,SAAS;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AAED,KAAK,OAAO,GACR;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,mBAAmB,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,UAAU,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC;AAEhE,QAAA,MAAM,WAAW,odA6PhB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/speechstate.js
CHANGED
|
@@ -48,6 +48,8 @@ const speechstate = (0, xstate_1.createMachine)({
|
|
|
48
48
|
locale: context.settings.locale,
|
|
49
49
|
audioContext: context.audioContext,
|
|
50
50
|
azureCredentials: context.settings.azureCredentials,
|
|
51
|
+
azureLanguageCredentials: context.settings.azureLanguageCredentials,
|
|
52
|
+
speechRecognitionEndpointId: context.settings.speechRecognitionEndpointId,
|
|
51
53
|
},
|
|
52
54
|
});
|
|
53
55
|
},
|
|
@@ -186,10 +188,11 @@ const speechstate = (0, xstate_1.createMachine)({
|
|
|
186
188
|
},
|
|
187
189
|
RECOGNISED: {
|
|
188
190
|
actions: [
|
|
189
|
-
({ event }) => console.debug("[ASR→SpSt] RECOGNISED", event.value),
|
|
191
|
+
({ event }) => console.debug("[ASR→SpSt] RECOGNISED", event.value, event.nluValue),
|
|
190
192
|
(0, xstate_1.sendParent)(({ event }) => ({
|
|
191
193
|
type: "RECOGNISED",
|
|
192
194
|
value: event.value,
|
|
195
|
+
nluValue: event.nluValue,
|
|
193
196
|
})),
|
|
194
197
|
],
|
|
195
198
|
target: "Idle",
|
package/dist/tts.js
CHANGED
|
@@ -125,7 +125,7 @@ exports.ttsMachine = (0, xstate_1.createMachine)({
|
|
|
125
125
|
const ponyfill = (0, TextToSpeech_1.default)({
|
|
126
126
|
audioContext: input.audioContext,
|
|
127
127
|
credentials: {
|
|
128
|
-
region: REGION,
|
|
128
|
+
region: REGION, // TODO
|
|
129
129
|
authorizationToken: input.azureAuthorizationToken,
|
|
130
130
|
},
|
|
131
131
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface AzureSpeechCredentials {
|
|
2
2
|
endpoint: string;
|
|
3
3
|
key: string;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use `AzureSpeechCredentials` instead
|
|
7
|
+
*/
|
|
8
|
+
export interface AzureCredentials extends AzureSpeechCredentials {
|
|
9
|
+
}
|
|
10
|
+
export interface AzureLanguageCredentials {
|
|
11
|
+
endpoint: string;
|
|
12
|
+
key: string;
|
|
13
|
+
projectName: string;
|
|
14
|
+
deploymentName: string;
|
|
15
|
+
}
|
|
5
16
|
export interface Settings {
|
|
6
17
|
locale?: string;
|
|
7
|
-
azureCredentials: string | AzureCredentials;
|
|
18
|
+
azureCredentials: string | AzureCredentials | AzureSpeechCredentials;
|
|
19
|
+
azureLanguageCredentials?: AzureLanguageCredentials;
|
|
8
20
|
asrDefaultCompleteTimeout?: number;
|
|
9
21
|
asrDefaultNoInputTimeout?: number;
|
|
10
22
|
ttsDefaultVoice?: string;
|
|
23
|
+
speechRecognitionEndpointId?: string;
|
|
11
24
|
}
|
|
12
25
|
export interface Agenda {
|
|
13
26
|
utterance: string;
|
|
@@ -23,5 +36,6 @@ export interface RecogniseParameters {
|
|
|
23
36
|
completeTimeout?: number;
|
|
24
37
|
locale?: string;
|
|
25
38
|
hints?: string[];
|
|
39
|
+
nlu?: boolean | AzureLanguageCredentials;
|
|
26
40
|
}
|
|
27
41
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,sBAAsB;CAAG;AAEnE,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,GAAG,gBAAgB,GAAG,sBAAsB,CAAC;IACrE,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;IACpD,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2BAA2B,CAAC,EAAE,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,MAAM;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,GAAG,wBAAwB,CAAC;CAC1C"}
|
package/package.json
CHANGED
|
@@ -1,53 +1,55 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
2
|
+
"name": "speechstate",
|
|
3
|
+
"version": "2.0.0-beta.6",
|
|
4
|
+
"license": "GPL-3.0",
|
|
5
|
+
"homepage": "http://localhost/speechstate",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": ["/dist"],
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@statelyai/inspect": "^0.2.3",
|
|
11
|
+
"microsoft-cognitiveservices-speech-sdk": "^1.31.0",
|
|
12
|
+
"web-speech-cognitive-services": "^7.1.3",
|
|
13
|
+
"xstate": "^5.5.1"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "vite",
|
|
17
|
+
"compile": "tsc",
|
|
18
|
+
"test": "jest --silent=false"
|
|
19
|
+
},
|
|
20
|
+
"eslintConfig": {
|
|
21
|
+
"extends": ["react-app", "react-app/jest"]
|
|
22
|
+
},
|
|
23
|
+
"browserslist": {
|
|
24
|
+
"production": [">0.2%", "not dead", "not op_mini all"],
|
|
25
|
+
"development": [
|
|
26
|
+
"last 1 chrome version",
|
|
27
|
+
"last 1 firefox version",
|
|
28
|
+
"last 1 safari version"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^29.5.2",
|
|
33
|
+
"@types/webspeechapi": "^0.0.29",
|
|
34
|
+
"buffer": "^5.5.0||^6.0.0",
|
|
35
|
+
"jest": "^29.5.0",
|
|
36
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
37
|
+
"ts-jest": "^29.1.0",
|
|
38
|
+
"typescript": "^5.0.4",
|
|
39
|
+
"vite": "^5.0.11"
|
|
40
|
+
},
|
|
41
|
+
"packageManager": "yarn@3.6.4",
|
|
42
|
+
"description": "* SDK",
|
|
43
|
+
"directories": {
|
|
44
|
+
"doc": "docs",
|
|
45
|
+
"test": "test"
|
|
46
|
+
},
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+ssh://git@github.com/vladmaraev/speechstate.git"
|
|
50
|
+
},
|
|
51
|
+
"author": "Vlad Maraev",
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/vladmaraev/speechstate/issues"
|
|
54
|
+
}
|
|
53
55
|
}
|