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) {
3131}
3232util . inherits ( FormatStream , Transform ) ;
3333
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
3535var reRepeatedCharacter = / ( [ a - z ] ) \1{ 2 , } / ig; // detect the same character repeated three or more times and remove it
3636var reDUnderscoreWords = / D _ [ ^ \s ] + / g; // replace D_(anything)
3737
@@ -75,6 +75,10 @@ FormatStream.prototype.period = function period(text) {
7575 if ( ! text ) {
7676 return ' ' ;
7777 }
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+ }
7882 return text + ( this . isJaCn ? '。' : '. ' ) ;
7983} ;
8084
Original file line number Diff line number Diff line change @@ -81,6 +81,20 @@ describe('FormatStream', function() {
8181 stream . write ( source ) ;
8282 } ) ;
8383
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+
8498 /*
8599 { results:
86100 [ { alternatives:
You can’t perform that action at this time.
0 commit comments