Azure-Samples / SpeechToText-WebSockets-Javascript

SDK & Sample to do speech recognition using websockets in Javascript
MIT License
216 stars 151 forks source link

Keep microphone #34

Open Cheyenne55 opened 6 years ago

Cheyenne55 commented 6 years ago

Hi there,

Great work and Bing is very good at speech recognition.

However I found that this SDK lacks an option to keep the mic active. If running with Firefox, it keeps prompting for the user's mic (yes you can tick the box to tell Firefox to remember the agreement but hey..).

Would be a nice little option.

raaaar commented 6 years ago

Hi. This seems to be Firefox specific (Chrome, for instance, remembers the choice if an app is served over HTTPS. FF provides a checkbox instead). I don't see an easy fix for this (apart from redirecting the mic output to /dev/null when it's not being used, which is not really nice). If you find a solution, a PR would be appreciated.

Cheyenne55 commented 6 years ago

Hi,

Well in fact there's a solution in here (search for "keepMic"). Would a similar solution also work ?

raaaar commented 6 years ago

https://github.com/watson-developer-cloud/speech-javascript-sdk/blob/0c3a8794af14ac1abbf13bf4e931aab6de5de688/dist/watson-speech.js#L8726 -- that's what I meant by" redirecting mic output to /dev/null" (they pull the audio off the microphone and then ignore it). This is not exactly efficient -- it puts additional load on the system (it keeps the browser interacting with the audio system and then garbage collecting generated chunks). As an alternative to asking a user tick a checkbox, it's a little wasteful, don't you think? Also, not sure if this will play nice with concurrent mic clients.

Cheyenne55 commented 6 years ago

Well that's why it's an option I though, you're not forced to use it but you the option to. On my smartphone I don't see any performance difference whether this is active or not. However I have just checked now and Firefox in mobile does not propose the checkbox to remember the agreement the checkbox so it's very annoying.

They say that the option is made for Firefox : https://github.com/watson-developer-cloud/speech-javascript-sdk/blob/0c3a8794af14ac1abbf13bf4e931aab6de5de688/dist/watson-speech.js#L8743

rcollette commented 6 years ago

I don't get prompted to allow mic access multiple times unless I am opening the example using the file:// protocol. It seems to work fine if you open the example through a host, even localhost.

compulim commented 6 years ago

Hosting on localhost, both Edge and Firefox will prompt multiple times. And Chrome didn't.

I investigated the problem in MicAudioSource.ts. But can someone give explain some designs to me?

I saw the logic is Attach -> Listen -> TurnOn? I understand why Attach need to be public. But why TurnOn/TurnOff is a public method? Is it supposed to be called by the user?