Skip to content

Commit 6f35ba6

Browse files
committed
doc improvements [ci skip]
1 parent 8fc5bac commit 6f35ba6

File tree

2 files changed

+22
-74
lines changed

2 files changed

+22
-74
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ IBM Watson Speech Services for Web Browsers
44
[![Build Status](https://travis-ci.org/watson-developer-cloud/speech-javascript-sdk.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/speech-javascript-sdk)
55
[![npm-version](https://img.shields.io/npm/v/watson-speech.svg)](https://www.npmjs.com/package/watson-speech)
66

7-
Allows you to easily add voice recognition and synthesis to any web app with minimal code.
7+
Allows you to easily add voice recognition and synthesis to any web app with minimal code.
88

9-
**Warning** This library is still has a few rough edges and may yet see breaking changes.
10-
11-
12-
### For Web Browsers Only
13-
This library is primarily intended for use in browsers.
9+
### Build for Browsers
10+
This library is primarily intended for use in web browsers.
1411
Check out [watson-developer-cloud](https://www.npmjs.com/package/watson-developer-cloud) to use Watson services (speech and others) from Node.js.
1512

1613
However, a server-side component is required to generate auth tokens.

speech-to-text/recognize-stream.js

Lines changed: 19 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -49,85 +49,20 @@ var QUERY_PARAMS_ALLOWED = [
4949

5050

5151
/**
52-
* pipe()-able Node.js Readable/Writeable stream - accepts binary audio and emits text/objects in it's `data` events.
52+
* pipe()-able Node.js Duplex stream - accepts binary audio and emits text/objects in it's `data` events.
5353
*
5454
* Uses WebSockets under the hood. For audio with no recognizable speech, no `data` events are emitted.
5555
*
5656
* By default, only finalized text is emitted in the data events, however when `objectMode`/`readableObjectMode` and `interim_results` are enabled, both interim and final results objects are emitted.
5757
* WriteableElementStream uses this, for example, to live-update the DOM with word-by-word transcriptions.
5858
*
59-
* An interim result looks like this:
60-
```js
61-
{ alternatives:
62-
[ { timestamps:
63-
[ [ 'it', 20.9, 21.04 ],
64-
[ 'is', 21.04, 21.17 ],
65-
[ 'a', 21.17, 21.25 ],
66-
[ 'site', 21.25, 21.56 ],
67-
[ 'that', 21.56, 21.7 ],
68-
[ 'hardly', 21.7, 22.06 ],
69-
[ 'anyone', 22.06, 22.49 ],
70-
[ 'can', 22.49, 22.67 ],
71-
[ 'behold', 22.67, 23.13 ],
72-
[ 'without', 23.13, 23.46 ],
73-
[ 'some', 23.46, 23.67 ],
74-
[ 'sort', 23.67, 23.91 ],
75-
[ 'of', 23.91, 24 ],
76-
[ 'unwanted', 24, 24.58 ],
77-
[ 'emotion', 24.58, 25.1 ] ],
78-
transcript: 'it is a site that hardly anyone can behold without some sort of unwanted emotion ' } ],
79-
final: false,
80-
result_index: 3 }
81-
```
82-
83-
While a final result looks like this (some features only appear in final results):
84-
```js
85-
{ alternatives:
86-
[ { word_confidence:
87-
[ [ 'it', 1 ],
88-
[ 'is', 0.956286624429304 ],
89-
[ 'a', 0.8105753725270362 ],
90-
[ 'site', 1 ],
91-
[ 'that', 1 ],
92-
[ 'hardly', 1 ],
93-
[ 'anyone', 1 ],
94-
[ 'can', 1 ],
95-
[ 'behold', 0.5273598005406737 ],
96-
[ 'without', 1 ],
97-
[ 'some', 1 ],
98-
[ 'sort', 1 ],
99-
[ 'of', 1 ],
100-
[ 'unwanted', 1 ],
101-
[ 'emotion', 0.49401837076320887 ] ],
102-
confidence: 0.881,
103-
transcript: 'it is a site that hardly anyone can behold without some sort of unwanted emotion ',
104-
timestamps:
105-
[ [ 'it', 20.9, 21.04 ],
106-
[ 'is', 21.04, 21.17 ],
107-
[ 'a', 21.17, 21.25 ],
108-
[ 'site', 21.25, 21.56 ],
109-
[ 'that', 21.56, 21.7 ],
110-
[ 'hardly', 21.7, 22.06 ],
111-
[ 'anyone', 22.06, 22.49 ],
112-
[ 'can', 22.49, 22.67 ],
113-
[ 'behold', 22.67, 23.13 ],
114-
[ 'without', 23.13, 23.46 ],
115-
[ 'some', 23.46, 23.67 ],
116-
[ 'sort', 23.67, 23.91 ],
117-
[ 'of', 23.91, 24 ],
118-
[ 'unwanted', 24, 24.58 ],
119-
[ 'emotion', 24.58, 25.1 ] ] },
120-
{ transcript: 'it is a sight that hardly anyone can behold without some sort of unwanted emotion ' },
121-
{ transcript: 'it is a site that hardly anyone can behold without some sort of unwanted emotions ' } ],
122-
final: true,
123-
result_index: 3 }
124-
```
125-
59+
* Note that the WebSocket connection is not established until the first chunk of data is recieved. This allows for auto-detection of content type (for wav/flac/opus audio).
12660
*
12761
* @param {Object} options
12862
* @param {String} [options.model='en-US_BroadbandModel'] - voice model to use. Microphone streaming only supports broadband models.
12963
* @param {String} [options.url='wss://stream.watsonplatform.net/speech-to-text/api'] base URL for service
13064
* @param {String} [options.token] - Auth token
65+
* @param {Object} [options.headers] - Only works in Node.js, not in browsers. Allows for custom headers to be set, including an Authorization header (preventing the need for auth tokens)
13166
* @param {String} [options.content-type='audio/wav'] - content type of audio; can be automatically determined from file header in most cases. only wav, flac, and ogg/opus are supported
13267
* @param {Boolean} [options.interim_results=true] - Send back non-final previews of each "sentence" as it is being processed. These results are ignored in text mode.
13368
* @param {Boolean} [options.continuous=true] - set to false to automatically stop the transcription after the first "sentence"
@@ -226,6 +161,10 @@ RecognizeStream.prototype.initialize = function() {
226161

227162
this.socket.onopen = function() {
228163
self.sendJSON(openingMessage);
164+
/**
165+
* emitted once the WebSocket connection has been established
166+
* @event RecognizeStream#connect
167+
*/
229168
self.emit('connect');
230169
};
231170

@@ -297,6 +236,10 @@ RecognizeStream.prototype.initialize = function() {
297236
socket.close();
298237
} else {
299238
self.listening = true;
239+
/**
240+
* Emitted when the Watson Service indicates readieness to transcribe audio. Any audio sent before this point will be buffered until now.
241+
* @event RecognizeStream#listening
242+
*/
300243
self.emit('listening');
301244
}
302245
} else {
@@ -383,7 +326,15 @@ RecognizeStream.prototype.afterSend = function afterSend(next) {
383326
}
384327
};
385328

329+
/**
330+
* Prevents any more audio from being sent over the WebSocket and gracefully closes the connection.
331+
* Additional data may still be emitted up until the `end` event is triggered.
332+
*/
386333
RecognizeStream.prototype.stop = function() {
334+
/**
335+
* Event emitted when the stop method is called. Mainly for synchronising with file reading and playback.
336+
* @event RecognizeStream#stop
337+
*/
387338
this.emit('stop');
388339
this.finish();
389340
};

0 commit comments

Comments
 (0)