I have built one aplication using webkitSpeechRecognition. Record audio were fine and everything were ok until chrome update to 60.
The error occurs only on Windows 10 but not on MacOS whith the same update. (Update Chrome 59 to Chrome 60)
When I try to use the lib it give the error "not-allowed". I have manage chrome settings and set it to always ask for permission
, but results goes to always block
. So the error on Chrome persist and chrome does not allow the app to use mic settings.
On Chrome 59 (Windows 10), this behavor does not occurs!
Here is the angular speech service used to call the api:
import { UserService } from './user.service';
import { Injectable, NgZone } from '@angular/core';
import { Observable } from 'rxjs/Rx';
interface IWindow extends Window {
webkitSpeechRecognition: any;
SpeechRecognition: any;
}
@Injectable()
export class SpeechRecognitionService {
speechRecognition: any;
_me: any;
constructor(private userService: UserService, private zone: NgZone) {
this._me = userService.profile;
}
record(): Observable<string> {
return Observable.create(observer => {
const { webkitSpeechRecognition }: IWindow = <IWindow>window;
this.speechRecognition = new webkitSpeechRecognition();
this.speechRecognition.continuous = false;
// this.speechRecognition.interimResults = true;
this.speechRecognition.lang = this._me.lang;
this.speechRecognition.maxAlternatives = 1;
this.speechRecognition.onresult = speech => {
let term = '';
if (speech.results) {
const result = speech.results[speech.resultIndex];
const transcript = result[0].transcript;
if (result.isFinal) {
if (result[0].confidence < 0.3) {
console.log('Unrecognized result - Please try again');
} else {
term = transcript.trim();
console.log('Did you said? -> ' + term + ' , If not then say something else...');
}
}
}
this.zone.run(() => {
observer.next(term);
});
};
this.speechRecognition.onerror = error => {
observer.error(error);
};
this.speechRecognition.onend = () => {
observer.complete();
};
this.speechRecognition.start();
console.log('Say something - We are listening !!!');
});
}
stop() {
if (this.speechRecognition) {
this.speechRecognition.stop();
}
}
}
Here is the log error on console when using it on Windows 10 with Chrome 60