SpeechRecognition 在 Windows 10 中的 Chrome 版本 60 上始终被阻止
SpeechRecognition is always blocked on Chrome version 60 in Windows 10
我已经使用 webkitSpeechRecognition 构建了一个应用程序。录制音频一切正常,直到 chrome 更新到 60。
该错误仅发生在 Windows 10 上,但不会发生在具有相同更新的 MacOS 上。 (将 Chrome 59 更新为 Chrome 60)
当我尝试使用库时出现错误 "not-allowed"。我已管理 chrome 设置并将其设置为 always ask for permission
,但结果变为 always block
。因此 Chrome 上的错误仍然存在并且 chrome 不允许应用程序使用麦克风设置。
在 Chrome 59 (Windows 10) 上,不会发生此行为!
这里是用来调用api的angular语音服务:
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();
}
}
}
这是在 Windows 10 和 Chrome 60
上使用它时控制台上的日志错误
我的 Chrome 浏览器也这样做,我在 chrome 59(有效)中尝试过,更新到 60 后它被阻止了。
另外:我在我的本地服务器上用 WebSpeech Api 的音频输入试过了。如果我通过 localhost:XXXX 连接它可以工作但是当我通过 ip:XXXX
连接时它被阻止
我发现,如果网站使用 SSL,SpeechRecognition 会在 Chrome 60 上按预期工作。
我已经使用 webkitSpeechRecognition 构建了一个应用程序。录制音频一切正常,直到 chrome 更新到 60。
该错误仅发生在 Windows 10 上,但不会发生在具有相同更新的 MacOS 上。 (将 Chrome 59 更新为 Chrome 60)
当我尝试使用库时出现错误 "not-allowed"。我已管理 chrome 设置并将其设置为 always ask for permission
,但结果变为 always block
。因此 Chrome 上的错误仍然存在并且 chrome 不允许应用程序使用麦克风设置。
在 Chrome 59 (Windows 10) 上,不会发生此行为!
这里是用来调用api的angular语音服务:
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();
}
}
}
这是在 Windows 10 和 Chrome 60
上使用它时控制台上的日志错误我的 Chrome 浏览器也这样做,我在 chrome 59(有效)中尝试过,更新到 60 后它被阻止了。
另外:我在我的本地服务器上用 WebSpeech Api 的音频输入试过了。如果我通过 localhost:XXXX 连接它可以工作但是当我通过 ip:XXXX
连接时它被阻止我发现,如果网站使用 SSL,SpeechRecognition 会在 Chrome 60 上按预期工作。