UNPKG

watson-speech

Version:

IBM Watson Speech to Text and Text to Speech SDK for web browsers.

1,905 lines (552 loc) 28.2 kB
<!DOCTYPE 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 (assuming all features are enabled):</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 (again, assuming all features are enabled):</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"> &lt;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"> &lt;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>content-type</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> &lt;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"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Send back non-final previews of each &quot;sentence&quot; as it is being processed. Defaults to true when in objectMode.</p></td> </tr> <tr> <td class="name"><code>continuous</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> true </td> <td class="description last"><p>set to false to automatically stop the transcription after the first &quot;sentence&quot;</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"> &lt;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"> &lt;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"> &lt;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>inactivity_timeout</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="attributes"> &lt;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"> &lt;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"> &lt;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> <p>//todo: investigate other options at http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/apis/#!/speech-to-text/recognizeSessionless</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#line128">line 128</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#line141">line 141</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#line234">line 234</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#line239">line 239</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#line317">line 317</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#line310">line 310</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"> &lt;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"> &lt;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#line248">line 248</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#line291">line 291</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#line302">line 302</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_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:results">results</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.0</a> on Fri Apr 15 2016 18:26:43 GMT+0000 (UTC) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>