首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Windows10的Chrome版本60上,SpeechRecognition总是被阻止

在Windows10的Chrome版本60上,SpeechRecognition总是被阻止
EN

Stack Overflow用户
提问于 2017-08-02 22:52:43
回答 2查看 1.7K关注 0票数 3

我已经使用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语音服务:

代码语言:javascript
运行
复制
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上使用控制台时出现的日志错误

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-09 21:10:00

我发现,如果网站是在SSL下,SpeechRecognition在Chrome60上的工作方式是预期的。

票数 1
EN

Stack Overflow用户

发布于 2017-08-09 17:17:23

我的Chrome浏览器做了同样的事情,我在chrome 59 (有效)上试过了,但在更新到60之后,它被阻止了。

另外:我在我的本地服务器上用WebSpeech Api的音频输入进行了尝试。如果我通过localhost:XXXX连接,它可以工作,但是当我通过ip:XXXX连接时,它会被阻止

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45464201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档