Skip to content

Commit b318d88

Browse files
committed
cleaned up warnings and examples
1 parent 45da809 commit b318d88

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ var defaults = require('defaults');
1717
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
1818
* @see https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createScriptProcessor
1919
*
20-
* @todo: add option for whether to keep or destroy the context
21-
* @todo: test what happens if source has multiple channels
22-
*
2320
* @constructor
2421
*/
2522
function MediaElementAudioStream(element, options) {
@@ -67,7 +64,7 @@ function MediaElementAudioStream(element, options) {
6764
function processAudio(e) {
6865
// onaudioprocess can be called at least once after we've stopped
6966
if (recording) {
70-
// todo: interleave channels in binary mode
67+
// warning: this doesn't interleave channels in binary mode
7168
self.push(options.objectMode ? e.inputBuffer : new Buffer(e.inputBuffer.getChannelData(0)));
7269
}
7370
}

examples/static/file-ajax.html

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,16 @@ <h2>Output:</h2>
2222
<h2>Code for this demo:</h2>
2323
<pre><code><script style="display: block;">
2424

25-
// preloading the data for a smoother experience
26-
var preloadTokenAndAudio = Promise.all([
27-
fetch('/api/speech-to-text/token').then(function(response) {
28-
return response.text();
29-
}),
30-
fetch('/Us_English_Broadband_Sample_1.wav').then(function(response) {
31-
return response.blob();
32-
})
33-
]);
34-
3525
document.querySelector('#button').onclick = function () {
3626

37-
preloadTokenAndAudio.then(function (values) {
27+
Promise.all([
28+
fetch('/api/speech-to-text/token').then(function(response) {
29+
return response.text();
30+
}),
31+
fetch('/Us_English_Broadband_Sample_1.wav').then(function(response) {
32+
return response.blob();
33+
})
34+
]).then(function (values) {
3835
var token = values[0];
3936
var file = values[1];
4037

examples/static/speaker-stream-file-html.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ <h2>Code for this demo:</h2>
2626
document.querySelector('#button').onclick = function () {
2727
fetch('/api/speech-to-text/token').then(function(response) {
2828
return response.text();
29-
}).then(function (values) {
30-
var token = values[0];
29+
}).then(function (token) {
3130

3231
document.querySelector('#output').innerHTML = 'Processing. Note: it will take some time for the first results to appear.';
3332

speech-to-text/recognize-stream.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ RecognizeStream.WEBSOCKET_CONNECTION_ERROR = 'WebSocket connection error';
124124
RecognizeStream.prototype.initialize = function() {
125125
var options = this.options;
126126

127-
// todo: apply these corrections to other methods (?)
128127
if (options.token && !options['watson-token']) {
129128
options['watson-token'] = options.token;
130129
}
@@ -135,7 +134,10 @@ RecognizeStream.prototype.initialize = function() {
135134
options['X-Watson-Learning-Opt-Out'] = options['X-WDC-PL-OPT-OUT'];
136135
}
137136

138-
var queryParams = util._extend('customization_id' in options ? pick(options, QUERY_PARAMS_ALLOWED) : {model: 'en-US_BroadbandModel'}, pick(options, QUERY_PARAMS_ALLOWED));
137+
var queryParams = util._extend(
138+
'customization_id' in options ? pick(options, QUERY_PARAMS_ALLOWED) : {model: 'en-US_BroadbandModel'},
139+
pick(options, QUERY_PARAMS_ALLOWED)
140+
);
139141

140142
var queryString = qs.stringify(queryParams);
141143
var url = (options.url || 'wss://stream.watsonplatform.net/speech-to-text/api').replace(/^http/, 'ws') + '/v1/recognize?' + queryString;
@@ -329,8 +331,24 @@ RecognizeStream.prototype._write = function(chunk, encoding, callback) {
329331
}
330332
};
331333

332-
// flow control - don't ask for more data until we've finished what we have
333-
// todo: see if this can be improved
334+
/**
335+
* Flow control - don't ask for more data until we've finished what we have
336+
*
337+
* Notes:
338+
*
339+
* This limits upload speed to 100 * options.highWaterMark / second.
340+
*
341+
* The default highWaterMark is 16kb, so the default max upload speed is ~1.6mb/s.
342+
*
343+
* Microphone input provides audio at a (downsampled) rate of:
344+
* 16000 samples/s * 16-bits * 1 channel = 31.25kb/s
345+
* (note the bits to bytes conversion there)
346+
*
347+
* @private
348+
* @param next
349+
*/
350+
//
351+
334352
RecognizeStream.prototype.afterSend = function afterSend(next) {
335353
if (this.socket.bufferedAmount <= (this._writableState.highWaterMark || 0)) {
336354
process.nextTick(next);

0 commit comments

Comments
 (0)