我已经使用webkitSpeechRecognition构建了一个应用程序。录制音频没问题,一切正常,直到Chrome更新为60.SpeechRecognition在Windows 10的Chrome版本60上始终被阻止
该错误仅在Windows 10上发生,但不会在MacOS上进行相同的更新。 (将Chrome 59更新为Chrome 60)
当我尝试使用lib时,它给出错误“not-allowed”。我已经管理Chrome设置并将其设置为always ask for permission
,但结果为always block
。所以Chrome上的错误依然存在,Chrome浏览器不允许应用程序使用麦克风设置。
在Chrome 59(Windows 10)上,此行为不会发生!
这里是用来调用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();
}
}
}
这里使用Chrome 60
我知道,这样的语音识别可能看起来很愚蠢,但是你有权访问你的麦克风吗? –
是的,我试图这样做。在Chrome和Windows设置上。没有防守者,没有反病毒...不是我可以释放的是阻挡。只是阻止麦克风的Chrome版本60。 – calebeaires
这很奇怪。我很乐意帮助你解决这个问题,但是因为我不能让你谈及Google的支持? –