From c3825d9bb085bb8b8c9318aff7e8eab4d489ae9b Mon Sep 17 00:00:00 2001 From: Vincent Le Badezet Date: Mon, 13 Jul 2020 19:59:09 +0200 Subject: [PATCH] feat: Add recognition grammar and lang options (#12) --- README.md | 1 - package.json | 10 +--------- src/SpeechRecognitionWrapper.js | 4 +++- src/Vocal.js | 12 ++++++++++-- yarn.lock | 8 ++++++++ 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5198327..b12691b 100644 --- a/README.md +++ b/README.md @@ -104,5 +104,4 @@ The component passed as children must respect the following constraints: ## Todos - Rewrite with TypeScript -- Expose SpeechRecognition properties via props - Add a connector management to plug external speech-to-text services in diff --git a/package.json b/package.json index 11280b6..84863ee 100644 --- a/package.json +++ b/package.json @@ -85,15 +85,7 @@ ], "@semantic-release/release-notes-generator", "@semantic-release/changelog", - [ - "@semantic-release/git", - { - "assets": [ - "CHANGELOG.md", - "package.json" - ] - } - ], + "@semantic-release/git", "@semantic-release/npm", [ "@semantic-release/github", { diff --git a/src/SpeechRecognitionWrapper.js b/src/SpeechRecognitionWrapper.js index 9e9fc50..fb8e69a 100644 --- a/src/SpeechRecognitionWrapper.js +++ b/src/SpeechRecognitionWrapper.js @@ -2,10 +2,12 @@ import { getUserMediaStream } from '@untemps/user-permissions-utils' class SpeechRecognitionWrapper { static defaultOptions = { - lang: 'fr-FR', + grammars: null, + lang: 'en-US', continuous: false, interimResults: false, maxAlternatives: 1, + serviceURI: null, } static eventTypes = { diff --git a/src/Vocal.js b/src/Vocal.js index e7e9511..d7bb518 100644 --- a/src/Vocal.js +++ b/src/Vocal.js @@ -7,6 +7,8 @@ import MicrophoneIcon from './MicrophoneIcon' const Vocal = ({ children, + grammars, + lang, timeout, ariaLabel, tabIndex, @@ -28,7 +30,7 @@ const Vocal = ({ useEffect(() => { if (SpeechRecognitionWrapper.isSupported) { - recognitionRef.current = __recognitionInstance || new SpeechRecognitionWrapper() + recognitionRef.current = __recognitionInstance || new SpeechRecognitionWrapper({ grammars, lang }) return () => { recognitionRef.current.abort() recognitionRef.current.cleanup() @@ -157,6 +159,10 @@ const Vocal = ({ } Vocal.propTypes = { + /** Defines the grammars understood by the recognition (https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition/grammars) */ + grammars: PropTypes.object, + /** Defines the language understood by the recognition (https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition/lang) */ + lang: PropTypes.string, /** Defines the time in ms to wait before discarding the recognition */ timeout: PropTypes.number, /** Defines the a11y label for the default button */ @@ -175,7 +181,7 @@ Vocal.propTypes = { onSpeechStart: PropTypes.func, /** Defines the handler called when the speech ends */ onSpeechEnd: PropTypes.func, - /** Defines the handler called when a result is recognized */ + /** Defines the handler called when a result is returned from te recognition */ onResult: PropTypes.func, /** Defines the handler called when an error occurs */ onError: PropTypes.func, @@ -184,6 +190,8 @@ Vocal.propTypes = { } Vocal.defaultProps = { + grammars: null, + lang: 'en-US', timeout: 3000, ariaLabel: 'speech', tabIndex: -1, diff --git a/yarn.lock b/yarn.lock index 5f7770f..31feb25 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6466,6 +6466,7 @@ npm@^6.10.3: cmd-shim "^3.0.3" columnify "~1.5.4" config-chain "^1.1.12" + debuglog "*" detect-indent "~5.0.0" detect-newline "^2.1.0" dezalgo "~1.0.3" @@ -6480,6 +6481,7 @@ npm@^6.10.3: has-unicode "~2.0.1" hosted-git-info "^2.8.8" iferr "^1.0.2" + imurmurhash "*" infer-owner "^1.0.4" inflight "~1.0.6" inherits "^2.0.4" @@ -6498,8 +6500,14 @@ npm@^6.10.3: libnpx "^10.2.2" lock-verify "^2.1.0" lockfile "^1.0.4" + lodash._baseindexof "*" lodash._baseuniq "~4.6.0" + lodash._bindcallback "*" + lodash._cacheindexof "*" + lodash._createcache "*" + lodash._getnative "*" lodash.clonedeep "~4.5.0" + lodash.restparam "*" lodash.union "~4.6.0" lodash.uniq "~4.5.0" lodash.without "~4.4.0"