You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+267-2Lines changed: 267 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -109,6 +109,48 @@ const vtc = new VatisTechClient.default({
109
109
110
110
## Props
111
111
112
+
### `config`
113
+
114
+
This is an **Object** with the following structure:
115
+
116
+
```
117
+
{
118
+
"spokenCommandsList": [
119
+
{
120
+
"command": "COMMAND_NAME",
121
+
"regex": [ "regex1", "regex2", "regex3", ... ]
122
+
},
123
+
...
124
+
]
125
+
}
126
+
```
127
+
128
+
Where the value of `spokenCommandsList` is an array of objects that have two properties, `command` and `regex`.
129
+
130
+
The value of the `command`, i.e. `COMMAND_NAME`, is a **String**.
131
+
132
+
The value of the `regex`, i.e. `[ "regex1", "regex2", "regex3", ... ]`, is an **Array of Strings**, i.e. `regex1`, `regex2`, `regex3` are **Strings**.
133
+
134
+
The ideea with this `spokenCommandsList`, is that each time one of the values from the `regex` array is matched in the transcript, it will fire the [onCommandData callback](#oncommanddata), with a special `header` on the data, named `SpokenCommand`.
135
+
The value of the `SpokenCommand` header will be exactly the value of the `command`, i.e. `COMMAND_NAME`.
136
+
137
+
For example, you can use this `spokenCommandsList` to define rules of when you want a new paragraph:
138
+
139
+
```
140
+
{
141
+
"spokenCommandsList": [
142
+
{
143
+
"command": "COMMAND_NAME",
144
+
"regex": [ "new line", "new paragraph", "from the start", "start new line" ]
145
+
}
146
+
]
147
+
}
148
+
```
149
+
150
+
So each time the back-end algorithm will find in the transcript one of `"new line"`, `"new paragraph"`, `"from the start"`, `"start new line"` phrases, the VTC client will fire the [onCommandData callback](#oncommanddata). This way, in your applocation, you will be able to know, when to start a new paragraph.
151
+
152
+
When sending a `config` to the client, the first callback to be fired, will be the [onConfig callback](#oncommanddata).
153
+
112
154
### `service`
113
155
114
156
This is a **String** that refers to the service that you would like to use.
@@ -148,7 +190,7 @@ To get one, please follow these instructions:
148
190
149
191
### `onData`
150
192
151
-
This is a **Function** on which you will receive from the back-end the transcript chunks.
193
+
This is a **Function** on which you will receive from the back-end the transcript chunks.**It is a callback it is always fired.**.
152
194
153
195
It has the following signature:
154
196
@@ -166,7 +208,230 @@ function onData(data) {
166
208
}
167
209
```
168
210
169
-
The `data` object that is received has the following props:
211
+
The `data` object that is received has the following structure:
| PacketNumber | int | Incremental packet number |
310
+
| Sid | string | Session id |
311
+
| FrameStartTime | double | Frame start time in milliseconds |
312
+
| FrameEndTime | double | Frame end time in milliseconds |
313
+
| FinalFrame | boolean | Flag for marking that a segment of speech has ended and it won't be updated |
314
+
| SilenceDetected | boolean | Flag to indicate silence was detected on the audio frame |
315
+
| ProcessingTimeSeconds | double | Time of inferencing |
316
+
| SplitPacket | boolean | Flag that indicates the response packet was split and this is one of the pieces |
317
+
| FinalSplitPacket | boolean | Flag that indicates this is the final piece of the split response |
318
+
| SplitId | string | Full packet id in format `<packet_number>.<split_id>.<sub-split-id>.<sub-sub-split-id>`|
319
+
| RequestBytes | int | Additional bytes requested to produce a frame. This is just an estimation, any number of bytes can be sent |
320
+
| SpokenCommand | string | Command detected in frame |
321
+
322
+
#### NOTE
323
+
324
+
So, the `data` can be final frame - i.e. the backend has fully finalized the transcript for those words and the time intervals (start and end time).
325
+
Or can be partial frame - i.e. the backend has not fully finalized the transcript for those words and the time intervals, and it will most likely change until it is overlapped by a final frame.
326
+
327
+
### `onPartialData`
328
+
329
+
This is a **Function** on which you will receive from the back-end the partial transcript chunks.
330
+
331
+
It is identical to what the [onData callback](#ondata) does, just that the `data` will always represent partial frames.
332
+
333
+
It has the following signature:
334
+
335
+
```
336
+
const onPartialData = (data) => {
337
+
/* do something with data */
338
+
}
339
+
```
340
+
341
+
Or with function names:
342
+
343
+
```
344
+
function onPartialData(data) {
345
+
/* do something with data */
346
+
}
347
+
```
348
+
349
+
#### NOTE
350
+
351
+
The `data` object that comes on the current `onPartialData` callback overrides the `data` object that came on the previous `onPartialData` callback.
352
+
353
+
### `onFinalData`
354
+
355
+
This is a **Function** on which you will receive from the back-end the final transcript chunks.
356
+
357
+
It is identical to what the [onData callback](#ondata) does, just that the `data` will always represent final frames.
358
+
359
+
It has the following signature:
360
+
361
+
```
362
+
const onFinalData = (data) => {
363
+
/* do something with data */
364
+
}
365
+
```
366
+
367
+
Or with function names:
368
+
369
+
```
370
+
function onFinalData(data) {
371
+
/* do something with data */
372
+
}
373
+
```
374
+
375
+
#### NOTE
376
+
377
+
The `data` object that comes from the `onFinalData` callback overrides the `data` object that came on the previous `onPartialData` callback.
378
+
379
+
### `onConfig`
380
+
381
+
This is a **Function** on which you will receive from the back-end a message saying if the config was succesfully added ore not.
382
+
383
+
It has the following signature:
384
+
385
+
```
386
+
const onConfig = (data) => {
387
+
/* do something with data */
388
+
}
389
+
```
390
+
391
+
Where `data` object has the following structure:
392
+
393
+
#### Config applied packet
394
+
395
+
```json
396
+
{
397
+
"type": "CONFIG_APPLIED",
398
+
"headers": {},
399
+
"config_packet": {
400
+
"type": "CONFIG",
401
+
"headers": {},
402
+
"spokenCommandsList": [
403
+
{
404
+
"command": "NEW_PARAGRAPH",
405
+
"regex": ["new line"]
406
+
}
407
+
]
408
+
}
409
+
}
410
+
```
411
+
412
+
### `onCommandData`
413
+
414
+
This is a **Function** on which you will receive from the back-end the transcript chunks for speciffic commands.
415
+
416
+
For example, if you initialize the plugin with a set of commands (e.g. `{spokenCommandsList: [ { "command": "NEW_PARAGRAPH", "regex": ["start new paragraph", "new phrase", "new sentence"] } ] }`), each time the back-end algorithm will find these sets of commands, it will send on this function the data.
417
+
418
+
It has the following signature:
419
+
420
+
```
421
+
const onCommandData = (data) => {
422
+
/* do something with data */
423
+
}
424
+
```
425
+
426
+
Or with function names:
427
+
428
+
```
429
+
function onCommandData(data) {
430
+
/* do something with data */
431
+
}
432
+
```
433
+
434
+
The `data` object from this callback, is the same as the one from [onData callback](#ondata), but it also has a new property, named `spokenCommand`, with the actual command that triggered the callback.
0 commit comments