Skip to content

Commit

Permalink
feat: Add recognition grammar and lang options (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
untemps authored Jul 13, 2020
1 parent 8d15010 commit c3825d9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 1 addition & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
4 changes: 3 additions & 1 deletion src/SpeechRecognitionWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
12 changes: 10 additions & 2 deletions src/Vocal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import MicrophoneIcon from './MicrophoneIcon'

const Vocal = ({
children,
grammars,
lang,
timeout,
ariaLabel,
tabIndex,
Expand All @@ -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()
Expand Down Expand Up @@ -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 */
Expand All @@ -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,
Expand All @@ -184,6 +190,8 @@ Vocal.propTypes = {
}

Vocal.defaultProps = {
grammars: null,
lang: 'en-US',
timeout: 3000,
ariaLabel: 'speech',
tabIndex: -1,
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit c3825d9

Please sign in to comment.