2017-08-02 317 views
2

我已经使用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

enter image description here

+0

我知道,这样的语音识别可能看起来很愚蠢,但是你有权访问你的麦克风吗? –

+0

是的,我试图这样做。在Chrome和Windows设置上。没有防守者,没有反病毒...不是我可以释放的是阻挡。只是阻止麦克风的Chrome版本60。 – calebeaires

+0

这很奇怪。我很乐意帮助你解决这个问题,但是因为我不能让你谈及Google的支持? –

回答

0

我发现,如果该网站是SSL下按预期工作在Chrome 60

1

我的Chrome使用Windows 10时,它是在控制台上的日志错误浏览器做同样的事情,我试图在铬59(工程),并更新到60后它被阻止。

此外:我尝试在我的本地服务器上使用WebSpeech Api进行音频输入。如果我通过本地主机连接:XXXX它的工作原理,但是当我通过IP连接它被封锁:XXXX

+0

也发现此[链接](https://stackoverflow.com/questions/34197653/getusermedia-in-chrome-47-without-using-https)。出于某种原因,他们已经做出了这样的改变并且再次将其删除。 – AdeD