我已經使用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的支持? –