Apps that use WindowsSpeechInputProvider can't start in noisy environments
Ported to github, reference 21521102
This is unconfirmed, but seems to be highly likely based on other recent observations, so we wanted to get it on the radar. The problem is that Windows.Media.SpeechRecognition.SpeechRecognizer can block for up to 20 seconds while processing audio input, and this can happen during instantiation. SpeechRecognizer is wrapped by Unity's KeywordRecognizer, which is initialized on the Unity main thread, and in turn instantiates SpeechRecognizer on the Unity main thread. If you launch an app that uses Unity's KeywordRecognizer in a noisy environment, the app "hangs" on SpeechRecognizer, and PLM will kill the app as it appears to be unresponsive.
Ideally, this would be fixed in SpeechRecognizer, but this work isn't currently planned.
The next best place to have this fixed is in Unity's wrapper (KeywordRecognizer), but as far as I can tell Unity does not intend to implement a workaround for the underlying Windows API bug. We could try to push on this more, but I don't think it is currently being considered.
In the meantime, it would probably make sense to work around the problem in MRTK's WindowsSpeechInputProvider. The recommendation from Unity is to asynchronously instantiate the SpeechRecognizer explicitly on a background thread, and delay instantiation of KeywordRecognizer until instantiation is complete (see https://forum.unity.com/threads/hololens-app-gets-stuck-during-keywordrecognizer-constructor-when-in-a-noisy-environment.648853/). Presumably this works because there is some global/singleton underlying state for SpeechRecognizer that all instances use, not sure.
I think in MRTK this would mean speech input might not work in a noisy environment until 20+ seconds after launching the app, but this might be the best we can do if the underlying Windows bug is not addressed.
Duplicate of #3497