Skip to content

Commit 5d23b96

Browse files
committed
upgrading to latest prettier
1 parent 2ac1041 commit 5d23b96

17 files changed

+136
-171
lines changed

examples/static/audio-video-deprecated/media-element-audio-stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ function MediaElementAudioStream(element, options) {
7070

7171
var AudioContext = window.AudioContext || window.webkitAudioContext;
7272
// cache the source node & context since it's not possible to recreate it later
73-
var context = element.context = element.context || new AudioContext();
74-
var audioInput = element.node = element.node || context.createMediaElementSource(element);
73+
var context = (element.context = element.context || new AudioContext());
74+
var audioInput = (element.node = element.node || context.createMediaElementSource(element));
7575
var scriptProcessor = context.createScriptProcessor(options.bufferSize, inputChannels, outputChannels);
7676

7777
scriptProcessor.onaudioprocess = processAudio;

examples/stt-token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var express = require('express');
44
var router = express.Router(); // eslint-disable-line new-cap
55
var watson = require('watson-developer-cloud');
66
var vcapServices = require('vcap_services');
7-
var extend = extend = require('util')._extend;
7+
var extend = (extend = require('util')._extend);
88

99
// set up an endpoint to serve speech-to-text auth tokens
1010

examples/tts-token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var express = require('express');
44
var router = express.Router(); // eslint-disable-line new-cap
55
var watson = require('watson-developer-cloud');
66
var vcapServices = require('vcap_services');
7-
var extend = extend = require('util')._extend;
7+
var extend = (extend = require('util')._extend);
88

99
// another endpoint for the text to speech service
1010

speech-to-text/file-player.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var getContentTypeFromHeader = require('./content-type');
99
* @constructor
1010
*/
1111
function UrlPlayer(url) {
12-
var audio = this.audio = new Audio();
12+
var audio = (this.audio = new Audio());
1313
audio.src = url;
1414
audio.play();
1515
/**
@@ -28,7 +28,7 @@ function UrlPlayer(url) {
2828
* @constructor
2929
*/
3030
function FilePlayer(file, contentType) {
31-
var audio = this.audio = new Audio();
31+
var audio = (this.audio = new Audio());
3232
if (audio.canPlayType(contentType)) {
3333
audio.src = URL.createObjectURL(new Blob([file], { type: contentType }));
3434
audio.play();

speech-to-text/format-stream.js

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function FormatStream(opts) {
3434
util.inherits(FormatStream, Transform);
3535

3636
var reHesitation = /%HESITATION ?/g; // http://www.ibm.com/watson/developercloud/doc/speech-to-text/output.shtml#hesitation - D_ is handled below
37-
var reRepeatedCharacter = /([a-z])\1{2,}/ig; // detect the same character repeated three or more times and remove it
37+
var reRepeatedCharacter = /([a-z])\1{2,}/gi; // detect the same character repeated three or more times and remove it
3838
var reDUnderscoreWords = /D_[^\s]+/g; // replace D_(anything)
3939

4040
/**
@@ -121,43 +121,34 @@ FormatStream.prototype.formatString = function(str, isInterim) {
121121
FormatStream.prototype.formatResult = function formatResult(data) {
122122
data = clone(data);
123123
if (Array.isArray(data.results)) {
124-
data.results.forEach(
125-
function(result, i) {
126-
// if there are multiple interim results (as produced by the speaker stream),
127-
// treat the text as final in all but the last result
128-
var textFinal = result.final || i !== data.results.length - 1;
129-
130-
result.alternatives = result.alternatives.map(
131-
function(alt) {
132-
alt.transcript = this.formatString(alt.transcript, !textFinal);
133-
if (alt.timestamps) {
134-
alt.timestamps = alt.timestamps
135-
.map(
136-
function(ts, j, arr) {
137-
// timestamps is an array of arrays, each sub-array is in the form ["word", startTime, endTime]'
138-
ts[0] = this.clean(ts[0]);
139-
if (j === 0) {
140-
ts[0] = this.capitalize(ts[0]);
141-
}
142-
143-
if (j === arr.length - 1 && textFinal) {
144-
ts[0] = this.period(ts[0]);
145-
}
146-
return ts;
147-
},
148-
this
149-
)
150-
.filter(function(ts) {
151-
return ts[0]; // remove any timestamps without a word (due to cleaning out junk words)
152-
});
153-
}
154-
return alt;
155-
},
156-
this
157-
);
158-
},
159-
this
160-
);
124+
data.results.forEach(function(result, i) {
125+
// if there are multiple interim results (as produced by the speaker stream),
126+
// treat the text as final in all but the last result
127+
var textFinal = result.final || i !== data.results.length - 1;
128+
129+
result.alternatives = result.alternatives.map(function(alt) {
130+
alt.transcript = this.formatString(alt.transcript, !textFinal);
131+
if (alt.timestamps) {
132+
alt.timestamps = alt.timestamps
133+
.map(function(ts, j, arr) {
134+
// timestamps is an array of arrays, each sub-array is in the form ["word", startTime, endTime]'
135+
ts[0] = this.clean(ts[0]);
136+
if (j === 0) {
137+
ts[0] = this.capitalize(ts[0]);
138+
}
139+
140+
if (j === arr.length - 1 && textFinal) {
141+
ts[0] = this.period(ts[0]);
142+
}
143+
return ts;
144+
}, this)
145+
.filter(function(ts) {
146+
return ts[0]; // remove any timestamps without a word (due to cleaning out junk words)
147+
});
148+
}
149+
return alt;
150+
}, this);
151+
}, this);
161152
}
162153
return data;
163154
};

speech-to-text/no-timestamps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
module.exports = function noTimestamps(data) {
99
return data.results.some(function(result) {
1010
var alt = result.alternatives && result.alternatives[0];
11-
return !!(alt && (alt.transcript.trim() && !alt.timestamps || !alt.timestamps.length));
11+
return !!(alt && ((alt.transcript.trim() && !alt.timestamps) || !alt.timestamps.length));
1212
});
1313
};
1414

speech-to-text/recognize-file.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module.exports = function recognizeFile(options) {
8282
options.smart_formatting = options.format;
8383
}
8484

85-
var realtime = options.realtime || typeof options.realtime === 'undefined' && options.play;
85+
var realtime = options.realtime || (typeof options.realtime === 'undefined' && options.play);
8686

8787
// the timing stream requires timestamps to work, so enable them automatically
8888
if (realtime) {
@@ -168,9 +168,11 @@ module.exports = function recognizeFile(options) {
168168
// 3. re-pipe the source streams
169169

170170
var sources = streams.filter(function(s) {
171-
return s._readableState &&
171+
return (
172+
s._readableState &&
172173
s._readableState.pipes &&
173-
(s._readableState.pipes === stream || Array.isArray(s._readableState.pipes) && s._readableState.pipes.indexOf(stream) !== -1);
174+
(s._readableState.pipes === stream || (Array.isArray(s._readableState.pipes) && s._readableState.pipes.indexOf(stream) !== -1))
175+
);
174176
});
175177

176178
stream.emit('error', err);

speech-to-text/recognize-stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ RecognizeStream.prototype.initialize = function() {
159159

160160
// node params: requestUrl, protocols, origin, headers, extraRequestOptions
161161
// browser params: requestUrl, protocols (all others ignored)
162-
var socket = this.socket = new W3CWebSocket(url, null, null, options.headers, null);
162+
var socket = (this.socket = new W3CWebSocket(url, null, null, options.headers, null));
163163

164164
// when the input stops, let the service know that we're done
165165
self.on('finish', self.finish.bind(self));

speech-to-text/result-stream.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,11 @@ ResultStream.prototype._transform = function(data, encoding, next) {
3939
// when speaker_labels is enabled, some messages won't have a results array
4040
if (Array.isArray(data.results)) {
4141
// usually there is exactly 1 result, but there can be 0 in some circumstances, and potentially more in future iterations
42-
data.results.forEach(
43-
function(result) {
44-
var cloned = clone(result);
45-
cloned.index = data.result_index;
46-
this.push(cloned);
47-
},
48-
this
49-
);
42+
data.results.forEach(function(result) {
43+
var cloned = clone(result);
44+
cloned.index = data.result_index;
45+
this.push(cloned);
46+
}, this);
5047
} else {
5148
this.push(data);
5249
}

speech-to-text/speaker-stream.js

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,23 @@ SpeakerStream.prototype.buildMessage = function() {
169169
});
170170

171171
// group the words together into utterances by speaker
172-
var utterances = words.reduce(
173-
function(arr, word) {
174-
var utterance = arr[arr.length - 1];
175-
// any time the speaker changes or the (original) result changes, create a new utterance
176-
if (!utterance || utterance.speaker !== word.speaker || utterance.result !== word.result) {
177-
utterance = {
178-
speaker: word.speaker,
179-
timestamps: [word.timestamp],
180-
result: word.result
181-
};
182-
// and add it to the list
183-
arr.push(utterance);
184-
} else {
185-
// otherwise just append the current word to the current result
186-
utterance.timestamps.push(word.timestamp);
187-
}
188-
return arr;
189-
},
190-
[]
191-
);
172+
var utterances = words.reduce(function(arr, word) {
173+
var utterance = arr[arr.length - 1];
174+
// any time the speaker changes or the (original) result changes, create a new utterance
175+
if (!utterance || utterance.speaker !== word.speaker || utterance.result !== word.result) {
176+
utterance = {
177+
speaker: word.speaker,
178+
timestamps: [word.timestamp],
179+
result: word.result
180+
};
181+
// and add it to the list
182+
arr.push(utterance);
183+
} else {
184+
// otherwise just append the current word to the current result
185+
utterance.timestamps.push(word.timestamp);
186+
}
187+
return arr;
188+
}, []);
192189

193190
// create new results
194191
var results = utterances.map(function(utterance, i) {
@@ -207,11 +204,12 @@ SpeakerStream.prototype.buildMessage = function() {
207204
result.speaker = utterance.speaker;
208205
// overwrite the transcript and timestamps on the first alternative
209206
var alt = result.alternatives[0];
210-
alt.transcript = utterance.timestamps
211-
.map(function(ts) {
212-
return ts[WORD];
213-
})
214-
.join(' ') + ' ';
207+
alt.transcript =
208+
utterance.timestamps
209+
.map(function(ts) {
210+
return ts[WORD];
211+
})
212+
.join(' ') + ' ';
215213
alt.timestamps = utterance.timestamps;
216214
// overwrite the final value
217215
result.final = final;
@@ -266,12 +264,9 @@ SpeakerStream.prototype.handleResults = function(data) {
266264
.filter(function(result) {
267265
return result.final;
268266
})
269-
.forEach(
270-
function(result) {
271-
this.results.push(result);
272-
},
273-
this
274-
);
267+
.forEach(function(result) {
268+
this.results.push(result);
269+
}, this);
275270
};
276271

277272
// sorts by start time and then end time
@@ -350,18 +345,16 @@ SpeakerStream.prototype._flush = function(done) {
350345
.map(function(r) {
351346
return r.alternatives[0].timestamps;
352347
})
353-
.reduce(
354-
function(a, b) {
355-
return a.concat(b);
356-
},
357-
[]
358-
);
348+
.reduce(function(a, b) {
349+
return a.concat(b);
350+
}, []);
359351
if (timestamps.length !== this.speaker_labels.length) {
360352
var msg;
361353
if (timestamps.length && !this.speaker_labels.length) {
362354
msg = 'No speaker_labels found. SpeakerStream requires speaker_labels to be enabled.';
363355
} else {
364-
msg = 'Mismatch between number of word timestamps (' +
356+
msg =
357+
'Mismatch between number of word timestamps (' +
365358
timestamps.length +
366359
') and number of speaker_labels (' +
367360
this.speaker_labels.length +

0 commit comments

Comments
 (0)