Skip to content

Commit

Permalink
re-use speech recognizer instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Ecer committed Jan 22, 2017
1 parent ed13809 commit acb7cae
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@ export const isSpeechRecognitionSupported = () =>
!!SpeechRecognizer;

export class SpeechRecognition {
abort() {
_getOrCreateSpeechRecognizer() {
if (this._recognizer) {
this._recognizer.destroy();
return Promise.resolve(this._recognizer);
}
return SpeechRecognizer.createSpeechRecognizer().then(recognizer => {
this._recognizer = recognizer;
return recognizer;
});
}

start() {
abort() {
if (this._recognizer) {
this._recognizer.destroy();
this._recognizer = null;
}
SpeechRecognizer.createSpeechRecognizer().then(recognizer => {
this._recognizer = recognizer;
}

start() {
this._getOrCreateSpeechRecognizer().then(recognizer => {
const listeners = {};
if (this.onspeechstart) {
listeners.onBeginningOfSpeech = () => this.onspeechstart();
Expand Down

0 comments on commit acb7cae

Please sign in to comment.