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
SpeakerStream: handle early speaker_labels, include keywords, alternatives, etc
* Can now gracefully handle early speaker_labels and recover once the matching result arrives
* Includes original result w/ keywords, alternatives, etc
* may not be matched to the exact correct result currently
@@ -21,18 +21,19 @@ var Transform = require('stream').Transform;
21
21
varutil=require('util');
22
22
varpullAllWith=require('lodash.pullallwith');
23
23
varnoTimestamps=require('./no-timestamps');
24
+
varclone=require('clone');
24
25
25
26
/**
26
27
* Object-Mode stream that splits up results by speaker.
27
28
*
28
29
* Output format is similar to existing results formats, but with an extra speaker field,
29
30
*
30
31
* Output results array will usually contain multiple results.
31
-
* All results are interim until the final batch; the text will not change, but the speaker may, and so the text may move from one interim result to another.
32
+
* All results are interim until the final batch; the text may change (if options.speakerlessInterim is enabled) or move from one interim result to another.
32
33
*
33
-
* Note: when combined with a TimingStream, data events may contain a combination of final and interim results (with the last one sometimes being interim)
34
+
* Keywords, words_alternatives, and other features may appear on results that come slightly earlier than the timestamp due to the way things are split up.
34
35
*
35
-
* Ignores interim results from the service.
36
+
* Ignores interim results from the service unless options.speakerlessInterim is enabled.
36
37
*
37
38
* @constructor
38
39
* @param {Object} options
@@ -55,7 +56,7 @@ function SpeakerStream(options) {
55
56
* @type {Array<Array>}
56
57
* @private
57
58
*/
58
-
this.timestamps=[];
59
+
this.results=[];
59
60
/**
60
61
* speaker_labels is an array of objects.
61
62
* Example:
@@ -82,6 +83,12 @@ function SpeakerStream(options) {
82
83
* @private
83
84
*/
84
85
this.speaker_labels=[];
86
+
87
+
this.mismatchErrorEmitted=false;
88
+
89
+
// flag to signal that labels were recieved before results, and therefore
90
+
// the stream needs to emit on the next batch of final results
Copy file name to clipboardExpand all lines: speech-to-text/timing-stream.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,13 @@ var noTimestamps = require('./no-timestamps');
14
14
* @todo: fix TimingStream to work with the output of the SpeakerStream
15
15
*
16
16
* @param {Object} [opts]
17
-
* @param {*} [opts.emitAt=TimingStream.START] - set to TimingStream.END to only emit text that has been completely spoken.
17
+
* @param {*} [opts.emitAt=TimingStream.END] - set to TimingStream.START for a more subtitles-like output where results are returned as soon as the utterance begins
18
18
* @param {Number} [opts.delay=0] - Additional delay (in seconds) to apply before emitting words, useful for precise syncing to audio tracks. May be negative
19
19
* @constructor
20
20
*/
21
21
functionTimingStream(opts){
22
22
this.options=defaults(opts,{
23
-
emitAt: TimingStream.START,
23
+
emitAt: TimingStream.END,
24
24
delay: 0,
25
25
allowHalfOpen: true,// keep the readable side open after the source closes
0 commit comments