watson-speech
Version:
IBM Watson Speech to Text and Text to Speech SDK for web browsers.
2,421 lines (689 loc) • 35.6 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: RecognizeStream</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: RecognizeStream</h1>
<section>
<header>
<h2>RecognizeStream</h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="RecognizeStream"><span class="type-signature"></span>new RecognizeStream<span class="signature">(options)</span><span class="type-signature"></span></h4>
<div class="description">
<p>pipe()-able Node.js Readable/Writeable stream - accepts binary audio and emits text/objects in it's <code>data</code> events.</p>
<p>Uses WebSockets under the hood. For audio with no recognizable speech, no <code>data</code> events are emitted.</p>
<p>By default, only finalized text is emitted in the data events, however in <code>readableObjectMode</code> (usually just <code>objectMode</code> when using a helper method).</p>
<p> An interim result looks like this:</p>
<pre class="prettyprint source lang-js"><code> { alternatives:
[ { timestamps:
[ [ 'it', 20.9, 21.04 ],
[ 'is', 21.04, 21.17 ],
[ 'a', 21.17, 21.25 ],
[ 'site', 21.25, 21.56 ],
[ 'that', 21.56, 21.7 ],
[ 'hardly', 21.7, 22.06 ],
[ 'anyone', 22.06, 22.49 ],
[ 'can', 22.49, 22.67 ],
[ 'behold', 22.67, 23.13 ],
[ 'without', 23.13, 23.46 ],
[ 'some', 23.46, 23.67 ],
[ 'sort', 23.67, 23.91 ],
[ 'of', 23.91, 24 ],
[ 'unwanted', 24, 24.58 ],
[ 'emotion', 24.58, 25.1 ] ],
transcript: 'it is a site that hardly anyone can behold without some sort of unwanted emotion ' } ],
final: false,
result_index: 3 }</code></pre><p> While a final result looks like this (some features only appear in final results):</p>
<pre class="prettyprint source lang-js"><code> { alternatives:
[ { word_confidence:
[ [ 'it', 1 ],
[ 'is', 0.956286624429304 ],
[ 'a', 0.8105753725270362 ],
[ 'site', 1 ],
[ 'that', 1 ],
[ 'hardly', 1 ],
[ 'anyone', 1 ],
[ 'can', 1 ],
[ 'behold', 0.5273598005406737 ],
[ 'without', 1 ],
[ 'some', 1 ],
[ 'sort', 1 ],
[ 'of', 1 ],
[ 'unwanted', 1 ],
[ 'emotion', 0.49401837076320887 ] ],
confidence: 0.881,
transcript: 'it is a site that hardly anyone can behold without some sort of unwanted emotion ',
timestamps:
[ [ 'it', 20.9, 21.04 ],
[ 'is', 21.04, 21.17 ],
[ 'a', 21.17, 21.25 ],
[ 'site', 21.25, 21.56 ],
[ 'that', 21.56, 21.7 ],
[ 'hardly', 21.7, 22.06 ],
[ 'anyone', 22.06, 22.49 ],
[ 'can', 22.49, 22.67 ],
[ 'behold', 22.67, 23.13 ],
[ 'without', 23.13, 23.46 ],
[ 'some', 23.46, 23.67 ],
[ 'sort', 23.67, 23.91 ],
[ 'of', 23.91, 24 ],
[ 'unwanted', 24, 24.58 ],
[ 'emotion', 24.58, 25.1 ] ] },
{ transcript: 'it is a sight that hardly anyone can behold without some sort of unwanted emotion ' },
{ transcript: 'it is a site that hardly anyone can behold without some sort of unwanted emotions ' } ],
final: true,
result_index: 3 }</code></pre>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>model</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
'en-US_BroadbandModel'
</td>
<td class="description last"><p>voice model to use. Microphone streaming only supports broadband models.</p></td>
</tr>
<tr>
<td class="name"><code>url</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
'wss://stream.watsonplatform.net/speech-to-text/api'
</td>
<td class="description last"><p>base URL for service</p></td>
</tr>
<tr>
<td class="name"><code>token</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last"><p>Auth token</p></td>
</tr>
<tr>
<td class="name"><code>content-type</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
'audio/wav'
</td>
<td class="description last"><p>content type of audio; can be automatically determined from file header in most cases. only wav, flac, and ogg/opus are supported</p></td>
</tr>
<tr>
<td class="name"><code>interim_results</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last"><p>Send back non-final previews of each "sentence" as it is being processed. These results are ignored in text mode.</p></td>
</tr>
<tr>
<td class="name"><code>continuous</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last"><p>set to false to automatically stop the transcription after the first "sentence"</p></td>
</tr>
<tr>
<td class="name"><code>word_confidence</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>include confidence scores with results. Defaults to true when in objectMode.</p></td>
</tr>
<tr>
<td class="name"><code>timestamps</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>include timestamps with results. Defaults to true when in objectMode.</p></td>
</tr>
<tr>
<td class="name"><code>max_alternatives</code></td>
<td class="type">
<span class="param-type">Number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
1
</td>
<td class="description last"><p>maximum number of alternative transcriptions to include. Defaults to 3 when in objectMode.</p></td>
</tr>
<tr>
<td class="name"><code>keywords</code></td>
<td class="type">
<span class="param-type">Array.<String></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last"><p>a list of keywords to search for in the audio</p></td>
</tr>
<tr>
<td class="name"><code>keywords_threshold</code></td>
<td class="type">
<span class="param-type">Number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last"><p>Number between 0 and 1 representing the minimum confidence before including a keyword in the results. Required when options.keywords is set</p></td>
</tr>
<tr>
<td class="name"><code>word_alternatives_threshold</code></td>
<td class="type">
<span class="param-type">Number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last"><p>Number between 0 and 1 representing the minimum confidence before including an alternative word in the results. Must be set to enable word alternatives,</p></td>
</tr>
<tr>
<td class="name"><code>profanity_filter</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>set to true to filter out profanity and replace the words with *'s</p></td>
</tr>
<tr>
<td class="name"><code>inactivity_timeout</code></td>
<td class="type">
<span class="param-type">Number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
30
</td>
<td class="description last"><p>how many seconds of silence before automatically closing the stream (even if continuous is true). use -1 for infinity</p></td>
</tr>
<tr>
<td class="name"><code>readableObjectMode</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>emit <code>result</code> objects instead of string Buffers for the <code>data</code> events. Changes several other defaults.</p></td>
</tr>
<tr>
<td class="name"><code>X-WDC-PL-OPT-OUT</code></td>
<td class="type">
<span class="param-type">Number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
0
</td>
<td class="description last"><p>set to 1 to opt-out of allowing Watson to use this request to improve it's services</p></td>
</tr>
<tr>
<td class="name"><code>smart_formatting</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>formats numeric values such as dates, times, currency, etc.</p></td>
</tr>
<tr>
<td class="name"><code>customization_id</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last"><p>not yet supported on the public STT service</p></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line131">line 131</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="~flowForResults"><span class="type-signature">(inner) </span>flowForResults<span class="signature">(event)</span><span class="type-signature"></span></h4>
<div class="description">
<p>listening for <code>results</code> events should put the stream in flowing mode just like <code>data</code> events</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>event</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line144">line 144</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Events</h3>
<h4 class="name" id="event:close">close</h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>reasonCode</code></td>
<td class="type">
<span class="param-type">Number</span>
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>description</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line238">line 238</a>
</li></ul></dd>
</dl>
<h4 class="name" id="event:connection-close">connection-close</h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>reasonCode</code></td>
<td class="type">
<span class="param-type">Number</span>
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>description</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="important tag-deprecated">Deprecated:</dt><dd class="yes-def tag-deprecated"><ul class="dummy"><li>Yes</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line244">line 244</a>
</li></ul></dd>
</dl>
<h4 class="name" id="event:data">data</h4>
<div class="description">
<p>Finalized text</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>transcript</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line326">line 326</a>
</li></ul></dd>
</dl>
<h4 class="name" id="event:data">data</h4>
<div class="description">
<p>Object with interim or final results, possibly including confidence scores, alternatives, and word timing.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line319">line 319</a>
</li></ul></dd>
</dl>
<h4 class="name" id="event:error">error</h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>msg</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>custom error message</p></td>
</tr>
<tr>
<td class="name"><code>frame</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>unprocessed frame (should have a .data property with either string or binary data)</p></td>
</tr>
<tr>
<td class="name"><code>err</code></td>
<td class="type">
<span class="param-type">Error</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line253">line 253</a>
</li></ul></dd>
</dl>
<h4 class="name" id="event:receive-json">receive-json</h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>msg</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"><p>the raw JSON received from Watson - sometimes useful for debugging</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line281">line 281</a>
</li></ul></dd>
</dl>
<h4 class="name" id="event:results">results</h4>
<div class="description">
<p>Object with interim or final results, possibly including confidence scores, alternatives, and word timing.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="important tag-deprecated">Deprecated:</dt><dd><ul class="dummy"><li>- use objectMode and listen for the 'data' event instead</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line311">line 311</a>
</li></ul></dd>
</dl>
<h4 class="name" id="event:results">results</h4>
<div class="description">
<p>Object with array of interim or final results, possibly including confidence scores, alternatives, and word timing. May have no results at all for empty audio files.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="important tag-deprecated">Deprecated:</dt><dd><ul class="dummy"><li>- use objectMode and listen for the 'data' event instead</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line300">line 300</a>
</li></ul></dd>
</dl>
<h4 class="name" id="event:send-json">send-json</h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>msg</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"><p>the raw JSON sent to Watson - sometimes useful for debugging</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="speech-to-text_recognize-stream.js.html">speech-to-text/recognize-stream.js</a>, <a href="speech-to-text_recognize-stream.js.html#line343">line 343</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-watson-speech.html">watson-speech</a></li><li><a href="module-watson-speech_speech-to-text.html">watson-speech/speech-to-text</a></li><li><a href="module-watson-speech_speech-to-text_get-models.html">watson-speech/speech-to-text/get-models</a></li><li><a href="module-watson-speech_speech-to-text_recognize-file.html">watson-speech/speech-to-text/recognize-file</a></li><li><a href="module-watson-speech_speech-to-text_recognize-microphone.html">watson-speech/speech-to-text/recognize-microphone</a></li><li><a href="module-watson-speech_text-to-speech.html">watson-speech/text-to-speech</a></li><li><a href="module-watson-speech_text-to-speech_get-voices.html">watson-speech/text-to-speech/get-voices</a></li><li><a href="module-watson-speech_text-to-speech_synthesize.html">watson-speech/text-to-speech/synthesize</a></li></ul><h3>Classes</h3><ul><li><a href="FilePlayer.html">FilePlayer</a></li><li><a href="FormatStream.html">FormatStream</a></li><li><a href="RecognizeStream.html">RecognizeStream</a></li><li><a href="TimingStream.html">TimingStream</a></li><li><a href="WebAudioL16Stream.html">WebAudioL16Stream</a></li><li><a href="WritableElementStream.html">WritableElementStream</a></li></ul><h3>Events</h3><ul><li><a href="RecognizeStream.html#event:close">close</a></li><li><a href="RecognizeStream.html#event:connection-close">connection-close</a></li><li><a href="RecognizeStream.html#event:data">data</a></li><li><a href="RecognizeStream.html#event:error">error</a></li><li><a href="RecognizeStream.html#event:receive-json">receive-json</a></li><li><a href="RecognizeStream.html#event:results">results</a></li><li><a href="RecognizeStream.html#event:send-json">send-json</a></li></ul><h3>Global</h3><ul><li><a href="global.html#getContentTypeFromFile">getContentTypeFromFile</a></li><li><a href="global.html#noTimestamps">noTimestamps</a></li><li><a href="global.html#playFile">playFile</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.1</a> on Tue Sep 13 2016 21:04:31 GMT+0000 (UTC)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>