speechstate 2.0.3 → 2.0.5

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.
@@ -1 +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;I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,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,ghBA0UhB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -10,252 +10,273 @@ const speechstate = (0, xstate_1.createMachine)({
10
10
  settings: input,
11
11
  }),
12
12
  id: "speechstate",
13
- type: "parallel",
13
+ initial: "Active",
14
14
  states: {
15
- AsrTtsSpawner: {
16
- initial: "Idle",
17
- on: {
18
- STOP: { target: ".Stopped", actions: (0, xstate_1.assign)({ audioContext: null }) },
19
- },
15
+ Stopped: {
16
+ meta: { view: "stopped" },
17
+ entry: [
18
+ (0, xstate_1.stopChild)("ttsRef"),
19
+ (0, xstate_1.stopChild)("asrRef"),
20
+ (0, xstate_1.assign)({
21
+ audioContext: undefined,
22
+ ttsRef: undefined,
23
+ asrRef: undefined,
24
+ }),
25
+ () => console.debug("[SpSt] destroyed ASR and TTS"),
26
+ ],
27
+ },
28
+ Active: {
29
+ type: "parallel",
20
30
  states: {
21
- Idle: { on: { PREPARE: "CreateAudioContext" } },
22
- CreateAudioContext: {
23
- invoke: {
24
- id: "createAudioContext",
25
- src: "audioContext",
26
- onDone: {
27
- target: "Spawn",
28
- actions: (0, xstate_1.assign)({ audioContext: ({ event }) => event.output }),
31
+ AsrTtsSpawner: {
32
+ initial: "Idle",
33
+ states: {
34
+ Idle: { on: { PREPARE: "CreateAudioContext" } },
35
+ CreateAudioContext: {
36
+ invoke: {
37
+ id: "createAudioContext",
38
+ src: "audioContext",
39
+ onDone: {
40
+ target: "Spawn",
41
+ actions: (0, xstate_1.assign)({
42
+ audioContext: ({ event }) => event.output,
43
+ }),
44
+ },
45
+ },
29
46
  },
30
- },
31
- },
32
- Spawn: {
33
- entry: [
34
- (0, xstate_1.assign)({
35
- ttsRef: ({ context, spawn }) => {
36
- return spawn(tts_1.ttsMachine, {
37
- id: "ttsRef",
38
- input: {
39
- ttsDefaultVoice: context.settings.ttsDefaultVoice,
40
- audioContext: context.audioContext,
41
- azureCredentials: context.settings.azureCredentials,
47
+ Spawn: {
48
+ entry: [
49
+ (0, xstate_1.assign)({
50
+ ttsRef: ({ context, spawn }) => {
51
+ return spawn(tts_1.ttsMachine, {
52
+ id: "ttsRef",
53
+ input: {
54
+ ttsDefaultVoice: context.settings.ttsDefaultVoice,
55
+ audioContext: context.audioContext,
56
+ azureCredentials: context.settings.azureCredentials,
57
+ },
58
+ });
42
59
  },
43
- });
44
- },
45
- }),
46
- (0, xstate_1.assign)({
47
- asrRef: ({ context, spawn }) => {
48
- return spawn(asr_1.asrMachine, {
49
- id: "asrRef",
50
- input: {
51
- asrDefaultCompleteTimeout: context.settings.asrDefaultCompleteTimeout,
52
- asrDefaultNoInputTimeout: context.settings.asrDefaultNoInputTimeout,
53
- locale: context.settings.locale,
54
- audioContext: context.audioContext,
55
- azureCredentials: context.settings.azureCredentials,
56
- azureLanguageCredentials: context.settings.azureLanguageCredentials,
57
- speechRecognitionEndpointId: context.settings.speechRecognitionEndpointId,
60
+ }),
61
+ (0, xstate_1.assign)({
62
+ asrRef: ({ context, spawn }) => {
63
+ return spawn(asr_1.asrMachine, {
64
+ id: "asrRef",
65
+ input: {
66
+ asrDefaultCompleteTimeout: context.settings.asrDefaultCompleteTimeout,
67
+ asrDefaultNoInputTimeout: context.settings.asrDefaultNoInputTimeout,
68
+ locale: context.settings.locale,
69
+ audioContext: context.audioContext,
70
+ azureCredentials: context.settings.azureCredentials,
71
+ azureLanguageCredentials: context.settings.azureLanguageCredentials,
72
+ speechRecognitionEndpointId: context.settings.speechRecognitionEndpointId,
73
+ },
74
+ });
58
75
  },
59
- });
76
+ }),
77
+ ],
78
+ after: {
79
+ 300000: {
80
+ target: "Spawn",
81
+ reenter: true,
82
+ actions: [
83
+ ({}) => console.debug("[SpSt] respawning ASR and TTS"),
84
+ (0, xstate_1.stopChild)("ttsRef"),
85
+ (0, xstate_1.stopChild)("asrRef"),
86
+ (0, xstate_1.assign)({
87
+ audioContext: undefined,
88
+ ttsRef: undefined,
89
+ asrRef: undefined,
90
+ }),
91
+ ],
92
+ },
60
93
  },
61
- }),
62
- ],
63
- exit: [
64
- (0, xstate_1.stopChild)("ttsRef"),
65
- (0, xstate_1.stopChild)("asrRef"),
66
- (0, xstate_1.assign)({ ttsRef: undefined, asrRef: undefined }),
67
- ],
68
- after: {
69
- 300000: {
70
- target: "Spawn",
71
- reenter: true,
72
94
  },
73
95
  },
74
96
  },
75
- Stopped: {},
76
- },
77
- },
78
- AsrTtsManager: {
79
- initial: "Initialize",
80
- on: {
81
- TTS_READY: {
82
- actions: () => console.debug("[TTS→SpSt] TTS_READY"),
83
- target: ".PreReady",
84
- },
85
- ASR_READY: {
86
- actions: () => console.debug("[ASR→SpSt] ASR_READY"),
87
- target: ".PreReady",
88
- },
89
- // ASR_ERROR not implemented
90
- TTS_ERROR: {
91
- actions: () => console.error("[TTS→SpSt] TTS_ERROR"),
92
- target: ".Fail",
93
- },
94
- ASR_NOINPUT: {
95
- actions: [
96
- () => console.debug("[ASR→SpSt] NOINPUT"),
97
- (0, xstate_1.sendParent)({ type: "ASR_NOINPUT" }),
98
- ],
99
- target: ".Ready",
100
- },
101
- STOP: ".Stopped",
102
- },
103
- states: {
104
- Initialize: {
105
- meta: { view: "not-ready" },
106
- },
107
- PreReady: {
108
- meta: { view: "not-ready" },
97
+ AsrTtsManager: {
98
+ initial: "Initialize",
109
99
  on: {
110
100
  TTS_READY: {
111
101
  actions: () => console.debug("[TTS→SpSt] TTS_READY"),
112
- target: "Ready",
102
+ target: ".PreReady",
113
103
  },
114
104
  ASR_READY: {
115
105
  actions: () => console.debug("[ASR→SpSt] ASR_READY"),
116
- target: "Ready",
106
+ target: ".PreReady",
117
107
  },
108
+ // ASR_ERROR not implemented
109
+ TTS_ERROR: {
110
+ actions: () => console.error("[TTS→SpSt] TTS_ERROR"),
111
+ target: ".Fail",
112
+ },
113
+ ASR_NOINPUT: {
114
+ actions: [
115
+ () => console.debug("[ASR→SpSt] NOINPUT"),
116
+ (0, xstate_1.sendParent)({ type: "ASR_NOINPUT" }),
117
+ ],
118
+ target: ".Ready",
119
+ },
120
+ STOP: "#speechstate.Stopped",
118
121
  },
119
- },
120
- Ready: {
121
- initial: "Idle",
122
- entry: [
123
- () => console.debug("[SpSt] All ready"),
124
- (0, xstate_1.sendParent)({ type: "ASRTTS_READY" }),
125
- ],
126
122
  states: {
127
- Idle: {
128
- meta: { view: "idle" },
123
+ Initialize: {
124
+ meta: { view: "not-ready" },
125
+ },
126
+ PreReady: {
127
+ meta: { view: "not-ready" },
129
128
  on: {
130
- LISTEN: { target: "WaitForRecogniser" },
131
- SPEAK: [
132
- {
133
- target: "Speaking",
134
- },
135
- ],
129
+ TTS_READY: {
130
+ actions: () => console.debug("[TTS→SpSt] TTS_READY"),
131
+ target: "Ready",
132
+ },
133
+ ASR_READY: {
134
+ actions: () => console.debug("[ASR→SpSt] ASR_READY"),
135
+ target: "Ready",
136
+ },
136
137
  },
137
138
  },
138
- Speaking: {
139
- initial: "Proceed",
139
+ Ready: {
140
+ initial: "Idle",
140
141
  entry: [
141
- ({ event }) => console.debug("[SpSt→TTS] SPEAK", event.value),
142
- ({ context, event }) => context.ttsRef.send({
143
- type: "SPEAK",
144
- value: event.value,
145
- }),
142
+ () => console.debug("[SpSt] All ready"),
143
+ (0, xstate_1.sendParent)({ type: "ASRTTS_READY" }),
146
144
  ],
147
- on: {
148
- STOP: {
149
- target: "#speechstate.AsrTtsManager.Stopped",
150
- actions: [
151
- () => console.debug("[SpSt→TTS] STOP"),
152
- ({ context }) => context.ttsRef.send({
153
- type: "STOP",
154
- }),
155
- ],
145
+ states: {
146
+ Idle: {
147
+ meta: { view: "idle" },
148
+ on: {
149
+ LISTEN: { target: "WaitForRecogniser" },
150
+ SPEAK: [
151
+ {
152
+ target: "Speaking",
153
+ },
154
+ ],
155
+ },
156
156
  },
157
- TTS_STARTED: {
158
- actions: [
159
- () => console.debug("[TTS→SpSt] TTS_STARTED"),
160
- (0, xstate_1.sendParent)({ type: "TTS_STARTED" }),
157
+ Speaking: {
158
+ initial: "Proceed",
159
+ entry: [
160
+ ({ event }) => console.debug("[SpSt→TTS] SPEAK", event.value),
161
+ ({ context, event }) => context.ttsRef.send({
162
+ type: "SPEAK",
163
+ value: event.value,
164
+ }),
161
165
  ],
166
+ on: {
167
+ STOP: {
168
+ target: "#speechstate.Stopped",
169
+ actions: [
170
+ ({}) => console.debug("[SpSt→TTS] STOP"),
171
+ ({ context, event }) => context.ttsRef.send({
172
+ type: "STOP",
173
+ }),
174
+ ],
175
+ },
176
+ TTS_STARTED: {
177
+ actions: [
178
+ () => console.debug("[TTS→SpSt] TTS_STARTED"),
179
+ (0, xstate_1.sendParent)({ type: "TTS_STARTED" }),
180
+ ],
181
+ },
182
+ SPEAK_COMPLETE: {
183
+ target: "Idle",
184
+ actions: [
185
+ () => console.debug("[TTS→SpSt] SPEAK_COMPLETE"),
186
+ (0, xstate_1.sendParent)({ type: "SPEAK_COMPLETE" }),
187
+ ],
188
+ },
189
+ },
190
+ states: {
191
+ Proceed: {
192
+ meta: { view: "speaking" },
193
+ on: {
194
+ CONTROL: {
195
+ target: "Paused",
196
+ actions: [
197
+ () => console.debug("[SpSt→TTS] CONTROL"),
198
+ ({ context }) => context.ttsRef.send({
199
+ type: "CONTROL",
200
+ }),
201
+ ],
202
+ },
203
+ },
204
+ },
205
+ Paused: {
206
+ meta: { view: "speaking-paused" },
207
+ on: {
208
+ CONTROL: {
209
+ target: "Proceed",
210
+ actions: [
211
+ () => console.debug("[SpSt→TTS] CONTROL"),
212
+ ({ context }) => context.ttsRef.send({
213
+ type: "CONTROL",
214
+ }),
215
+ ],
216
+ },
217
+ },
218
+ },
219
+ },
162
220
  },
163
- SPEAK_COMPLETE: {
164
- target: "Idle",
165
- actions: [
166
- () => console.debug("[TTS→SpSt] SPEAK_COMPLETE"),
167
- (0, xstate_1.sendParent)({ type: "SPEAK_COMPLETE" }),
221
+ WaitForRecogniser: {
222
+ meta: { view: "idle" },
223
+ entry: [
224
+ ({ event }) => console.debug("[SpSt→ASR] START", event.value),
225
+ ({ context, event }) => context.asrRef.send({
226
+ type: "START",
227
+ value: event.value,
228
+ }),
168
229
  ],
169
- },
170
- },
171
- states: {
172
- Proceed: {
173
- meta: { view: "speaking" },
174
230
  on: {
175
- CONTROL: {
176
- target: "Paused",
231
+ ASR_STARTED: {
232
+ target: "Recognising",
177
233
  actions: [
178
- () => console.debug("[SpSt→TTS] CONTROL"),
179
- ({ context }) => context.ttsRef.send({
180
- type: "CONTROL",
181
- }),
234
+ () => console.debug("[ASR→SpSt] ASR_STARTED"),
235
+ (0, xstate_1.sendParent)({ type: "ASR_STARTED" }),
182
236
  ],
183
237
  },
184
238
  },
185
239
  },
186
- Paused: {
187
- meta: { view: "speaking-paused" },
240
+ Recognising: {
241
+ meta: { view: "recognising" },
188
242
  on: {
189
243
  CONTROL: {
190
- target: "Proceed",
244
+ /** TODO go to paused state? */
191
245
  actions: [
192
- () => console.debug("[SpSt→TTS] CONTROL"),
193
- ({ context }) => context.ttsRef.send({
246
+ () => console.debug("[SpSt→ASR] CONTROL"),
247
+ ({ context }) => context.asrRef.send({
194
248
  type: "CONTROL",
195
249
  }),
196
250
  ],
197
251
  },
252
+ STOP: {
253
+ target: "#speechstate.Stopped",
254
+ actions: [
255
+ () => console.debug("[SpSt→ASR] STOP"),
256
+ ({ context }) => context.asrRef.send({
257
+ type: "STOP",
258
+ }),
259
+ ],
260
+ },
261
+ RECOGNISED: {
262
+ actions: [
263
+ ({ event }) => console.debug("[ASR→SpSt] RECOGNISED", event.value, event.nluValue),
264
+ (0, xstate_1.sendParent)(({ event }) => ({
265
+ type: "RECOGNISED",
266
+ value: event.value,
267
+ nluValue: event.nluValue,
268
+ })),
269
+ ],
270
+ target: "Idle",
271
+ },
198
272
  },
199
273
  },
200
274
  },
201
275
  },
202
- WaitForRecogniser: {
203
- meta: { view: "idle" },
204
- entry: [
205
- ({ event }) => console.debug("[SpSt→ASR] START", event.value),
206
- ({ context, event }) => context.asrRef.send({
207
- type: "START",
208
- value: event.value,
209
- }),
210
- ],
211
- on: {
212
- ASR_STARTED: {
213
- target: "Recognising",
214
- actions: [
215
- () => console.debug("[ASR→SpSt] ASR_STARTED"),
216
- (0, xstate_1.sendParent)({ type: "ASR_STARTED" }),
217
- ],
218
- },
219
- },
220
- },
221
- Recognising: {
222
- meta: { view: "recognising" },
223
- on: {
224
- CONTROL: {
225
- /** TODO go to paused state? */
226
- actions: [
227
- () => console.debug("[SpSt→ASR] CONTROL"),
228
- ({ context }) => context.asrRef.send({
229
- type: "CONTROL",
230
- }),
231
- ],
232
- },
233
- STOP: {
234
- target: "#speechstate.AsrTtsManager.Stopped",
235
- actions: [
236
- () => console.debug("[SpSt→ASR] STOP"),
237
- ({ context }) => context.asrRef.send({
238
- type: "STOP",
239
- }),
240
- ],
241
- },
242
- RECOGNISED: {
243
- actions: [
244
- ({ event }) => console.debug("[ASR→SpSt] RECOGNISED", event.value, event.nluValue),
245
- (0, xstate_1.sendParent)(({ event }) => ({
246
- type: "RECOGNISED",
247
- value: event.value,
248
- nluValue: event.nluValue,
249
- })),
250
- ],
251
- target: "Idle",
252
- },
253
- },
254
- },
276
+ Fail: { meta: { view: "error" } },
277
+ Stopped: { meta: { view: "stopped" } },
255
278
  },
256
279
  },
257
- Fail: { meta: { view: "error" } },
258
- Stopped: { meta: { view: "stopped" } },
259
280
  },
260
281
  },
261
282
  },
package/dist/tts.js CHANGED
@@ -66,8 +66,8 @@ exports.ttsMachine = (0, xstate_1.setup)({
66
66
  }),
67
67
  start: (0, xstate_1.fromCallback)(({ sendBack, input }) => {
68
68
  if (["", " "].includes(input.utterance)) {
69
- console.debug("[TTS] SPEAK: ", input.utterance);
70
- input.wsaTTS.speak("");
69
+ console.debug("[TTS] SPEAK: (empty utterance)");
70
+ sendBack({ type: "SPEAK_COMPLETE" });
71
71
  }
72
72
  else {
73
73
  console.debug("[TTS] SPEAK: ", input.utterance);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speechstate",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "license": "GPL-3.0",
5
5
  "homepage": "http://localhost/speechstate",
6
6
  "main": "./dist/index.js",