speechstate 2.0.0-beta.9 → 2.0.1
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/package.json +13 -4
- package/README.plantuml +0 -3
- package/README.png +0 -0
- package/dist/asr.d.ts +0 -117
- package/dist/asr.d.ts.map +0 -1
- package/dist/asr.js +0 -354
- package/dist/getToken.d.ts +0 -2
- package/dist/getToken.d.ts.map +0 -1
- package/dist/getToken.js +0 -26
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -5
- package/dist/speechstate.d.ts +0 -48
- package/dist/speechstate.d.ts.map +0 -1
- package/dist/speechstate.js +0 -247
- package/dist/tts.d.ts +0 -42
- package/dist/tts.d.ts.map +0 -1
- package/dist/tts.js +0 -182
- package/dist/types.d.ts +0 -41
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "speechstate",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"license": "GPL-3.0",
|
|
5
5
|
"homepage": "http://localhost/speechstate",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"files": [
|
|
8
|
+
"files": [
|
|
9
|
+
"/dist"
|
|
10
|
+
],
|
|
9
11
|
"dependencies": {
|
|
10
12
|
"@statelyai/inspect": "^0.2.3",
|
|
11
13
|
"microsoft-cognitiveservices-speech-sdk": "^1.31.0",
|
|
@@ -18,10 +20,17 @@
|
|
|
18
20
|
"test": "jest --silent=false"
|
|
19
21
|
},
|
|
20
22
|
"eslintConfig": {
|
|
21
|
-
"extends": [
|
|
23
|
+
"extends": [
|
|
24
|
+
"react-app",
|
|
25
|
+
"react-app/jest"
|
|
26
|
+
]
|
|
22
27
|
},
|
|
23
28
|
"browserslist": {
|
|
24
|
-
"production": [
|
|
29
|
+
"production": [
|
|
30
|
+
">0.2%",
|
|
31
|
+
"not dead",
|
|
32
|
+
"not op_mini all"
|
|
33
|
+
],
|
|
25
34
|
"development": [
|
|
26
35
|
"last 1 chrome version",
|
|
27
36
|
"last 1 firefox version",
|
package/README.plantuml
DELETED
package/README.png
DELETED
|
Binary file
|
package/dist/asr.d.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
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").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>>;
|
|
116
|
-
export {};
|
|
117
|
-
//# sourceMappingURL=asr.d.ts.map
|
package/dist/asr.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,CAA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AC;IAClD,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;CACrD;AAED,eAAO,MAAM,UAAU;;;;;eAiF8C,MAAM;;;;;;;;;;;;;;;;;;;;eAAN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;eAAN,MAAM;;;;;;;;;mBA6RzE,CAAC"}
|
package/dist/asr.js
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
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
|
-
});
|
package/dist/getToken.d.ts
DELETED
package/dist/getToken.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getToken.d.ts","sourceRoot":"","sources":["../src/getToken.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,iDAanB,CAAC"}
|
package/dist/getToken.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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; } });
|
package/dist/speechstate.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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").ResolveTypegenMeta<import("xstate").TypegenDisabled, SSEvent, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, string>>;
|
|
47
|
-
export { speechstate };
|
|
48
|
-
//# sourceMappingURL=speechstate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"speechstate.d.ts","sourceRo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EAAE,WAAW,EAAE,CAAC"}
|
package/dist/speechstate.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.speechstate = void 0;
|
|
4
|
-
const xstate_1 = require("xstate");
|
|
5
|
-
const tts_1 = require("./tts");
|
|
6
|
-
const asr_1 = require("./asr");
|
|
7
|
-
const speechstate = (0, xstate_1.createMachine)({
|
|
8
|
-
types: {},
|
|
9
|
-
context: ({ input }) => ({
|
|
10
|
-
settings: input,
|
|
11
|
-
}),
|
|
12
|
-
id: "speechstate",
|
|
13
|
-
type: "parallel",
|
|
14
|
-
states: {
|
|
15
|
-
AsrTtsSpawner: {
|
|
16
|
-
initial: "Idle",
|
|
17
|
-
states: {
|
|
18
|
-
Idle: { on: { PREPARE: "CreateAudioContext" } },
|
|
19
|
-
CreateAudioContext: {
|
|
20
|
-
invoke: {
|
|
21
|
-
id: "createAudioContext",
|
|
22
|
-
src: "audioContext",
|
|
23
|
-
onDone: {
|
|
24
|
-
target: "Spawn",
|
|
25
|
-
actions: (0, xstate_1.assign)({ audioContext: ({ event }) => event.output }),
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
Spawn: {
|
|
30
|
-
entry: [
|
|
31
|
-
(0, xstate_1.assign)({
|
|
32
|
-
ttsRef: ({ context, spawn }) => {
|
|
33
|
-
return spawn(tts_1.ttsMachine, {
|
|
34
|
-
input: {
|
|
35
|
-
ttsDefaultVoice: context.settings.ttsDefaultVoice,
|
|
36
|
-
audioContext: context.audioContext,
|
|
37
|
-
azureCredentials: context.settings.azureCredentials,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
}),
|
|
42
|
-
(0, xstate_1.assign)({
|
|
43
|
-
asrRef: ({ context, spawn }) => {
|
|
44
|
-
return spawn(asr_1.asrMachine, {
|
|
45
|
-
input: {
|
|
46
|
-
asrDefaultCompleteTimeout: context.settings.asrDefaultCompleteTimeout,
|
|
47
|
-
asrDefaultNoInputTimeout: context.settings.asrDefaultNoInputTimeout,
|
|
48
|
-
locale: context.settings.locale,
|
|
49
|
-
audioContext: context.audioContext,
|
|
50
|
-
azureCredentials: context.settings.azureCredentials,
|
|
51
|
-
azureLanguageCredentials: context.settings.azureLanguageCredentials,
|
|
52
|
-
speechRecognitionEndpointId: context.settings.speechRecognitionEndpointId,
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
}),
|
|
57
|
-
],
|
|
58
|
-
after: {
|
|
59
|
-
300000: {
|
|
60
|
-
target: "Spawn",
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
AsrTtsManager: {
|
|
67
|
-
initial: "Initialize",
|
|
68
|
-
on: {
|
|
69
|
-
TTS_READY: {
|
|
70
|
-
actions: () => console.debug("[TTS→SpSt] TTS_READY"),
|
|
71
|
-
target: ".PreReady",
|
|
72
|
-
},
|
|
73
|
-
ASR_READY: {
|
|
74
|
-
actions: () => console.debug("[ASR→SpSt] ASR_READY"),
|
|
75
|
-
target: ".PreReady",
|
|
76
|
-
},
|
|
77
|
-
// ASR_ERROR not implemented
|
|
78
|
-
TTS_ERROR: {
|
|
79
|
-
actions: () => console.error("[TTS→SpSt] TTS_ERROR"),
|
|
80
|
-
target: ".Fail",
|
|
81
|
-
},
|
|
82
|
-
ASR_NOINPUT: {
|
|
83
|
-
actions: [
|
|
84
|
-
() => console.debug("[ASR→SpSt] NOINPUT"),
|
|
85
|
-
(0, xstate_1.sendParent)({ type: "ASR_NOINPUT" }),
|
|
86
|
-
],
|
|
87
|
-
target: ".Ready",
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
states: {
|
|
91
|
-
Initialize: {},
|
|
92
|
-
PreReady: {
|
|
93
|
-
on: {
|
|
94
|
-
TTS_READY: {
|
|
95
|
-
actions: () => console.debug("[TTS→SpSt] TTS_READY"),
|
|
96
|
-
target: "Ready",
|
|
97
|
-
},
|
|
98
|
-
ASR_READY: {
|
|
99
|
-
actions: () => console.debug("[ASR→SpSt] ASR_READY"),
|
|
100
|
-
target: "Ready",
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
Ready: {
|
|
105
|
-
initial: "Idle",
|
|
106
|
-
entry: [
|
|
107
|
-
() => console.debug("[SpSt] All ready"),
|
|
108
|
-
(0, xstate_1.sendParent)({ type: "ASRTTS_READY" }),
|
|
109
|
-
],
|
|
110
|
-
states: {
|
|
111
|
-
Idle: {
|
|
112
|
-
on: {
|
|
113
|
-
LISTEN: { target: "WaitForRecogniser" },
|
|
114
|
-
SPEAK: [
|
|
115
|
-
{
|
|
116
|
-
target: "Speaking",
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
Speaking: {
|
|
122
|
-
entry: [
|
|
123
|
-
({ event }) => console.debug("[SpSt→TTS] SPEAK", event.value),
|
|
124
|
-
({ context, event }) => context.ttsRef.send({
|
|
125
|
-
type: "SPEAK",
|
|
126
|
-
value: event.value,
|
|
127
|
-
}),
|
|
128
|
-
],
|
|
129
|
-
on: {
|
|
130
|
-
CONTROL: {
|
|
131
|
-
actions: [
|
|
132
|
-
() => console.debug("[SpSt→TTS] CONTROL"),
|
|
133
|
-
({ context }) => context.ttsRef.send({
|
|
134
|
-
type: "CONTROL",
|
|
135
|
-
}),
|
|
136
|
-
],
|
|
137
|
-
},
|
|
138
|
-
STOP: {
|
|
139
|
-
actions: [
|
|
140
|
-
() => console.debug("[SpSt→TTS] STOP"),
|
|
141
|
-
({ context }) => context.ttsRef.send({
|
|
142
|
-
type: "STOP",
|
|
143
|
-
}),
|
|
144
|
-
],
|
|
145
|
-
},
|
|
146
|
-
TTS_STARTED: {
|
|
147
|
-
actions: [
|
|
148
|
-
() => console.debug("[TTS→SpSt] TTS_STARTED"),
|
|
149
|
-
(0, xstate_1.sendParent)({ type: "TTS_STARTED" }),
|
|
150
|
-
],
|
|
151
|
-
},
|
|
152
|
-
SPEAK_COMPLETE: {
|
|
153
|
-
target: "Idle",
|
|
154
|
-
actions: [
|
|
155
|
-
() => console.debug("[TTS→SpSt] SPEAK_COMPLETE"),
|
|
156
|
-
(0, xstate_1.sendParent)({ type: "SPEAK_COMPLETE" }),
|
|
157
|
-
],
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
WaitForRecogniser: {
|
|
162
|
-
entry: [
|
|
163
|
-
({ event }) => console.debug("[SpSt→ASR] START", event.value),
|
|
164
|
-
({ context, event }) => context.asrRef.send({
|
|
165
|
-
type: "START",
|
|
166
|
-
value: event.value,
|
|
167
|
-
}),
|
|
168
|
-
],
|
|
169
|
-
on: {
|
|
170
|
-
ASR_STARTED: {
|
|
171
|
-
target: "Recognising",
|
|
172
|
-
actions: [
|
|
173
|
-
() => console.debug("[ASR→SpSt] ASR_STARTED"),
|
|
174
|
-
(0, xstate_1.sendParent)({ type: "ASR_STARTED" }),
|
|
175
|
-
],
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
Recognising: {
|
|
180
|
-
on: {
|
|
181
|
-
CONTROL: {
|
|
182
|
-
actions: [
|
|
183
|
-
() => console.debug("[SpSt→ASR] CONTROL"),
|
|
184
|
-
({ context }) => context.asrRef.send({
|
|
185
|
-
type: "CONTROL",
|
|
186
|
-
}),
|
|
187
|
-
],
|
|
188
|
-
},
|
|
189
|
-
STOP: {
|
|
190
|
-
target: "Idle",
|
|
191
|
-
actions: [
|
|
192
|
-
() => console.debug("[SpSt→ASR] STOP"),
|
|
193
|
-
({ context }) => context.asrRef.send({
|
|
194
|
-
type: "STOP",
|
|
195
|
-
}),
|
|
196
|
-
],
|
|
197
|
-
},
|
|
198
|
-
RECOGNISED: {
|
|
199
|
-
actions: [
|
|
200
|
-
({ event }) => console.debug("[ASR→SpSt] RECOGNISED", event.value, event.nluValue),
|
|
201
|
-
(0, xstate_1.sendParent)(({ event }) => ({
|
|
202
|
-
type: "RECOGNISED",
|
|
203
|
-
value: event.value,
|
|
204
|
-
nluValue: event.nluValue,
|
|
205
|
-
})),
|
|
206
|
-
],
|
|
207
|
-
target: "Idle",
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
Fail: {},
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
}, {
|
|
218
|
-
actors: {
|
|
219
|
-
audioContext: (0, xstate_1.fromPromise)(() => {
|
|
220
|
-
const audioContext = new (window.AudioContext ||
|
|
221
|
-
window.webkitAudioContext)();
|
|
222
|
-
navigator.mediaDevices
|
|
223
|
-
.getUserMedia({ audio: true })
|
|
224
|
-
.then(function (stream) {
|
|
225
|
-
audioContext.createMediaStreamSource(stream);
|
|
226
|
-
});
|
|
227
|
-
return audioContext;
|
|
228
|
-
}),
|
|
229
|
-
},
|
|
230
|
-
actions: {
|
|
231
|
-
// logRecResult: ({ event }) => {
|
|
232
|
-
// console.log("U>", (event as any).value[0]["utterance"], {
|
|
233
|
-
// confidence: (event as any).value[0]["confidence"],
|
|
234
|
-
// });
|
|
235
|
-
// },
|
|
236
|
-
// logAgenda: ({ context, event }) => {
|
|
237
|
-
// console.log("S>", (event as any).value, {
|
|
238
|
-
// passivity: `${context.tdmPassivity ?? "∞"} ms`,
|
|
239
|
-
// speechCompleteTimeout: `${
|
|
240
|
-
// context.tdmSpeechCompleteTimeout ||
|
|
241
|
-
// context.settings.completeTimeout
|
|
242
|
-
// } ms`,
|
|
243
|
-
// });
|
|
244
|
-
// },
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
exports.speechstate = speechstate;
|
package/dist/tts.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { AzureCredentials, Agenda } from "./types";
|
|
2
|
-
interface MySpeechSynthesisUtterance extends SpeechSynthesisUtterance {
|
|
3
|
-
new (s: string): any;
|
|
4
|
-
}
|
|
5
|
-
interface TTSInit {
|
|
6
|
-
audioContext: AudioContext;
|
|
7
|
-
azureCredentials: string | AzureCredentials;
|
|
8
|
-
ttsDefaultVoice: string;
|
|
9
|
-
}
|
|
10
|
-
interface TTSContext extends TTSInit {
|
|
11
|
-
azureAuthorizationToken?: string;
|
|
12
|
-
ttsLexicon?: string;
|
|
13
|
-
wsaTTS?: SpeechSynthesis;
|
|
14
|
-
wsaVoice?: SpeechSynthesisVoice;
|
|
15
|
-
wsaUtt?: MySpeechSynthesisUtterance;
|
|
16
|
-
agenda?: Agenda;
|
|
17
|
-
}
|
|
18
|
-
type TTSEvent = {
|
|
19
|
-
type: "PREPARE";
|
|
20
|
-
} | {
|
|
21
|
-
type: "CONTROL";
|
|
22
|
-
} | {
|
|
23
|
-
type: "STOP";
|
|
24
|
-
} | {
|
|
25
|
-
type: "READY";
|
|
26
|
-
value: {
|
|
27
|
-
wsaTTS: SpeechSynthesis;
|
|
28
|
-
wsaUtt: MySpeechSynthesisUtterance;
|
|
29
|
-
};
|
|
30
|
-
} | {
|
|
31
|
-
type: "ERROR";
|
|
32
|
-
} | {
|
|
33
|
-
type: "SPEAK";
|
|
34
|
-
value: Agenda;
|
|
35
|
-
} | {
|
|
36
|
-
type: "TTS_STARTED";
|
|
37
|
-
} | {
|
|
38
|
-
type: "SPEAK_COMPLETE";
|
|
39
|
-
};
|
|
40
|
-
export declare const ttsMachine: import("xstate").StateMachine<TTSContext, TTSEvent, Record<string, import("xstate").AnyActorRef>, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, import("xstate").StateValue, string, TTSInit, {}, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, TTSEvent, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, string>>;
|
|
41
|
-
export {};
|
|
42
|
-
//# sourceMappingURL=tts.d.ts.map
|
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
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ttsMachine = void 0;
|
|
4
|
-
const xstate_1 = require("xstate");
|
|
5
|
-
const getToken_1 = require("./getToken");
|
|
6
|
-
const TextToSpeech_1 = require("web-speech-cognitive-services/lib/SpeechServices/TextToSpeech");
|
|
7
|
-
const REGION = "northeurope";
|
|
8
|
-
exports.ttsMachine = (0, xstate_1.createMachine)({
|
|
9
|
-
id: "tts",
|
|
10
|
-
types: {},
|
|
11
|
-
context: ({ input }) => ({
|
|
12
|
-
ttsDefaultVoice: input.ttsDefaultVoice || "en-US-DavisNeural",
|
|
13
|
-
audioContext: input.audioContext,
|
|
14
|
-
azureCredentials: input.azureCredentials,
|
|
15
|
-
}),
|
|
16
|
-
initial: "GetToken",
|
|
17
|
-
on: {
|
|
18
|
-
READY: {
|
|
19
|
-
target: ".Ready",
|
|
20
|
-
actions: [
|
|
21
|
-
(0, xstate_1.assign)({
|
|
22
|
-
wsaTTS: ({ event }) => event.value.wsaTTS,
|
|
23
|
-
wsaUtt: ({ event }) => event.value.wsaUtt,
|
|
24
|
-
}),
|
|
25
|
-
(0, xstate_1.sendParent)({ type: "TTS_READY" }),
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
ERROR: { actions: (0, xstate_1.sendParent)({ type: "TTS_ERROR" }) },
|
|
29
|
-
},
|
|
30
|
-
states: {
|
|
31
|
-
Ready: {
|
|
32
|
-
initial: "Idle",
|
|
33
|
-
states: {
|
|
34
|
-
Idle: {
|
|
35
|
-
on: {
|
|
36
|
-
SPEAK: {
|
|
37
|
-
target: "Speaking",
|
|
38
|
-
actions: (0, xstate_1.assign)({ agenda: ({ event }) => event.value }),
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
Speaking: {
|
|
43
|
-
initial: "Go",
|
|
44
|
-
on: {
|
|
45
|
-
STOP: {
|
|
46
|
-
target: "Idle",
|
|
47
|
-
},
|
|
48
|
-
TTS_STARTED: {
|
|
49
|
-
actions: (0, xstate_1.sendParent)({ type: "TTS_STARTED" }),
|
|
50
|
-
},
|
|
51
|
-
SPEAK_COMPLETE: {
|
|
52
|
-
target: "Idle",
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
exit: (0, xstate_1.sendParent)({ type: "SPEAK_COMPLETE" }),
|
|
56
|
-
states: {
|
|
57
|
-
Go: {
|
|
58
|
-
invoke: {
|
|
59
|
-
src: "start",
|
|
60
|
-
input: ({ context }) => ({
|
|
61
|
-
wsaTTS: context.wsaTTS,
|
|
62
|
-
wsaUtt: context.wsaUtt,
|
|
63
|
-
ttsLexicon: context.ttsLexicon,
|
|
64
|
-
voice: context.agenda.voice || context.ttsDefaultVoice,
|
|
65
|
-
// streamURL: context.agenda.streamURL,
|
|
66
|
-
utterance: context.agenda.utterance,
|
|
67
|
-
}),
|
|
68
|
-
},
|
|
69
|
-
on: {
|
|
70
|
-
CONTROL: "Paused",
|
|
71
|
-
},
|
|
72
|
-
exit: "ttsStop",
|
|
73
|
-
},
|
|
74
|
-
Paused: {
|
|
75
|
-
on: {
|
|
76
|
-
CONTROL: "Go",
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
Fail: {},
|
|
84
|
-
GetToken: {
|
|
85
|
-
invoke: {
|
|
86
|
-
id: "getAuthorizationToken",
|
|
87
|
-
input: ({ context }) => ({
|
|
88
|
-
credentials: context.azureCredentials,
|
|
89
|
-
}),
|
|
90
|
-
src: "getToken",
|
|
91
|
-
onDone: {
|
|
92
|
-
target: "Ponyfill",
|
|
93
|
-
actions: [
|
|
94
|
-
(0, xstate_1.assign)(({ event }) => {
|
|
95
|
-
return { azureAuthorizationToken: event.output };
|
|
96
|
-
}),
|
|
97
|
-
],
|
|
98
|
-
},
|
|
99
|
-
onError: {
|
|
100
|
-
actions: ({ event }) => console.error("[TTS] getToken error", event),
|
|
101
|
-
target: "Fail",
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
Ponyfill: {
|
|
106
|
-
invoke: {
|
|
107
|
-
id: "ponyTTS",
|
|
108
|
-
src: "ponyfill",
|
|
109
|
-
input: ({ context }) => ({
|
|
110
|
-
audioContext: context.audioContext,
|
|
111
|
-
azureAuthorizationToken: context.azureAuthorizationToken,
|
|
112
|
-
}),
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
}, {
|
|
117
|
-
actions: {
|
|
118
|
-
ttsStop: ({ context }) => {
|
|
119
|
-
context.wsaTTS.cancel();
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
actors: {
|
|
123
|
-
getToken: getToken_1.getToken,
|
|
124
|
-
ponyfill: (0, xstate_1.fromCallback)(({ sendBack, input }) => {
|
|
125
|
-
const ponyfill = (0, TextToSpeech_1.default)({
|
|
126
|
-
audioContext: input.audioContext,
|
|
127
|
-
credentials: {
|
|
128
|
-
region: REGION, // TODO
|
|
129
|
-
authorizationToken: input.azureAuthorizationToken,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
const { speechSynthesis, SpeechSynthesisUtterance } = ponyfill;
|
|
133
|
-
const tts = speechSynthesis;
|
|
134
|
-
const ttsUtterance = SpeechSynthesisUtterance;
|
|
135
|
-
tts.addEventListener("voiceschanged", () => {
|
|
136
|
-
const voices = tts.getVoices();
|
|
137
|
-
if (voices.length > 0) {
|
|
138
|
-
console.debug("[TTS] READY");
|
|
139
|
-
sendBack({
|
|
140
|
-
type: "READY",
|
|
141
|
-
value: { wsaTTS: tts, wsaUtt: ttsUtterance },
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
console.error("[TTS] No voices available");
|
|
146
|
-
sendBack({ type: "ERROR" });
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}),
|
|
150
|
-
start: (0, xstate_1.fromCallback)(({ sendBack, input }) => {
|
|
151
|
-
if (["", " "].includes(input.utterance)) {
|
|
152
|
-
console.debug("[TTS] SPEAK: ", input.utterance);
|
|
153
|
-
input.wsaTTS.speak("");
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
console.debug("[TTS] SPEAK: ", input.utterance);
|
|
157
|
-
const content = wrapSSML(input.utterance, input.voice, input.ttsLexicon, 1); // todo speech rate;
|
|
158
|
-
const utterance = new input.wsaUtt(content);
|
|
159
|
-
utterance.addEventListener("start", () => {
|
|
160
|
-
sendBack({ type: "TTS_STARTED" });
|
|
161
|
-
console.debug("[TTS] TTS_STARTED");
|
|
162
|
-
});
|
|
163
|
-
utterance.addEventListener("end", () => {
|
|
164
|
-
sendBack({ type: "SPEAK_COMPLETE" });
|
|
165
|
-
console.debug("[TTS] SPEAK_COMPLETE");
|
|
166
|
-
});
|
|
167
|
-
input.wsaTTS.speak(utterance);
|
|
168
|
-
}
|
|
169
|
-
}),
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
const wrapSSML = (text, voice, lexicon, speechRate) => {
|
|
173
|
-
let content = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xml:lang="en-US"><voice name="${voice}">`;
|
|
174
|
-
if (lexicon) {
|
|
175
|
-
content = content + `<lexicon uri="${lexicon}"/>`;
|
|
176
|
-
}
|
|
177
|
-
content =
|
|
178
|
-
content +
|
|
179
|
-
`<prosody rate="${speechRate}">` +
|
|
180
|
-
`${text}</prosody></voice></speak>`;
|
|
181
|
-
return content;
|
|
182
|
-
};
|
package/dist/types.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export interface AzureSpeechCredentials {
|
|
2
|
-
endpoint: string;
|
|
3
|
-
key: string;
|
|
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
|
-
}
|
|
16
|
-
export interface Settings {
|
|
17
|
-
locale?: string;
|
|
18
|
-
azureCredentials: string | AzureCredentials | AzureSpeechCredentials;
|
|
19
|
-
azureLanguageCredentials?: AzureLanguageCredentials;
|
|
20
|
-
asrDefaultCompleteTimeout?: number;
|
|
21
|
-
asrDefaultNoInputTimeout?: number;
|
|
22
|
-
ttsDefaultVoice?: string;
|
|
23
|
-
speechRecognitionEndpointId?: string;
|
|
24
|
-
}
|
|
25
|
-
export interface Agenda {
|
|
26
|
-
utterance: string;
|
|
27
|
-
voice?: string;
|
|
28
|
-
stream?: ReadableStream<string>;
|
|
29
|
-
}
|
|
30
|
-
export interface Hypothesis {
|
|
31
|
-
utterance: string;
|
|
32
|
-
confidence: number;
|
|
33
|
-
}
|
|
34
|
-
export interface RecogniseParameters {
|
|
35
|
-
noInputTimeout?: number;
|
|
36
|
-
completeTimeout?: number;
|
|
37
|
-
locale?: string;
|
|
38
|
-
hints?: string[];
|
|
39
|
-
nlu?: boolean | AzureLanguageCredentials;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/dist/types.js
DELETED