speechstate 2.0.1 → 2.0.3
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/asr.d.ts +121 -0
- package/dist/asr.d.ts.map +1 -0
- package/dist/asr.js +354 -0
- package/dist/getToken.d.ts +2 -0
- package/dist/getToken.d.ts.map +1 -0
- package/dist/getToken.js +26 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/speechstate.d.ts +48 -0
- package/dist/speechstate.d.ts.map +1 -0
- package/dist/speechstate.js +292 -0
- package/dist/tts.d.ts +142 -0
- package/dist/tts.d.ts.map +1 -0
- package/dist/tts.js +409 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/package.json +5 -4
package/dist/asr.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/// <reference types="webspeechapi" />
|
|
2
|
+
import { RecogniseParameters, Hypothesis, AzureSpeechCredentials, AzureLanguageCredentials } from "./types";
|
|
3
|
+
interface MySpeechRecognition extends SpeechRecognition {
|
|
4
|
+
new (): any;
|
|
5
|
+
}
|
|
6
|
+
interface MySpeechGrammarList extends SpeechGrammarList {
|
|
7
|
+
new (): any;
|
|
8
|
+
}
|
|
9
|
+
type ASREvent = {
|
|
10
|
+
type: "READY";
|
|
11
|
+
value: {
|
|
12
|
+
wsaASR: MySpeechRecognition;
|
|
13
|
+
wsaGrammarList: MySpeechGrammarList;
|
|
14
|
+
};
|
|
15
|
+
} | {
|
|
16
|
+
type: "ERROR";
|
|
17
|
+
} | {
|
|
18
|
+
type: "NOINPUT";
|
|
19
|
+
} | {
|
|
20
|
+
type: "CONTROL";
|
|
21
|
+
} | {
|
|
22
|
+
type: "START";
|
|
23
|
+
value?: RecogniseParameters;
|
|
24
|
+
} | {
|
|
25
|
+
type: "STARTED";
|
|
26
|
+
value: {
|
|
27
|
+
wsaASRinstance: MySpeechRecognition;
|
|
28
|
+
};
|
|
29
|
+
} | {
|
|
30
|
+
type: "STARTSPEECH";
|
|
31
|
+
} | {
|
|
32
|
+
type: "RECOGNISED";
|
|
33
|
+
} | {
|
|
34
|
+
type: "RESULT";
|
|
35
|
+
value: Hypothesis[];
|
|
36
|
+
};
|
|
37
|
+
interface ASRContext extends ASRInit {
|
|
38
|
+
azureAuthorizationToken?: string;
|
|
39
|
+
wsaASR?: MySpeechRecognition;
|
|
40
|
+
wsaASRinstance?: MySpeechRecognition;
|
|
41
|
+
wsaGrammarList?: MySpeechGrammarList;
|
|
42
|
+
result?: Hypothesis[];
|
|
43
|
+
nluResult?: any;
|
|
44
|
+
params?: RecogniseParameters;
|
|
45
|
+
}
|
|
46
|
+
interface ASRInit {
|
|
47
|
+
asrDefaultCompleteTimeout: number;
|
|
48
|
+
asrDefaultNoInputTimeout: number;
|
|
49
|
+
locale: string;
|
|
50
|
+
audioContext: AudioContext;
|
|
51
|
+
azureCredentials: string | AzureSpeechCredentials;
|
|
52
|
+
speechRecognitionEndpointId?: string;
|
|
53
|
+
azureLanguageCredentials?: AzureLanguageCredentials;
|
|
54
|
+
}
|
|
55
|
+
export declare const asrMachine: import("xstate").StateMachine<ASRContext, ASREvent, {
|
|
56
|
+
[x: string]: import("xstate").ActorRef<import("xstate").CallbackSnapshot<{}>, import("xstate").EventObject, import("xstate").EventObject> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<string, any>, {
|
|
57
|
+
[k: string]: unknown;
|
|
58
|
+
type: string;
|
|
59
|
+
}, import("xstate").EventObject> | import("xstate").ActorRef<import("xstate").CallbackSnapshot<any>, import("xstate").EventObject, import("xstate").EventObject> | import("xstate").ActorRef<import("xstate").PromiseSnapshot<any, AzureLanguageCredentials & {
|
|
60
|
+
query: string;
|
|
61
|
+
}>, {
|
|
62
|
+
[k: string]: unknown;
|
|
63
|
+
type: string;
|
|
64
|
+
}, import("xstate").EventObject>;
|
|
65
|
+
}, import("xstate").Values<{
|
|
66
|
+
getToken: {
|
|
67
|
+
src: "getToken";
|
|
68
|
+
logic: import("xstate").PromiseActorLogic<string, any>;
|
|
69
|
+
id: string;
|
|
70
|
+
};
|
|
71
|
+
ponyfill: {
|
|
72
|
+
src: "ponyfill";
|
|
73
|
+
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, {}>;
|
|
74
|
+
id: string;
|
|
75
|
+
};
|
|
76
|
+
recStart: {
|
|
77
|
+
src: "recStart";
|
|
78
|
+
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, any>;
|
|
79
|
+
id: string;
|
|
80
|
+
};
|
|
81
|
+
nluPromise: {
|
|
82
|
+
src: "nluPromise";
|
|
83
|
+
logic: import("xstate").PromiseActorLogic<any, AzureLanguageCredentials & {
|
|
84
|
+
query: string;
|
|
85
|
+
}>;
|
|
86
|
+
id: string;
|
|
87
|
+
};
|
|
88
|
+
}>, {
|
|
89
|
+
type: "recStop";
|
|
90
|
+
params: unknown;
|
|
91
|
+
}, never, never, "GetToken" | "Ready" | "Fail" | "Ponyfill" | "Pause" | {
|
|
92
|
+
Recognising?: "WaitForRecogniser" | "NoInput" | "InProgress" | "Match" | "NLURequest";
|
|
93
|
+
}, string, ASRInit, {}, import("xstate").EventObject, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, ASREvent, import("xstate").Values<{
|
|
94
|
+
getToken: {
|
|
95
|
+
src: "getToken";
|
|
96
|
+
logic: import("xstate").PromiseActorLogic<string, any>;
|
|
97
|
+
id: string;
|
|
98
|
+
};
|
|
99
|
+
ponyfill: {
|
|
100
|
+
src: "ponyfill";
|
|
101
|
+
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, {}>;
|
|
102
|
+
id: string;
|
|
103
|
+
};
|
|
104
|
+
recStart: {
|
|
105
|
+
src: "recStart";
|
|
106
|
+
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, any>;
|
|
107
|
+
id: string;
|
|
108
|
+
};
|
|
109
|
+
nluPromise: {
|
|
110
|
+
src: "nluPromise";
|
|
111
|
+
logic: import("xstate").PromiseActorLogic<any, AzureLanguageCredentials & {
|
|
112
|
+
query: string;
|
|
113
|
+
}>;
|
|
114
|
+
id: string;
|
|
115
|
+
};
|
|
116
|
+
}>, {
|
|
117
|
+
type: "recStop";
|
|
118
|
+
params: unknown;
|
|
119
|
+
}, never, never, string, import("xstate").EventObject>>;
|
|
120
|
+
export {};
|
|
121
|
+
//# sourceMappingURL=asr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;mBAAN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAN,MAAM;;;;;;;uDA6RzE,CAAC"}
|
package/dist/asr.js
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.asrMachine = void 0;
|
|
13
|
+
const xstate_1 = require("xstate");
|
|
14
|
+
const getToken_1 = require("./getToken");
|
|
15
|
+
const SpeechToText_1 = require("web-speech-cognitive-services/lib/SpeechServices/SpeechToText");
|
|
16
|
+
const REGION = "northeurope";
|
|
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({
|
|
122
|
+
id: "asr",
|
|
123
|
+
context: ({ input }) => ({
|
|
124
|
+
asrDefaultCompleteTimeout: input.asrDefaultCompleteTimeout || 0,
|
|
125
|
+
asrDefaultNoInputTimeout: input.asrDefaultNoInputTimeout || 5000,
|
|
126
|
+
locale: input.locale || "en-US",
|
|
127
|
+
audioContext: input.audioContext,
|
|
128
|
+
azureCredentials: input.azureCredentials,
|
|
129
|
+
azureLanguageCredentials: input.azureLanguageCredentials,
|
|
130
|
+
speechRecognitionEndpointId: input.speechRecognitionEndpointId,
|
|
131
|
+
}),
|
|
132
|
+
initial: "GetToken",
|
|
133
|
+
on: {
|
|
134
|
+
READY: {
|
|
135
|
+
target: ".Ready",
|
|
136
|
+
actions: [
|
|
137
|
+
(0, xstate_1.assign)({
|
|
138
|
+
wsaASR: ({ event }) => event.value.wsaASR,
|
|
139
|
+
wsaGrammarList: ({ event }) => event.value.wsaGrammarList,
|
|
140
|
+
}),
|
|
141
|
+
(0, xstate_1.sendParent)({ type: "ASR_READY" }),
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
states: {
|
|
146
|
+
Fail: {},
|
|
147
|
+
Ready: {
|
|
148
|
+
on: {
|
|
149
|
+
START: {
|
|
150
|
+
target: "Recognising",
|
|
151
|
+
actions: (0, xstate_1.assign)({ params: ({ event }) => event.value || {} }),
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
Recognising: {
|
|
156
|
+
initial: "WaitForRecogniser",
|
|
157
|
+
invoke: {
|
|
158
|
+
id: "recStart",
|
|
159
|
+
input: ({ context }) => ({
|
|
160
|
+
wsaASR: context.wsaASR,
|
|
161
|
+
wsaGrammarList: context.wsaGrammarList,
|
|
162
|
+
locale: context.locale,
|
|
163
|
+
phrases: (context.params || {}).hints || [],
|
|
164
|
+
}),
|
|
165
|
+
src: "recStart",
|
|
166
|
+
},
|
|
167
|
+
exit: "recStop",
|
|
168
|
+
on: {
|
|
169
|
+
RESULT: {
|
|
170
|
+
actions: [
|
|
171
|
+
(0, xstate_1.assign)({
|
|
172
|
+
result: ({ event }) => event.value,
|
|
173
|
+
}),
|
|
174
|
+
(0, xstate_1.cancel)("completeTimeout"),
|
|
175
|
+
],
|
|
176
|
+
target: ".Match",
|
|
177
|
+
},
|
|
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
|
+
],
|
|
193
|
+
CONTROL: {
|
|
194
|
+
target: "Pause",
|
|
195
|
+
},
|
|
196
|
+
STOP: {
|
|
197
|
+
target: "Ready",
|
|
198
|
+
},
|
|
199
|
+
NOINPUT: {
|
|
200
|
+
actions: (0, xstate_1.sendParent)({ type: "ASR_NOINPUT" }),
|
|
201
|
+
target: "Ready",
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
states: {
|
|
205
|
+
WaitForRecogniser: {
|
|
206
|
+
on: {
|
|
207
|
+
STARTED: {
|
|
208
|
+
target: "NoInput",
|
|
209
|
+
actions: [
|
|
210
|
+
(0, xstate_1.assign)({
|
|
211
|
+
wsaASRinstance: ({ event }) => event.value.wsaASRinstance,
|
|
212
|
+
}),
|
|
213
|
+
(0, xstate_1.sendParent)({ type: "ASR_STARTED" }),
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
NoInput: {
|
|
219
|
+
entry: [
|
|
220
|
+
(0, xstate_1.raise)({ type: "NOINPUT" }, {
|
|
221
|
+
delay: ({ context }) => (context.params || {}).noInputTimeout ||
|
|
222
|
+
context.asrDefaultNoInputTimeout,
|
|
223
|
+
id: "timeout",
|
|
224
|
+
}),
|
|
225
|
+
],
|
|
226
|
+
on: {
|
|
227
|
+
STARTSPEECH: {
|
|
228
|
+
target: "InProgress",
|
|
229
|
+
actions: (0, xstate_1.cancel)("completeTimeout"),
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
exit: [(0, xstate_1.cancel)("timeout")],
|
|
233
|
+
},
|
|
234
|
+
InProgress: {
|
|
235
|
+
entry: () => console.debug("[ASR] in progress"),
|
|
236
|
+
},
|
|
237
|
+
Match: {
|
|
238
|
+
entry: [
|
|
239
|
+
({ context }) => console.debug("RECOGNISED will be sent in (ms)", (context.params || {}).completeTimeout ||
|
|
240
|
+
context.asrDefaultCompleteTimeout),
|
|
241
|
+
(0, xstate_1.raise)({ type: "RECOGNISED" }, {
|
|
242
|
+
delay: ({ context }) => (context.params || {}).completeTimeout ||
|
|
243
|
+
context.asrDefaultCompleteTimeout,
|
|
244
|
+
id: "completeTimeout",
|
|
245
|
+
}),
|
|
246
|
+
],
|
|
247
|
+
},
|
|
248
|
+
NLURequest: {
|
|
249
|
+
invoke: {
|
|
250
|
+
src: "nluPromise",
|
|
251
|
+
input: ({ context }) => {
|
|
252
|
+
let c;
|
|
253
|
+
typeof context.params.nlu === "boolean"
|
|
254
|
+
? (c = context.azureLanguageCredentials)
|
|
255
|
+
: (c = context.params.nlu);
|
|
256
|
+
return {
|
|
257
|
+
endpoint: c.endpoint,
|
|
258
|
+
key: c.key,
|
|
259
|
+
projectName: c.projectName,
|
|
260
|
+
deploymentName: c.deploymentName,
|
|
261
|
+
query: context.result[0].utterance,
|
|
262
|
+
};
|
|
263
|
+
},
|
|
264
|
+
onDone: [
|
|
265
|
+
{
|
|
266
|
+
actions: [
|
|
267
|
+
({ event }) => console.error("[ASR] no NLU prediction", event.output),
|
|
268
|
+
(0, xstate_1.sendParent)(({ context }) => ({
|
|
269
|
+
type: "RECOGNISED",
|
|
270
|
+
value: context.result,
|
|
271
|
+
})),
|
|
272
|
+
],
|
|
273
|
+
target: "#asr.Ready",
|
|
274
|
+
guard: ({ event }) => !(event.output.result || {}).prediction,
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
actions: [
|
|
278
|
+
({ event }) => console.debug("[ASR] NLU result", event.output.result.prediction),
|
|
279
|
+
(0, xstate_1.sendParent)(({ context, event }) => ({
|
|
280
|
+
type: "RECOGNISED",
|
|
281
|
+
value: context.result,
|
|
282
|
+
nluValue: event.output.result.prediction,
|
|
283
|
+
})),
|
|
284
|
+
],
|
|
285
|
+
target: "#asr.Ready",
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
onError: {
|
|
289
|
+
actions: [
|
|
290
|
+
({ event }) => console.error("[ASR]", event.error),
|
|
291
|
+
(0, xstate_1.sendParent)(({ context }) => ({
|
|
292
|
+
type: "RECOGNISED",
|
|
293
|
+
value: context.result,
|
|
294
|
+
})),
|
|
295
|
+
],
|
|
296
|
+
target: "#asr.Ready",
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
Pause: {
|
|
303
|
+
entry: (0, xstate_1.sendParent)({ type: "ASR_PAUSED" }),
|
|
304
|
+
on: {
|
|
305
|
+
CONTROL: {
|
|
306
|
+
target: "Recognising",
|
|
307
|
+
// ///// todo? reset noInputTimeout
|
|
308
|
+
// // actions: assign({
|
|
309
|
+
// // params: {
|
|
310
|
+
// // noInputTimeout: ({ context }) =>
|
|
311
|
+
// // context.asrDefaultNoInputTimeout,
|
|
312
|
+
// // completeTimeout: 0,
|
|
313
|
+
// // locale: "0",
|
|
314
|
+
// // hints: [""],
|
|
315
|
+
// // },
|
|
316
|
+
// // }),} },
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
GetToken: {
|
|
321
|
+
invoke: {
|
|
322
|
+
id: "getAuthorizationToken",
|
|
323
|
+
input: ({ context }) => ({
|
|
324
|
+
credentials: context.azureCredentials,
|
|
325
|
+
}),
|
|
326
|
+
src: "getToken",
|
|
327
|
+
onDone: {
|
|
328
|
+
target: "Ponyfill",
|
|
329
|
+
actions: [
|
|
330
|
+
(0, xstate_1.assign)(({ event }) => {
|
|
331
|
+
return { azureAuthorizationToken: event.output };
|
|
332
|
+
}),
|
|
333
|
+
],
|
|
334
|
+
},
|
|
335
|
+
onError: {
|
|
336
|
+
actions: ({ event }) => console.error("[ASR]", event.error),
|
|
337
|
+
target: "Fail",
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
Ponyfill: {
|
|
342
|
+
invoke: {
|
|
343
|
+
id: "ponyASR",
|
|
344
|
+
src: "ponyfill",
|
|
345
|
+
input: ({ context }) => ({
|
|
346
|
+
audioContext: context.audioContext,
|
|
347
|
+
azureAuthorizationToken: context.azureAuthorizationToken,
|
|
348
|
+
locale: context.locale,
|
|
349
|
+
speechRecognitionEndpointId: context.speechRecognitionEndpointId,
|
|
350
|
+
}),
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getToken.d.ts","sourceRoot":"","sources":["../src/getToken.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,iDAanB,CAAC"}
|
package/dist/getToken.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getToken = void 0;
|
|
13
|
+
const xstate_1 = require("xstate");
|
|
14
|
+
exports.getToken = (0, xstate_1.fromPromise)(({ input }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
if (typeof input.credentials === "string") {
|
|
16
|
+
return fetch(new Request(input.credentials)).then((data) => data.text());
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return fetch(new Request(input.credentials.endpoint, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: {
|
|
22
|
+
"Ocp-Apim-Subscription-Key": input.credentials.key,
|
|
23
|
+
},
|
|
24
|
+
})).then((data) => data.text());
|
|
25
|
+
}
|
|
26
|
+
}));
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,MAAM,EACN,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.speechstate = void 0;
|
|
4
|
+
var speechstate_1 = require("./speechstate");
|
|
5
|
+
Object.defineProperty(exports, "speechstate", { enumerable: true, get: function () { return speechstate_1.speechstate; } });
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Settings, Agenda, Hypothesis, RecogniseParameters } from "./types";
|
|
2
|
+
interface SSContext {
|
|
3
|
+
settings: Settings;
|
|
4
|
+
audioContext?: AudioContext;
|
|
5
|
+
asrRef?: any;
|
|
6
|
+
ttsRef?: any;
|
|
7
|
+
}
|
|
8
|
+
/** events sent to the spawned `speechstate` machine **/
|
|
9
|
+
type SSEventExtIn = {
|
|
10
|
+
type: "PREPARE";
|
|
11
|
+
} | {
|
|
12
|
+
type: "CONTROL";
|
|
13
|
+
} | {
|
|
14
|
+
type: "STOP";
|
|
15
|
+
} | {
|
|
16
|
+
type: "SPEAK";
|
|
17
|
+
value: Agenda;
|
|
18
|
+
} | {
|
|
19
|
+
type: "LISTEN";
|
|
20
|
+
value: RecogniseParameters;
|
|
21
|
+
};
|
|
22
|
+
/** for sendParent, not type-checked */
|
|
23
|
+
type SSEventExtOut = {
|
|
24
|
+
type: "ASR_NOINPUT";
|
|
25
|
+
} | {
|
|
26
|
+
type: "ASRTTS_READY";
|
|
27
|
+
} | {
|
|
28
|
+
type: "ASR_STARTED";
|
|
29
|
+
} | {
|
|
30
|
+
type: "TTS_STARTED";
|
|
31
|
+
} | {
|
|
32
|
+
type: "SPEAK_COMPLETE";
|
|
33
|
+
} | {
|
|
34
|
+
type: "RECOGNISED";
|
|
35
|
+
value: Hypothesis[];
|
|
36
|
+
nluValue?: any;
|
|
37
|
+
};
|
|
38
|
+
type SSEventIntIn = {
|
|
39
|
+
type: "TTS_READY";
|
|
40
|
+
} | {
|
|
41
|
+
type: "ASR_READY";
|
|
42
|
+
} | {
|
|
43
|
+
type: "TTS_ERROR";
|
|
44
|
+
};
|
|
45
|
+
type SSEvent = SSEventIntIn | SSEventExtIn | SSEventExtOut;
|
|
46
|
+
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").EventObject, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, SSEvent, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, string, import("xstate").EventObject>>;
|
|
47
|
+
export { speechstate };
|
|
48
|
+
//# sourceMappingURL=speechstate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speechstate.d.ts","sourceRoot":"","sources":["../src/speechstate.ts"],"names":[],"mappings":"AAUA,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,wDAAwD;AACxD,KAAK,YAAY,GACb;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,QAAQ,CAAC;IAAC,KAAK,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAEnD,uCAAuC;AACvC,KAAK,aAAa,GACd;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,UAAU,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC;AAEhE,KAAK,YAAY,GACb;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1B,KAAK,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,aAAa,CAAC;AAE3D,QAAA,MAAM,WAAW,ghBAqThB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|