Skip to content

Commit ef8aad8

Browse files
committed
Fixed stop method
1 parent f9b155f commit ef8aad8

1 file changed

Lines changed: 9 additions & 22 deletions

File tree

Recognizer.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,28 @@ define('Recognizer', function() {
1414

1515
Recognizer.prototype.start = function() {
1616
var self = this;
17+
this.isStarted = true;
1718
this.recognition.start();
1819
this.recognition.onend = function() {
19-
if (this.isStarted == false) {
20-
this.start();
21-
this.stop();
22-
}
23-
else {
24-
this.start();
20+
if (self.isStarted) {
21+
self.recognition.start();
2522
}
26-
}
23+
};
2724
this.recognition.onresult = function(event) {
2825
if (self.onResult) {
2926
self.onResult({
3027
text: event.results[0][0].transcript,
31-
locale: self.locale,
28+
locale: self.recognition.lang,
3229
id: self.id++
3330
})
3431
}
3532
}
36-
}
33+
};
3734

3835
Recognizer.prototype.stop = function() {
39-
var self = this;
40-
this.recognition.onresult = function(event) {
41-
if (self.onResult) {
42-
self.onResult({
43-
text: event.results[0][0].transcript,
44-
locale: self.locale,
45-
id: self.id++
46-
})
47-
}
48-
}
49-
this.isStarted = true;
50-
this.recognition.onend = function() {
51-
this.stop();
36+
if (this.isStarted) {
37+
this.isStarted = false;
38+
this.recognition.stop();
5239
}
5340
}
5441

0 commit comments

Comments
 (0)