我已经使用webkitSpeechRecognition构建了一个应用程序。录制的音频很好,一切都很好,直到chrome更新到60。
该错误仅出现在Windows10上,而不会出现在具有相同更新的MacOS上。(将Chrome 59更新为Chrome 60)
当我尝试使用lib时,它给出了错误"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();
}
}
}
以下是在装有Chrome 60的Windows 10上使用控制台时出现的日志错误
发布于 2017-08-09 21:10:00
我发现,如果网站是在SSL下,SpeechRecognition在Chrome60上的工作方式是预期的。
发布于 2017-08-09 17:17:23
我的Chrome浏览器做了同样的事情,我在chrome 59 (有效)上试过了,但在更新到60之后,它被阻止了。
另外:我在我的本地服务器上用WebSpeech Api的音频输入进行了尝试。如果我通过localhost:XXXX连接,它可以工作,但是当我通过ip:XXXX连接时,它会被阻止
https://stackoverflow.com/questions/45464201
复制相似问题