speechflow 2.1.0 → 2.1.2

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +14 -11
  3. package/package.json +6 -6
  4. package/speechflow-cli/dst/speechflow-node-a2a-vad.js +1 -1
  5. package/speechflow-cli/dst/speechflow-node-a2a-vad.js.map +1 -1
  6. package/speechflow-cli/dst/speechflow-node-a2t-deepgram.js +11 -7
  7. package/speechflow-cli/dst/speechflow-node-a2t-deepgram.js.map +1 -1
  8. package/speechflow-cli/dst/speechflow-node-t2t-sentence.d.ts +3 -3
  9. package/speechflow-cli/dst/speechflow-node-t2t-sentence.js +117 -100
  10. package/speechflow-cli/dst/speechflow-node-t2t-sentence.js.map +1 -1
  11. package/speechflow-cli/dst/{speechflow-node-a2t-assemblyai.d.ts → speechflow-node-t2t-simulator.d.ts} +1 -6
  12. package/speechflow-cli/dst/speechflow-node-t2t-simulator.js +128 -0
  13. package/speechflow-cli/dst/speechflow-node-t2t-simulator.js.map +1 -0
  14. package/speechflow-cli/dst/speechflow-node-xio-webrtc.js +2 -2
  15. package/speechflow-cli/dst/speechflow-node-xio-webrtc.js.map +1 -1
  16. package/speechflow-cli/dst/speechflow-util-queue.d.ts +9 -3
  17. package/speechflow-cli/dst/speechflow-util-queue.js +39 -17
  18. package/speechflow-cli/dst/speechflow-util-queue.js.map +1 -1
  19. package/speechflow-cli/dst/speechflow-util-stream.d.ts +1 -1
  20. package/speechflow-cli/dst/speechflow-util-stream.js +15 -15
  21. package/speechflow-cli/dst/speechflow-util-stream.js.map +1 -1
  22. package/speechflow-cli/etc/oxlint.jsonc +5 -3
  23. package/speechflow-cli/package.json +26 -23
  24. package/speechflow-cli/src/speechflow-node-a2a-vad.ts +1 -1
  25. package/speechflow-cli/src/speechflow-node-a2t-deepgram.ts +17 -14
  26. package/speechflow-cli/src/speechflow-node-t2t-sentence.ts +128 -112
  27. package/speechflow-cli/src/speechflow-node-xio-webrtc.ts +4 -4
  28. package/speechflow-cli/src/speechflow-util-queue.ts +44 -19
  29. package/speechflow-cli/src/speechflow-util-stream.ts +15 -15
  30. package/speechflow-ui-db/dst/app-font-fa-brands-400.woff2 +0 -0
  31. package/speechflow-ui-db/dst/app-font-fa-regular-400.woff2 +0 -0
  32. package/speechflow-ui-db/dst/app-font-fa-solid-900.woff2 +0 -0
  33. package/speechflow-ui-db/dst/app-font-fa-v4compatibility.woff2 +0 -0
  34. package/speechflow-ui-db/dst/index.css +1 -1
  35. package/speechflow-ui-db/dst/index.js +47 -46
  36. package/speechflow-ui-db/package.json +16 -14
  37. package/speechflow-ui-db/src/app.vue +2 -2
  38. package/speechflow-ui-st/dst/app-font-fa-brands-400.woff2 +0 -0
  39. package/speechflow-ui-st/dst/app-font-fa-regular-400.woff2 +0 -0
  40. package/speechflow-ui-st/dst/app-font-fa-solid-900.woff2 +0 -0
  41. package/speechflow-ui-st/dst/app-font-fa-v4compatibility.woff2 +0 -0
  42. package/speechflow-ui-st/dst/index.css +1 -1
  43. package/speechflow-ui-st/dst/index.js +65 -64
  44. package/speechflow-ui-st/etc/oxlint.jsonc +2 -1
  45. package/speechflow-ui-st/package.json +17 -15
  46. package/speechflow-cli/dst/speechflow-node-a2t-assemblyai.js +0 -275
  47. package/speechflow-cli/dst/speechflow-node-a2t-assemblyai.js.map +0 -1
  48. /package/speechflow-cli/package.d/{sherpa-onnx+1.12.23.patch → sherpa-onnx+1.12.25.patch} +0 -0
@@ -97,6 +97,7 @@ export type QueueElement = { type: string }
97
97
  export class QueuePointer<T extends QueueElement> extends EventEmitter {
98
98
  /* internal state */
99
99
  private index = 0
100
+ private silence = false
100
101
 
101
102
  /* construction */
102
103
  constructor (
@@ -107,6 +108,17 @@ export class QueuePointer<T extends QueueElement> extends EventEmitter {
107
108
  this.setMaxListeners(100)
108
109
  }
109
110
 
111
+ /* control silence operation */
112
+ silent (silence: boolean) {
113
+ this.silence = silence
114
+ }
115
+
116
+ /* notify about operation */
117
+ notify (event: string, info: any) {
118
+ if (!this.silence)
119
+ this.emit(event, info)
120
+ }
121
+
110
122
  /* positioning operations */
111
123
  maxPosition () {
112
124
  return this.queue.elements.length
@@ -114,7 +126,7 @@ export class QueuePointer<T extends QueueElement> extends EventEmitter {
114
126
  position (index?: number): number {
115
127
  if (index !== undefined) {
116
128
  this.index = Math.max(0, Math.min(index, this.queue.elements.length))
117
- this.emit("position", this.index)
129
+ this.notify("position", this.index)
118
130
  }
119
131
  return this.index
120
132
  }
@@ -125,19 +137,19 @@ export class QueuePointer<T extends QueueElement> extends EventEmitter {
125
137
  else if (num < 0)
126
138
  this.index = Math.max(this.index + num, 0)
127
139
  if (this.index !== indexOld)
128
- this.emit("position", { start: this.index })
140
+ this.notify("position", { start: this.index })
129
141
  }
130
142
  walkForwardUntil (type: T["type"]) {
131
143
  while (this.index < this.queue.elements.length
132
144
  && this.queue.elements[this.index].type !== type)
133
145
  this.index++
134
- this.emit("position", { start: this.index })
146
+ this.notify("position", { start: this.index })
135
147
  }
136
148
  walkBackwardUntil (type: T["type"]) {
137
149
  while (this.index > 0
138
150
  && this.queue.elements[this.index].type !== type)
139
151
  this.index--
140
- this.emit("position", { start: this.index })
152
+ this.notify("position", { start: this.index })
141
153
  }
142
154
 
143
155
  /* search operations */
@@ -146,7 +158,7 @@ export class QueuePointer<T extends QueueElement> extends EventEmitter {
146
158
  while (position < this.queue.elements.length
147
159
  && this.queue.elements[position].type !== type)
148
160
  position++
149
- this.emit("search", { start: this.index, end: position })
161
+ this.notify("search", { start: this.index, end: position })
150
162
  return position
151
163
  }
152
164
  searchBackward (type: T["type"]) {
@@ -154,24 +166,24 @@ export class QueuePointer<T extends QueueElement> extends EventEmitter {
154
166
  while (position > 0
155
167
  && this.queue.elements[position].type !== type)
156
168
  position--
157
- this.emit("search", { start: position, end: this.index })
169
+ this.notify("search", { start: position, end: this.index })
158
170
  return position
159
171
  }
160
172
 
161
173
  /* reading operations */
162
- peek (position?: number) {
174
+ peek (position?: number): T | undefined {
163
175
  if (position === undefined)
164
176
  position = this.index
165
177
  position = Math.max(0, Math.min(position, this.queue.elements.length))
166
178
  const element = this.queue.elements[position]
167
- this.queue.emit("read", { start: position, end: position })
179
+ this.queue.notify("read", { start: position, end: position })
168
180
  return element
169
181
  }
170
- read () {
182
+ read (): T | undefined {
171
183
  const element = this.queue.elements[this.index]
172
184
  if (this.index < this.queue.elements.length)
173
185
  this.index++
174
- this.queue.emit("read", { start: this.index - 1, end: this.index - 1 })
186
+ this.queue.notify("read", { start: this.index - 1, end: this.index - 1 })
175
187
  return element
176
188
  }
177
189
  slice (size?: number) {
@@ -186,30 +198,32 @@ export class QueuePointer<T extends QueueElement> extends EventEmitter {
186
198
  slice = this.queue.elements.slice(this.index)
187
199
  this.index = this.queue.elements.length
188
200
  }
189
- this.queue.emit("read", { start, end: this.index })
201
+ this.queue.notify("read", { start, end: this.index })
190
202
  return slice
191
203
  }
192
204
 
193
205
  /* writing operations */
194
- touch () {
195
- if (this.index >= this.queue.elements.length)
196
- throw new Error("cannot touch after last element")
197
- this.queue.emit("write", { start: this.index, end: this.index + 1 })
206
+ touch (position?: number) {
207
+ if (position === undefined)
208
+ position = this.index
209
+ if (position >= this.queue.elements.length)
210
+ throw new Error(`cannot touch after last element ${position} ${this.queue.elements.length}`)
211
+ this.queue.notify("write", { start: position, end: position, op: "touch" })
198
212
  }
199
213
  append (element: T) {
200
214
  this.queue.elements.push(element)
201
215
  this.index = this.queue.elements.length
202
- this.queue.emit("write", { start: this.index - 1, end: this.index - 1 })
216
+ this.queue.notify("write", { start: this.index - 1, end: this.index - 1, op: "append" })
203
217
  }
204
218
  insert (element: T) {
205
219
  this.queue.elements.splice(this.index, 0, element)
206
- this.queue.emit("write", { start: this.index - 1, end: this.index })
220
+ this.queue.notify("write", { start: this.index, end: this.index, op: "insert" })
207
221
  }
208
222
  delete () {
209
223
  if (this.index >= this.queue.elements.length)
210
224
  throw new Error("cannot delete after last element")
211
225
  this.queue.elements.splice(this.index, 1)
212
- this.queue.emit("write", { start: this.index, end: this.index })
226
+ this.queue.notify("write", { start: this.index, end: this.index, op: "delete" })
213
227
  }
214
228
  }
215
229
 
@@ -217,10 +231,18 @@ export class QueuePointer<T extends QueueElement> extends EventEmitter {
217
231
  export class Queue<T extends QueueElement> extends EventEmitter {
218
232
  public elements: T[] = []
219
233
  private pointers = new Map<string, QueuePointer<T>>()
234
+ private silence = false
220
235
  constructor () {
221
236
  super()
222
237
  this.setMaxListeners(100)
223
238
  }
239
+ silent (silence: boolean) {
240
+ this.silence = silence
241
+ }
242
+ notify (event: string, info: any) {
243
+ if (!this.silence)
244
+ this.emit(event, info)
245
+ }
224
246
  pointerUse (name: string): QueuePointer<T> {
225
247
  if (!this.pointers.has(name))
226
248
  this.pointers.set(name, new QueuePointer<T>(name, this))
@@ -234,9 +256,10 @@ export class Queue<T extends QueueElement> extends EventEmitter {
234
256
  trim (): void {
235
257
  /* determine minimum pointer position */
236
258
  let min = this.elements.length
237
- for (const pointer of this.pointers.values())
259
+ for (const pointer of this.pointers.values()) {
238
260
  if (min > pointer.position())
239
261
  min = pointer.position()
262
+ }
240
263
 
241
264
  /* trim the maximum amount of first elements */
242
265
  if (min > 0) {
@@ -245,6 +268,8 @@ export class Queue<T extends QueueElement> extends EventEmitter {
245
268
  /* shift all pointers */
246
269
  for (const pointer of this.pointers.values())
247
270
  pointer.position(pointer.position() - min)
271
+
272
+ this.notify("write", { start: 0, end: min, op: "trim" })
248
273
  }
249
274
  }
250
275
  }
@@ -38,6 +38,21 @@ export function createTransformStreamForWritableSide (
38
38
  })
39
39
  }
40
40
 
41
+ /* ensure a chunk is of a certain type and format */
42
+ export function ensureStreamChunk (type: "audio" | "text", chunk: SpeechFlowChunk | Buffer | string) {
43
+ if (chunk instanceof SpeechFlowChunk) {
44
+ if (chunk.type !== type)
45
+ throw new Error(`invalid payload chunk (expected ${type} type, received ${chunk.type} type)`)
46
+ }
47
+ else {
48
+ if (type === "text" && Buffer.isBuffer(chunk))
49
+ chunk = chunk.toString("utf8")
50
+ else if (type === "audio" && !Buffer.isBuffer(chunk))
51
+ chunk = Buffer.from(chunk)
52
+ }
53
+ return chunk
54
+ }
55
+
41
56
  /* create a Duplex/Transform stream which has
42
57
  buffer/string-mode on Writable side and
43
58
  object-mode on Readable side */
@@ -71,21 +86,6 @@ export function createTransformStreamForReadableSide (
71
86
  })
72
87
  }
73
88
 
74
- /* ensure a chunk is of a certain type and format */
75
- export function ensureStreamChunk (type: "audio" | "text", chunk: SpeechFlowChunk | Buffer | string) {
76
- if (chunk instanceof SpeechFlowChunk) {
77
- if (chunk.type !== type)
78
- throw new Error(`invalid payload chunk (expected ${type} type, received ${chunk.type} type)`)
79
- }
80
- else {
81
- if (type === "text" && Buffer.isBuffer(chunk))
82
- chunk = chunk.toString("utf8")
83
- else if (type === "audio" && !Buffer.isBuffer(chunk))
84
- chunk = Buffer.from(chunk)
85
- }
86
- return chunk
87
- }
88
-
89
89
  /* type of a serialized SpeechFlow chunk */
90
90
  type SpeechFlowChunkSerialized = {
91
91
  timestampStart: number,