Skip to content

Commit 9122e14

Browse files
committed
add smart_formating param to STT, default to true in helper methods
1 parent 36c2df9 commit 9122e14

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

dist/watson-speech.js

Lines changed: 21 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

speech-to-text/recognize-file.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var WritableElementStream = require('./writable-element-stream');
3535
* @param {String} options.token - Auth Token - see https://github.com/watson-developer-cloud/node-sdk#authorization
3636
* @param {Blob|File} options.data - the raw audio data as a Blob or File instance
3737
* @param {Boolean} [options.play=false] - If a file is set, play it locally as it's being uploaded
38-
* @param {Boolena} [options.format=true] - pipe the text through a {FormatStream} which performs light formatting
38+
* @param {Boolena} [options.format=true] - pipe the text through a {FormatStream} which performs light formatting. Also controls smart_formatting option unless explicitly set.
3939
* @param {Boolena} [options.realtime=options.play] - pipe the text through a {TimingStream} which slows the output down to real-time to match the audio playback.
4040
* @param {String|DOMElement} [options.outputElement] pipe the text to a WriteableElementStream targeting the specified element. Also defaults objectMode to true to enable interim results.
4141
*
@@ -51,6 +51,13 @@ module.exports = function recognizeFile(options) {
5151
options.objectMode = true;
5252
}
5353

54+
// default format to true (capitals and periods)
55+
// default smart_formatting to options.format value (dates, currency, etc.)
56+
options.format = (options.format !== false);
57+
if (typeof options.smart_formatting === 'undefined') {
58+
options.smart_formatting = options.format;
59+
}
60+
5461
var realtime = options.realtime || typeof options.realtime === 'undefined' && options.play;
5562

5663
// the timing stream requires timestamps to work, so enable them automatically
@@ -68,7 +75,7 @@ module.exports = function recognizeFile(options) {
6875
var recognizeStream = new RecognizeStream(rsOpts);
6976
var stream = new BlobStream(options.data).pipe(recognizeStream);
7077

71-
if (options.format !== false) {
78+
if (options.format) {
7279
stream = stream.pipe(new FormatStream(options));
7380
}
7481
if (realtime) {

speech-to-text/recognize-microphone.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var bitBucket = new Writable({
4343
*
4444
* @param {Object} options - Also passed to {RecognizeStream}, and {FormatStream} when applicable
4545
* @param {String} options.token - Auth Token - see https://github.com/watson-developer-cloud/node-sdk#authorization
46-
* @param {Boolean} [options.format=true] - pipe the text through a {FormatStream} which performs light formatting
46+
* @param {Boolean} [options.format=true] - pipe the text through a {FormatStream} which performs light formatting. Also controls smart_formatting option unless explicitly set.
4747
* @param {Boolean} [options.keepMicrophone=false] - keeps an internal reference to the microphone stream to reuse in subsequent calls (prevents multiple permissions dialogs in firefox)
4848
* @param {String|DOMElement} [options.outputElement] pipe the text to a WriteableElementStream targeting the specified element. Also defaults objectMode to true to enable interim results.
4949
*
@@ -59,6 +59,13 @@ module.exports = function recognizeMicrophone(options) {
5959
options.objectMode = true;
6060
}
6161

62+
// default format to true (capitals and periods)
63+
// default smart_formatting to options.format value (dates, currency, etc.)
64+
options.format = (options.format !== false);
65+
if (typeof options.smart_formatting === 'undefined') {
66+
options.smart_formatting = options.format;
67+
}
68+
6269
// we don't want the readable stream to have objectMode on the input even if we're setting it for the output
6370
var rsOpts = assign({}, options);
6471
rsOpts.readableObjectMode = options.objectMode;
@@ -88,7 +95,7 @@ module.exports = function recognizeMicrophone(options) {
8895
// set up the output first so that we have a place to emit errors
8996
// if there's trouble with the input stream
9097
var stream = recognizeStream;
91-
if (options.format !== false) {
98+
if (options.format) {
9299
stream = stream.pipe(new FormatStream(options));
93100
stream.stop = recognizeStream.stop.bind(recognizeStream);
94101
}

speech-to-text/recognize-stream.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var defaults = require('defaults');
2626
var qs = require('../util/querystring.js');
2727

2828
var OPENING_MESSAGE_PARAMS_ALLOWED = ['continuous', 'max_alternatives', 'timestamps', 'word_confidence', 'inactivity_timeout',
29-
'content-type', 'interim_results', 'keywords', 'keywords_threshold', 'word_alternatives_threshold', 'profanity_filter'];
29+
'content-type', 'interim_results', 'keywords', 'keywords_threshold', 'word_alternatives_threshold', 'profanity_filter', 'smart_formatting'];
3030

3131
var QUERY_PARAMS_ALLOWED = ['model', 'watson-token']; // , 'X-Watson-Learning-Opt-Out' - should be allowed but currently isn't due to a service bug
3232

@@ -122,6 +122,7 @@ var QUERY_PARAMS_ALLOWED = ['model', 'watson-token']; // , 'X-Watson-Learning-Op
122122
* @param {Number} [options.inactivity_timeout=30] - how many seconds of silence before automatically closing the stream (even if continuous is true). use -1 for infinity
123123
* @param {Boolean} [options.readableObjectMode=false] - emit `result` objects instead of string Buffers for the `data` events. Changes several other defaults.
124124
* @param {Number} [options.X-WDC-PL-OPT-OUT=0] - set to 1 to opt-out of allowing Watson to use this request to improve it's services
125+
* @param {Boolean} [options.smart_formatting=false] - formats numeric values such as dates, times, currency, etc.
125126
*
126127
* @constructor
127128
*/

0 commit comments

Comments
 (0)