Skip to content

Commit 884f29b

Browse files
adjustment errorOccurred
1 parent 95fcd2c commit 884f29b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

projects/voicecapture-angular/src/lib/voicecapture-angular.component.legacy.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class VoiceCaptureLegacy implements OnInit {
2626
@Output() voiceTranscript = new EventEmitter<string>();
2727

2828
finalTranscript: string = '';
29+
errorOccurred: boolean = false;
2930
recognizing: boolean = false;
3031
recognition: any = null;
3132
animationButton: boolean = false;
@@ -81,6 +82,7 @@ export class VoiceCaptureLegacy implements OnInit {
8182

8283
this.recognition.onstart = () => {
8384
this.recognizing = true;
85+
this.errorOccurred = false;
8486
this.updateText('speakNow');
8587
this.animationButton = true;
8688
this.cdr.markForCheck();
@@ -89,6 +91,7 @@ export class VoiceCaptureLegacy implements OnInit {
8991
this.recognition.onerror = (event: any) => {
9092
console.error('Recognition error (onerror event):', event.error);
9193
this.animationButton = false;
94+
this.errorOccurred = true;
9295
this.handleError(event.error);
9396
this.cdr.markForCheck();
9497
};
@@ -99,7 +102,7 @@ export class VoiceCaptureLegacy implements OnInit {
99102
if (this.finalTranscript) {
100103
this.updateText('');
101104
this.voiceTranscript.emit(this.finalTranscript);
102-
} else {
105+
} else if (!this.errorOccurred) {
103106
console.warn('Recognition stopped without result.');
104107
this.updateText('noSpeech');
105108

projects/voicecapture-angular/src/lib/voicecapture-angular.component.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class VoiceCapture implements OnInit {
3030

3131
finalTranscript: string = '';
3232
recognizing: boolean = false;
33+
errorOccurred: boolean = false;
3334
recognition: any = null;
3435
animationButton: boolean = false;
3536
translations: { [key: string]: { [key: string]: string } } = translates;
@@ -84,6 +85,7 @@ export class VoiceCapture implements OnInit {
8485

8586
this.recognition.onstart = () => {
8687
this.recognizing = true;
88+
this.errorOccurred = false;
8789
this.updateText('speakNow');
8890
this.animationButton = true;
8991
this.cdr.markForCheck();
@@ -92,6 +94,7 @@ export class VoiceCapture implements OnInit {
9294
this.recognition.onerror = (event: any) => {
9395
console.error('Recognition error (onerror event):', event.error);
9496
this.animationButton = false;
97+
this.errorOccurred = true;
9598
this.handleError(event.error);
9699
this.cdr.markForCheck();
97100
};
@@ -102,7 +105,7 @@ export class VoiceCapture implements OnInit {
102105
if (this.finalTranscript) {
103106
this.updateText('');
104107
this.voiceTranscript.emit(this.finalTranscript);
105-
} else {
108+
} else if (!this.errorOccurred) {
106109
console.warn('Recognition stopped without result.');
107110
this.updateText('noSpeech');
108111

0 commit comments

Comments
 (0)