/
format-stream-spec.js
86 lines (79 loc) · 2.65 KB
/
format-stream-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';
var assert = require('assert');
var FormatStream = require('../speech-to-text/format-stream.js');
describe('FormatStream', function() {
it('should format strings', function(done) {
var stream = new FormatStream();
var source = 'foo bar ';
var expected = 'Foo bar. ';
stream.on('data', function(actual) {
assert(actual, expected);
done();
});
stream.on('error', done);
stream.write(source);
});
it('should format objects', function(done) {
var stream = new FormatStream({objectMode: true});
var source = {alternatives:
[{
confidence: 0.881,
transcript: 'foo bar ',
final: true}],
result_index: 0};
var expected = {alternatives:
[{
confidence: 0.881,
transcript: 'Foo bar. ',
final: true}],
result_index: 0};
stream.on('data', function(actual) {
assert(actual, expected);
done();
});
stream.on('error', done);
stream.write(source);
});
/*
{ results:
[ { alternatives:
[ { word_confidence:
[ [ 'it', 1 ],
[ 'is', 0.956286624429304 ],
[ 'a', 0.8105753725270362 ],
[ 'site', 1 ],
[ 'that', 1 ],
[ 'hardly', 1 ],
[ 'anyone', 1 ],
[ 'can', 1 ],
[ 'behold', 0.5273598005406737 ],
[ 'without', 1 ],
[ 'some', 1 ],
[ 'sort', 1 ],
[ 'of', 1 ],
[ 'unwanted', 1 ],
[ 'emotion', 0.49401837076320887 ] ],
confidence: 0.881,
transcript: 'it is a site that hardly anyone can behold without some sort of unwanted emotion ',
timestamps:
[ [ 'it', 20.9, 21.04 ],
[ 'is', 21.04, 21.17 ],
[ 'a', 21.17, 21.25 ],
[ 'site', 21.25, 21.56 ],
[ 'that', 21.56, 21.7 ],
[ 'hardly', 21.7, 22.06 ],
[ 'anyone', 22.06, 22.49 ],
[ 'can', 22.49, 22.67 ],
[ 'behold', 22.67, 23.13 ],
[ 'without', 23.13, 23.46 ],
[ 'some', 23.46, 23.67 ],
[ 'sort', 23.67, 23.91 ],
[ 'of', 23.91, 24 ],
[ 'unwanted', 24, 24.58 ],
[ 'emotion', 24.58, 25.1 ] ] },
{ transcript: 'it is a sight that hardly anyone can behold without some sort of unwanted emotion ' },
{ transcript: 'it is a site that hardly anyone can behold without some sort of unwanted emotions ' } ],
final: true } ],
result_index: 3 }
*/
});