Skip to content

Commit e6c4be1

Browse files
committed
objectmode works for file playback and transcription
1 parent d2ae95b commit e6c4be1

19 files changed

+224
-160
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,11 @@ Inherits `.stop()` method and `result` event from the `RecognizeStream`.
135135
* more tests in general
136136
* update node-sdk to use current version of this lib's RecognizeStream (and also provide the FormatStream + anything else that might be handy)
137137
* improve docs
138+
* consider a wrapper to match https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html
139+
140+
141+
recognizeBlob -> recognizeFile (?)
142+
objectMode
143+
move timing/format stream.stop to wrapper methods
144+
test promise with objectmode
145+
consider interim event for recognize/format/timing streams

dist/watson-speech.js

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

examples/public/audio-element-programmatic.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ <h2>Code for this demo:</h2>
3333

3434
var stream = WatsonSpeech.SpeechToText.recognizeElement({
3535
token: token,
36-
element: audioElement
36+
element: audioElement,
37+
objectMode: true // necessary to receive interim results
3738
// muteSource: true // prevents sound from also playing locally
3839
});
3940

4041
// each result gets it's own <span> because watson will sometimes go back and change a word as it hears more context
4142
var $curSentence = $('<span>&nbsp;</span>').appendTo($output);
4243

4344
// a result is approximately equivalent to a sentence
44-
stream.on('result', function(result) {
45+
stream.on('data', function(result) {
4546
// update the text for the current sentence with the default alternative.
4647
// there may be multiple alternatives but this example app ignores all but the first.
4748
$curSentence.html(result.alternatives[0].transcript);

examples/public/audio-element.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h2>Code for this demo:</h2>
3333
var stream = WatsonSpeech.SpeechToText.recognizeElement({
3434
token: token,
3535
element: $('#audio-element')[0],
36-
objectMode: true, // necessary to receive interim results
36+
objectMode: true // necessary to receive interim results
3737
// muteSource: true // prevents sound from also playing locally
3838
});
3939

examples/public/blob-realtime-vs-no-realtime.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h2>Code for this demo:</h2>
3131
var $curSentence = $('<span>&nbsp;</span>').appendTo($output);
3232

3333
// a result is approximately equivalent to a sentence
34-
stream.on('result', function(result) {
34+
stream.on('data', function(result) {
3535
// update the text for the current sentence with the default alternative.
3636
// there may be multiple alternatives but this example app ignores all but the first.
3737
$curSentence.html(result.alternatives[0].transcript);
@@ -62,14 +62,15 @@ <h2>Code for this demo:</h2>
6262
token: token,
6363
data: $('#audiofile')[0].files[0],
6464
play: true,
65+
objectMode: true,
6566
max_alternatives: 1, // default is 3, but only the first one includes word timing data
6667
realtime: false // defaults to true, but we're going to turn it off and then manually do it in a moment to show the difference
6768
});
6869

6970
renderStream(stream, $('#output'));
7071

7172
// now do what the realtime option would have done: pipe through a TimingStream
72-
var realtimeStream = stream.pipe(new WatsonSpeech.SpeechToText.TimingStream());
73+
var realtimeStream = stream.pipe(new WatsonSpeech.SpeechToText.TimingStream({objectMode: true}));
7374

7475
renderStream(realtimeStream, $('#realtime-output'));
7576

examples/public/file-promise.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ <h2>Code for this demo:</h2>
2929

3030
WatsonSpeech.SpeechToText.recognizeBlob({
3131
token: token,
32-
data: $('#audiofile')[0].files[0],
33-
// optional: disable unused features to save time/energy/bandwidth
34-
interim_results: false,
35-
word_confidence: false,
36-
timestamps: false,
37-
max_alternatives: 1
32+
data: $('#audiofile')[0].files[0]
3833
})
3934
.promise()
4035
.then(function(text) {

examples/public/file-streaming.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ <h2>Code for this demo:</h2>
3232
stream = WatsonSpeech.SpeechToText.recognizeBlob({
3333
token: token,
3434
data: $('#audiofile')[0].files[0],
35+
objectMode: true, // necessary to receive interim results
3536
play: true // play the audio out loud
3637
});
3738

3839
// each result (sentence) gets it's own <span> because watson will sometimes go back and change a word as it hears more context
3940
var $curSentence = $('<span>&nbsp;</span>').appendTo($output);
4041

4142
// a result is approximately equivalent to a sentence
42-
stream.on('result', function(result) {
43+
stream.on('data', function(result) {
4344
// update the text for the current sentence with the default alternative.
4445
// there may be multiple alternatives but this example app ignores all but the first.
4546
$curSentence.html(result.alternatives[0].transcript);

examples/public/microphone-streaming-auto-stop.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ <h2>Code for this demo:</h2>
2929
$.get('/token').then(function (token) {
3030
var stream = WatsonSpeech.SpeechToText.recognizeMicrophone({
3131
token: token,
32-
continuous: false // false = automatically stop transcription the first time a pause is detected
32+
continuous: false, // false = automatically stop transcription the first time a pause is detected
33+
objectMode: true // necessary to receive interim results
3334
});
3435

3536
// each result (sentence) gets it's own <span> because Watson will sometimes go back and change a word as it hears more context
3637
var $curSentence = $('<span>&nbsp;</span>').appendTo($output);
3738

3839
// a result is approximately equivalent to a sentence
39-
stream.on('result', function(result) {
40+
stream.on('data', function(result) {
4041
// update the text for the current sentence with the default alternative.
4142
// there may be multiple alternatives but this example app ignores all but the first.
4243
$curSentence.html(result.alternatives[0].transcript);

examples/public/microphone-streaming.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ <h2>Code for this demo:</h2>
2929

3030
$.get('/token').then(function (token) {
3131
var stream = WatsonSpeech.SpeechToText.recognizeMicrophone({
32-
token: token
32+
token: token,
33+
objectMode: true // necessary to receive interim results
3334
});
3435

3536
// each result (sentence) gets it's own <span> because Watson will sometimes go back and change a word as it hears more context
3637
var $curSentence = $('<span>&nbsp;</span>').appendTo($output);
3738

3839
// a result is approximately equivalent to a sentence
39-
stream.on('result', function(result) {
40+
stream.on('data', function(result) {
4041
// update the text for the current sentence with the default alternative.
4142
// there may be multiple alternatives but this example app ignores all but the first.
4243
$curSentence.html(result.alternatives[0].transcript);

examples/token-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var config = extend({
3535
}, vcapServices.getCredentials('speech_to_text'));
3636

3737
// quick hack to make development easier
38-
try { extend(config, require('../test/resources/auth.json')) } catch (ex) {}
38+
try { extend(config, require('../test/resources/stt-auth.json')) } catch (ex) {}
3939

4040
var authService = watson.authorization(config);
4141

0 commit comments

Comments
 (0)