File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ function FormatStream(opts) {
31
31
}
32
32
util . inherits ( FormatStream , Transform ) ;
33
33
34
- var reHesitation = / % H E S I T A T I O N \s / g; // when the service detects a "hesitation" pause, it literally puts the string "%HESITATION" into the transcription
34
+ var reHesitation = / % H E S I T A T I O N / g; // when the service detects a "hesitation" pause, it literally puts the string "%HESITATION" into the transcription
35
35
var reRepeatedCharacter = / ( [ a - z ] ) \1{ 2 , } / ig; // detect the same character repeated three or more times and remove it
36
36
var reDUnderscoreWords = / D _ [ ^ \s ] + / g; // replace D_(anything)
37
37
@@ -75,6 +75,10 @@ FormatStream.prototype.period = function period(text) {
75
75
if ( ! text ) {
76
76
return ' ' ;
77
77
}
78
+ // just add a space if the sentence ends in an ellipse
79
+ if ( this . options . hesitation && text . substr ( - 1 ) === this . options . hesitation ) {
80
+ return text + ' ' ;
81
+ }
78
82
return text + ( this . isJaCn ? '。' : '. ' ) ;
79
83
} ;
80
84
Original file line number Diff line number Diff line change @@ -81,6 +81,20 @@ describe('FormatStream', function() {
81
81
stream . write ( source ) ;
82
82
} ) ;
83
83
84
+ // https://github.com/watson-developer-cloud/speech-javascript-sdk/issues/13
85
+ it ( 'should handle %HESITATIONs at the end of a sentence (and not add a period)' , function ( done ) {
86
+ var stream = new FormatStream ( ) ;
87
+ stream . setEncoding ( 'utf8' ) ;
88
+ var source = '%HESITATION asdf %HESITATION ' ;
89
+ var expected = '… asdf … ' ;
90
+ stream . on ( 'data' , function ( actual ) {
91
+ assert . equal ( actual , expected ) ;
92
+ done ( ) ;
93
+ } ) ;
94
+ stream . on ( 'error' , done ) ;
95
+ stream . write ( source ) ;
96
+ } ) ;
97
+
84
98
/*
85
99
{ results:
86
100
[ { alternatives:
You can’t perform that action at this time.
0 commit comments