diff --git a/.eslintignore b/.eslintignore index 8dd93b67..7da88777 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,7 +1,3 @@ node_modules/ dist/ -doc/ -examples/static/watson-speech.js -examples/static/scripts/ -examples/node_modules/ -examples/static/webpack-bundle.js +doc/ \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index 12e56628..fdd0bf1f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,30 +1,24 @@ module.exports = { - "parser": "esprima", - "env": { - "node": true, - "browser": true, + parser: 'esprima', + env: { + node: true, + browser: true, }, - 'globals': { + globals: { // we want to enable a limited sub-set of ES6 features // this library should (partially) work even in IE // false meaning this code doesn't define it Promise: false, DataView: false, ArrayBuffer: false, - Float32Array: false + Float32Array: false, }, - "plugins": [ - "prettier", - ], - "extends": [ - "eslint:recommended", - "prettier", - ], - "rules": { - "prettier/prettier": ["error", {"singleQuote": true, "printWidth": 160}], - "no-var": "off", - "prefer-const": "off", - "prefer-rest-params": "off", - "prefer-spread": "off", - } -}; + plugins: ['prettier'], + extends: ['eslint:recommended', 'prettier'], + rules: { + 'no-var': 'off', + 'prefer-const': 'off', + 'prefer-rest-params': 'off', + 'prefer-spread': 'off', + }, +} diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 00000000..e3e4aac1 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,17 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 60 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security +# Label to use when marking an issue as stale +staleLabel: wontfix +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has had no + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false diff --git a/.gitignore b/.gitignore index f58cef7f..9cdf3b12 100644 --- a/.gitignore +++ b/.gitignore @@ -8,11 +8,10 @@ test/resources/tts-auth.json doc/ *-auth.json .env -examples/static/bower_components/ -examples/static/webpack-bundle.js -examples/static/scripts/ -examples/node_modules/ dist/*.js dist/*.map gh-pages/ .idea +watson-speech-*.tgz +IBM_Cloud_CLI_0.6.6_amd64.tar.gz +Bluemix_CLI diff --git a/.npmignore b/.npmignore index b3e92e88..84506553 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,15 @@ doc/ -examples/ jsdoc/ test/ .editorconfig .travis.yml +gh-pages/ +scripts/ +docs/ +.env +.github/ +CHANGELOG.md +bower.json +karma.conf.js +webpack.config.js +watson-speech-*.tgz diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..9845a1c0 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "trailingComma": "es5", + "tabWidth": 2, + "semi": true, + "singleQuote": true, + "arrowParens": "always", + "printWidth": 160 +} diff --git a/.travis.yml b/.travis.yml index 6f0167cf..dd23227e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,12 @@ language: node_js -node_js: 10 +node_js: + - "12" sudo: required -before_install: -- export CHROME_BIN=chromium-browser -- export DISPLAY=:99.0 -- sh -e /etc/init.d/xvfb start +services: + - xvfb +addons: + firefox: "latest" + chrome: "stable" script: - npm run build - npm test @@ -20,15 +22,8 @@ env: - BX_SPACE=sdks before_deploy: npm install -g bx-blue-green deploy: -- provider: script - skip_cleanup: true - script: - - cd examples/ && bx-blue-green-travis - on: - branch: master - repo: watson-developer-cloud/speech-javascript-sdk - provider: script skip_cleanup: true script: npx semantic-release@15 on: - node: 10 + node: 12 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fe7bdd1..e9354689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +### v0.40.0 +* Update vulnerable dependencies +* feat(recognize-stream): add new websocket parameter character_insertion_bias + +### v0.39.1 +* Update vulnerable dependencies +* Update example dependencies (removed vulenerable express-browserify) + +### v0.37.0 +* BREAKING CHANGES INTRODUCED: + * All options parameters for all methods are coverted to be lowerCamelCase + * For example: `access_token` is now `accessToken` and `content-type` is now `contentType` + * Response data from the service is not affected by this change + ### v0.34.0 * Add support for guessing .mp3 (via file name & header) & .webm (via filename) content-types * Re-factored content-type guessing to check filename first, and file header second diff --git a/README.md b/README.md index b5fdcb2f..81648191 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,19 @@ +![](docs/js-sdk.png) IBM Watson Speech Services for Web Browsers -=========================================== [![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) [![npm-version](https://img.shields.io/npm/v/watson-speech.svg)](https://www.npmjs.com/package/watson-speech) Allows you to easily add voice recognition and synthesis to any web app with minimal code. +## Deprecation Notice +This repo and the npm package associated with it are being deprecated. While this repo will no longer see active support from the IBM team, contributions by the community via PRs are still welcomed and will be reviewed. Keep in mind, updates will no longer be published to npm and changes made after this update will need to be built independently. + ### Built for Browsers -This library is primarily intended for use in web browsers. Check out [watson-developer-cloud](https://www.npmjs.com/package/watson-developer-cloud) to use Watson services (speech and others) from Node.js. -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 [Node.js](https://github.com/watson-developer-cloud/node-sdk#authorization), [Java](https://github.com/watson-developer-cloud/java-sdk), [Python](https://github.com/watson-developer-cloud/python-sdk/blob/master/examples/authorization_v1.py), and there is also a [REST API](https://www.ibm.com/watson/developercloud/doc/common/getting-started-tokens.html). +This library is primarily intended for use in web browsers. Check out [ibm-watson](https://www.npmjs.com/package/ibm-watson) to use Watson services (speech and others) from Node.js. +However, a **server-side component is required to generate auth tokens**. SDKs are available for [Node.js](https://github.com/watson-developer-cloud/node-sdk#authorization), [Java](https://github.com/watson-developer-cloud/java-sdk), [Python](https://github.com/watson-developer-cloud/python-sdk/blob/master/examples/authorization_v1.py), which can be used with a server-side application. ### Installation - standalone @@ -37,11 +40,11 @@ var recognizeMic = require('watson-speech/speech-to-text/recognize-microphone'); ## Using with IAM -This SDK _CAN_ be used in the browser with services that use IAM for authentication. This does require a server-side component - an endpoint used to retrieve the token. An example can be found [here](https://github.com/watson-developer-cloud/speech-javascript-sdk/blob/master/examples/server.js#L92). +This SDK _CAN_ be used in the browser with services that use IAM for authentication. This does require a server-side component - an endpoint used to retrieve the token. -In a local environment you should set only the `TEXT_TO_SPEECH_IAM_APIKEY` and `SPEECH_TO_TEXT_IAM_APIKEY` in your `.env` file, see example file [here](https://github.com/watson-developer-cloud/speech-javascript-sdk/blob/master/examples/.env.example). +In a local environment you should set only the `TEXT_TO_SPEECH_IAM_APIKEY` and `SPEECH_TO_TEXT_IAM_APIKEY` in your `.env` file. -Once that is set up, the token can be used in your SDK request with the parameter `access_token`. See [this example](https://github.com/watson-developer-cloud/speech-javascript-sdk/blob/master/examples/static/microphone-streaming.html#L36). +Once that is set up, the token can be used in your SDK request with the parameter `access_token`. ## Using with Angular @@ -60,21 +63,16 @@ See [CHANGELOG.md](CHANGELOG.md) for a complete list of changes. ## Development -### Use examples for development -The provided examples can be used to test developmental code in action: -* `cd examples/` -* `npm run dev` - -This will build the local code, move the new bundle into the `examples/` directory, and start a new server at `localhost:3000` where the examples will be running. +### Global Transaction ID -Note: This requires valid service credentials. +Unfortunately, there is no way to set or get the global transaction id provided by the initial websocket handshake with the Speech service. This is due to limitations from the W3C Websocket API for browser. It is possible; however, to grab the `X-Global-Transaction-Id` header through a browser's dev tool "Network" tab. After making a call to the service, look for a request to the `v1/recognize` endpoint which should return a 101 code. The response headers from that request will contain the `X-Global-Transaction-Id` header. ### Testing + The test suite is broken up into offline unit tests and integration tests that test against actual service instances. -* `npm test` will run the linter and the offline tests -* `npm run test-offline` will run the offline tests -* `npm run test-integration` will run the integration tests -To run the integration tests, a file with service credentials is required. This file must be called `stt-auth.json` and must be located in `/test/resources/`. There are tests for usage of both CF and RC service instances. For testing CF, the required keys in this configuration file are `username` and `password`. For testing RC, a key of either `iam_acess_token` or `iam_apikey` is required. Optionally, a service URL for an RC instance can be provided under the key `rc_service_url` if the service is available under a URL other than `https://stream.watsonplatform.net/speech-to-text/api`. +- `npm test` will run the linter and the offline tests +- `npm run test-offline` will run the offline tests +- `npm run test-integration` will run the integration tests -For an example, see `test/resources/stt-auth-example.json`. +To run the integration tests, service credentials are required. Make sure you have a valid `.env` file in the root directory. diff --git a/bower.json b/bower.json index 6c4669de..9dc3c273 100644 --- a/bower.json +++ b/bower.json @@ -2,26 +2,10 @@ "name": "watson-speech", "description": "IBM Watson Speech to Text and Text to Speech SDK for web browsers.", "main": "dist/watson-speech.js", - "authors": [ - "Nathan Friedly " - ], + "authors": ["Nathan Friedly "], "license": "Apache-2.0", - "keywords": [ - "voice", - "recognition", - "speech", - "text", - "transcription", - "synthesis" - ], - "moduleType": [ - "amd", - "globals", - "node" - ], + "keywords": ["voice", "recognition", "speech", "text", "transcription", "synthesis"], + "moduleType": ["amd", "globals", "node"], "homepage": "https://watson-speech.mybluemix.net/", - "ignore": [ - "**/*", - "!dist/*.js" - ] + "ignore": ["**/*", "!dist/*.js"] } diff --git a/docs/README.md b/docs/README.md index 837a4de8..572bd84a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,13 +1,5 @@ -API & Examples --------------- +## API & Examples The basic API is outlined below, see complete API docs at http://watson-developer-cloud.github.io/speech-javascript-sdk/master/ -See several basic examples at http://watson-speech.mybluemix.net/ ([source](https://github.com/watson-developer-cloud/speech-javascript-sdk/tree/master/examples/)) - -See a more advanced example at https://speech-to-text-demo.mybluemix.net/ - -All API methods require an auth token that must be [generated server-side](https://github.com/watson-developer-cloud/node-sdk#authorization). -(See https://github.com/watson-developer-cloud/speech-javascript-sdk/tree/master/examples/ for a couple of basic examples in Node.js and Python.) - -_NOTE_: The `token` parameter only works for CF instances of services. For RC services using IAM for authentication, the `access_token` parameter must be used. +All API methods require an auth token that must be [generated server-side](https://github.com/watson-developer-cloud/node-sdk#authorization). diff --git a/docs/SPEECH-TO-TEXT.md b/docs/SPEECH-TO-TEXT.md index 55891554..9f46828c 100644 --- a/docs/SPEECH-TO-TEXT.md +++ b/docs/SPEECH-TO-TEXT.md @@ -8,47 +8,47 @@ The core of the library is the [RecognizeStream] that performs the actual transc _NOTE_ The RecognizeStream class lives in the Watson Node SDK. Any option available on this class can be passed into the following methods. These parameters are documented at http://watson-developer-cloud.github.io/node-sdk/master/classes/recognizestream.html -### [`.recognizeMicrophone({token||access_token})`](http://watson-developer-cloud.github.io/speech-javascript-sdk/master/module-watson-speech_speech-to-text_recognize-microphone.html) -> Stream +### [`.recognizeMicrophone({token||accessToken})`](http://watson-developer-cloud.github.io/speech-javascript-sdk/master/module-watson-speech_speech-to-text_recognize-microphone.html) -> Stream -Options: -* `keepMicrophone`: if true, preserves the MicrophoneStream for subsequent calls, preventing additional permissions requests in Firefox -* `mediaStream`: Optionally pass in an existing media stream rather than prompting the user for microphone access. -* Other options passed to [RecognizeStream] -* Other options passed to [SpeakerStream] if `options.resultsbySpeaker` is set to true -* Other options passed to [FormatStream] if `options.format` is not set to false -* Other options passed to [WritableElementStream] if `options.outputElement` is set +Options: -Requires the `getUserMedia` API, so limited browser compatibility (see http://caniuse.com/#search=getusermedia) +- `keepMicrophone`: if true, preserves the MicrophoneStream for subsequent calls, preventing additional permissions requests in Firefox +- `mediaStream`: Optionally pass in an existing media stream rather than prompting the user for microphone access. +- Other options passed to [RecognizeStream] +- Other options passed to [SpeakerStream] if `options.resultsbySpeaker` is set to true +- Other options passed to [FormatStream] if `options.format` is not set to false +- Other options passed to [WritableElementStream] if `options.outputElement` is set + +Requires the `getUserMedia` 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 No more data will be set after `.stop()` is called on the returned stream, but additional results may be recieved for already-sent data. - -### [`.recognizeFile({data, token||access_token})`](http://watson-developer-cloud.github.io/speech-javascript-sdk/master/module-watson-speech_speech-to-text_recognize-file.html) -> Stream +### [`.recognizeFile({data, token||accessToken})`](http://watson-developer-cloud.github.io/speech-javascript-sdk/master/module-watson-speech_speech-to-text_recognize-file.html) -> Stream Can recognize and optionally attempt to play a URL, [File](https://developer.mozilla.org/en-US/docs/Web/API/File) or [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) (such as from an `` or from an ajax request.) -Options: -* `file`: a String URL or a `Blob` or `File` instance. Note that [CORS] restrictions apply to URLs. -* `play`: (optional, default=`false`) Attempt to also play the file locally while uploading it for transcription -* Other options passed to [RecognizeStream] -* Other options passed to [TimingStream] if `options.realtime` is true, or unset and `options.play` is true -* Other options passed to [SpeakerStream] if `options.resultsbySpeaker` is set to true -* Other options passed to [FormatStream] if `options.format` is not set to false -* Other options passed to [WritableElementStream] if `options.outputElement` is set +Options: -`play` requires that the browser support the format; most browsers support wav and ogg/opus, but not flac.) +- `file`: a String URL or a `Blob` or `File` instance. Note that [CORS] restrictions apply to URLs. +- `play`: (optional, default=`false`) Attempt to also play the file locally while uploading it for transcription +- Other options passed to [RecognizeStream] +- Other options passed to [TimingStream] if `options.realtime` is true, or unset and `options.play` is true +- Other options passed to [SpeakerStream] if `options.resultsbySpeaker` is set to true +- Other options passed to [FormatStream] if `options.format` is not set to false +- Other options passed to [WritableElementStream] if `options.outputElement` is set + +`play` requires that the browser support the format; most browsers support wav and ogg/opus, but not flac.) Will emit an `UNSUPPORTED_FORMAT` error on the RecognizeStream if playback fails. This error is special in that it does not stop the streaming of results. -Playback will automatically stop when `.stop()` is called on the returned stream. +Playback will automatically stop when `.stop()` is called on the returned stream. For Mobile Safari compatibility, a URL must be provided, and `recognizeFile()` must be called in direct response to a user interaction (so the token must be pre-loaded). -[RecognizeStream]: http://watson-developer-cloud.github.io/node-sdk/master/classes/recognizestream.html -[TimingStream]: http://watson-developer-cloud.github.io/speech-javascript-sdk/master/TimingStream.html -[FormatStream]: http://watson-developer-cloud.github.io/speech-javascript-sdk/master/FormatStream.html -[WritableElementStream]: http://watson-developer-cloud.github.io/speech-javascript-sdk/master/WritableElementStream.html -[SpeakerStream]: http://watson-developer-cloud.github.io/speech-javascript-sdk/master/SpeakerStream.html -[CORS]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS - +[recognizestream]: http://watson-developer-cloud.github.io/node-sdk/master/classes/recognizestream.html +[timingstream]: http://watson-developer-cloud.github.io/speech-javascript-sdk/master/TimingStream.html +[formatstream]: http://watson-developer-cloud.github.io/speech-javascript-sdk/master/FormatStream.html +[writableelementstream]: http://watson-developer-cloud.github.io/speech-javascript-sdk/master/WritableElementStream.html +[speakerstream]: http://watson-developer-cloud.github.io/speech-javascript-sdk/master/SpeakerStream.html +[cors]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS diff --git a/docs/TEXT-TO-SPEECH.md b/docs/TEXT-TO-SPEECH.md index b264506f..dfba5899 100644 --- a/docs/TEXT-TO-SPEECH.md +++ b/docs/TEXT-TO-SPEECH.md @@ -2,17 +2,18 @@ ## [`WatsonSpeech.TextToSpeech`](http://watson-developer-cloud.github.io/speech-javascript-sdk/master/module-watson-speech_text-to-speech.html) -### [`.synthesize({text, token||access_token})`](http://watson-developer-cloud.github.io/speech-javascript-sdk/master/module-watson-speech_text-to-speech_synthesize.html) -> `