UNPKG

watson-speech

Version:

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

144 lines (107 loc) 12.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Home</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">Home</h1> <h3>watson-speech 0.28.4</h3> <section> <article><h1>IBM Watson Speech Services for Web Browsers</h1><p><a href="https://travis-ci.org/watson-developer-cloud/speech-javascript-sdk"><img src="https://travis-ci.org/watson-developer-cloud/speech-javascript-sdk.svg?branch=master" alt="Build Status"></a> <a href="https://www.npmjs.com/package/watson-speech"><img src="https://img.shields.io/npm/v/watson-speech.svg" alt="npm-version"></a></p> <p>Allows you to easily add voice recognition and synthesis to any web app with minimal code.</p> <h3>Build for Browsers</h3><p>This library is primarily intended for use in web browsers. Check out <a href="https://www.npmjs.com/package/watson-developer-cloud">watson-developer-cloud</a> to use Watson services (speech and others) from Node.js.</p> <p>However, a server-side component is required to generate auth tokens. The examples/ folder includes example Node.js and Python servers, and SDKs are available for <a href="https://github.com/watson-developer-cloud/node-sdk#authorization">Node.js</a>, <a href="https://github.com/watson-developer-cloud/java-sdk">Java</a>, <a href="https://github.com/watson-developer-cloud/python-sdk/blob/v0.28.4/examples/authorization_v1.py">Python</a>, and there is also a <a href="http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/getting_started/gs-tokens.shtml">REST API</a>.</p> <h3>Installation - standalone</h3><p>Pre-compiled bundles are available from on GitHub Releases - just download the file and drop it into your website: https://github.com/watson-developer-cloud/speech-javascript-sdk/releases</p> <h3>Installation - npm with browserify</h3><p>This library is built with <a href="http://browserify.org/">browserify</a> and easy to use in browserify-based projects :</p> <pre class="prettyprint source"><code>npm install --save watson-speech</code></pre><h2>Breaking change for v0.22.0</h2><p>The format of objects emitted in objectMode has changed from <code>{alternatives: [...], index: 1}</code> to <code>{results: [{alternatives: [...]}], result_index: 1}</code>. This was done to enable the new <code>speaker_labels</code> feature. There is a new <code>ResultExtractor</code> class and <code>recognizeMicrophone()</code> and <code>recognizeFile()</code> both accept a new <code>extract_results</code> option to restore the old behavior.</p> <p>The format now exactly matches what the Watson Speech to Text service returns and shouldn't change again unless the Watson service changes.</p> <h2>API &amp; Examples</h2><p>The basic API is outlined below, see complete API docs at http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/</p> <p>See several examples at https://github.com/watson-developer-cloud/speech-javascript-sdk/tree/v0.28.4/examples/static/</p> <p>All API methods require an auth token that must be <a href="https://github.com/watson-developer-cloud/node-sdk#authorization">generated server-side</a>. (See https://github.com/watson-developer-cloud/speech-javascript-sdk/tree/v0.28.4/examples/ for a couple of basic examples in Node.js and Python.)</p> <h2><a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/module-watson-speech_text-to-speech.html"><code>WatsonSpeech.TextToSpeech</code></a></h2><h3><a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/module-watson-speech_text-to-speech_synthesize.html"><code>.synthesize({text, token})</code></a> -&gt; <code>&lt;audio&gt;</code></h3><p>Speaks the supplied text through an automatically-created <code>&lt;audio&gt;</code> element. Currently limited to text that can fit within a GET URL (this is particularly an issue on <a href="http://stackoverflow.com/questions/32267442/url-length-limitation-of-microsoft-edge">Internet Explorer before Windows 10</a> where the max length is around 1000 characters after the token is accounted for.)</p> <p>Options: </p> <ul> <li>text - the text to transcribe // todo: list supported languages</li> <li>voice - the desired playback voice's name - see .getVoices(). Note that the voices are language-specific.</li> <li>autoPlay - set to false to prevent the audio from automatically playing</li> </ul> <h2><a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/module-watson-speech_speech-to-text.html"><code>WatsonSpeech.SpeechToText</code></a></h2><h3><a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/module-watson-speech_speech-to-text_recognize-microphone.html"><code>.recognizeMicrophone({token})</code></a> -&gt; Stream</h3><p>Options: </p> <ul> <li><code>keepMic</code>: if true, preserves the MicrophoneStream for subsequent calls, preventing additional permissions requests in Firefox</li> <li>Other options passed to <a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/RecognizeStream.html">RecognizeStream</a></li> <li>Other options passed to <a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/WritableElementStream.html">WritableElementStream</a> if <code>options.outputElement</code> is set</li> </ul> <p>Requires the <code>getUserMedia</code> API, so limited browser compatibility (see http://caniuse.com/#search=getusermedia) Also note that Chrome requires https (with a few exceptions for localhost and such) - see https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features</p> <p>Pipes results through a <a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/FormatStream.html">FormatStream</a> by default, set <code>options.format=false</code> to disable.</p> <p>Known issue: Firefox continues to display a microphone icon in the address bar after recording has ceased. This is a browser bug.</p> <h3><a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/module-watson-speech_speech-to-text_recognize-file.html"><code>.recognizeFile({data, token})</code></a> -&gt; Stream</h3><p>Can recognize and optionally attempt to play a <a href="https://developer.mozilla.org/en-US/docs/Web/API/File">File</a> or <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a> (such as from an <code>&lt;input type=&quot;file&quot;/&gt;</code> or from an ajax request.)</p> <p>Options: </p> <ul> <li><code>data</code>: a <code>Blob</code> or <code>File</code> instance. </li> <li><code>play</code>: (optional, default=<code>false</code>) Attempt to also play the file locally while uploading it for transcription </li> <li>Other options passed to <a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/RecognizeStream.html">RecognizeStream</a></li> <li>Other options passed to <a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/WritableElementStream.html">WritableElementStream</a> if <code>options.outputElement</code> is set</li> </ul> <p><code>play</code>requires that the browser support the format; most browsers support wav and ogg/opus, but not flac.) Will emit a <code>playback-error</code> on the RecognizeStream if playback fails. Playback will automatically stop when <code>.stop()</code> is called on the RecognizeStream.</p> <p>Pipes results through a <a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/TimingStream.html">TimingStream</a> by if <code>options.play=true</code>, set <code>options.realtime=false</code> to disable.</p> <p>Pipes results through a <a href="http://watson-developer-cloud.github.io/speech-javascript-sdk/v0.28.4/FormatStream.html">FormatStream</a> by default, set <code>options.format=false</code> to disable.</p> <h2>Changes</h2><p>There have been a few breaking changes in recent releases:</p> <ul> <li>Removed <code>SpeechToText.recognizeElement()</code> due to quality issues</li> <li>renamed <code>recognizeBlob</code> to <code>recognizeFile</code> to make the primary usage more apparent</li> <li>Changed <code>playFile</code> option of <code>recognizeBlob()</code> to just <code>play</code>, corrected default</li> <li>Changed format of objects emitted in objectMode to exactly match what service sends. Added <code>ResultStrean</code> class and <code>extract_results</code> option to enable older behavior.</li> <li>Changed <code>playback-error</code> event to just <code>error</code> when recognizing and playing a file. Check for <code>error.name == 'UNSUPPORTED_FORMAT'</code> to identify playback errors</li> </ul> <p>See <a href="CHANGELOG.md">CHANGELOG.md</a> for a complete list of changes.</p> <h2>todo</h2><ul> <li>Further solidify API</li> <li>break components into standalone npm modules where it makes sense</li> <li>run integration tests on travis (fall back to offline server for pull requests)</li> <li>add even more tests</li> <li>better cross-browser testing (IE, Safari, mobile browsers - maybe saucelabs?)</li> <li>update node-sdk to use current version of this lib's RecognizeStream (and also provide the FormatStream + anything else that might be handy)</li> <li>move <code>result</code> and <code>results</code> events to node wrapper (along with the deprecation notice)</li> <li>improve docs</li> <li>consider a wrapper to match https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html</li> <li>support a &quot;hard&quot; stop that prevents any further data events, even for already uploaded audio, ensure timing stream also implements this.</li> <li>look for bug where single-word final results may omit word confidence (possibly due to FormatStream?)</li> <li>fix bug where TimingStream shows words slightly before they're spoken</li> </ul></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="ResultStream.html">ResultStream</a></li><li><a href="SpeakerStream.html">SpeakerStream</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:data">data</a></li><li><a href="RecognizeStream.html#event:error">error</a></li><li><a href="RecognizeStream.html#event:listening">listening</a></li><li><a href="RecognizeStream.html#event:message">message</a></li><li><a href="RecognizeStream.html#event:open">open</a></li><li><a href="RecognizeStream.html#event:send-data">send-data</a></li><li><a href="RecognizeStream.html#event:send-json">send-json</a></li><li><a href="RecognizeStream.html#event:stop">stop</a></li><li><a href="SpeakerStream.html#event:data">data</a></li></ul><h3>Global</h3><ul><li><a href="global.html#getContentTypeFromFile">getContentTypeFromFile</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.3</a> on Tue Jan 10 2017 15:30:38 GMT+0000 (UTC) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>