SpeechRecognizer not work, COMException: Class not

2019-05-28 08:50发布

问题:

After I have installed Windows IoT (10.0.10586) and Visual Studio 2015 with Update 1, I got COM-Exception when I use the SpeechRecognizer in Universal App on my Raspberry Pi 2 (with Windows IoT 10.0.10586).

If I run the SpeechRecognizer UWP App on Windows 10 it works without any problems, the COM-Exception occurs only in Windows IoT (10.0.10586). With older version of Windows IoT and Visual Studio 2015 without Update 1 it works, too.

Has anyone a solution for the problem?

var speechRecognizer = new SpeechRecognizer();
var constraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "dictation");
speechRecognizer.Constraints.Add(constraint);
await speechRecognizer.CompileConstraintsAsync();

//This line throw exception:
//Exception thrown: 'System.Runtime.InteropServices.COMException' in App.exe
//WinRT information: Class not registered
//Operation not supported.Unknown error: 0x80070057.
var result = await speechRecognizer.RecognizeWithUIAsync();

To get the sample work enable the following capabilities in the Package.appxmainifest:

Internet (Client) and Microphone

Edit

Like Eric Brown said RecognizeWithUIAsync seems not to work with Windows IoT (I rememberd not correctly, it seems to be I never used RecognizeWithUIAsync but I know SpeechRecognizer works in past).

But RecognizeAsync does not work for me, too. No Exception is thrown, but RecognizeAsync not wait for speech, it directly returns an SpeechRecognitionResult-object where property Confidence is Rejected and Status is Success, but spoken Text is always an empty string. It works on Windows 10, but not on Windows IoT.

Has anyone an idea why no speech is detected/ the spoken words not will be returned?

var speechRecognizer = new SpeechRecognizer();
var constraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "dictation");
speechRecognizer.Constraints.Add(constraint);
await speechRecognizer.CompileConstraintsAsync();
while (true)
{
    var result = await speechRecognizer.RecognizeAsync();
    Debug.WriteLine(!string.IsNullOrEmpty(result.Text) ? result.Text : "No speech in result.");
}

To get the sample work enable the following capabilities in the Package.appxmainifest:

Internet (Client) and Microphone

回答1:

RecognizeWithUIAsync isn't implemented in Windows IoT (because there's no UI). You can use RecognizeAsync just fine.



回答2:

Finally got SpeechRecognizer to work with Windows IoT 10.0.10586 and Visual Studio 2015 Update 1.

The solution: Use a microphone that is fully compatible with Windows IoT 10.0.10586. I use the Microsoft LifeCam HD-3000 (there is a microphone included).

SpeechRecognizer now working with ContinuousRecognitionSession and RecognizeAsync with a grammer file (file that defines what user can say) and with dictation (free speech). RecognizeWithUIAsync not work and maybe never will work (see Eric Browns answer).

Note: It is a mistake to believe that if a microphone works in any other app, it have to work with SpeechRecognizer, too. I have a microphone that works with a simple audio recorder app, but not works with the SpeechRecognizer. Note also that microphones that have worked with SpeechRecognizer in older Windows IoT versions not always have to work with SpeechRecognizer in Windows IoT 10.0.10586.

It is not really nice to use a webcam as microphone. If someone has a microphone that works with SpeechRecognizer and Windows IoT 10.0.10586 please post it.


If you look for a SpeechRecognizer ContinuousRecognitionSession with a grammar file example you can look in following project. In the comments you can see how you can use other languages with SpeechRecognizer.

https://www.hackster.io/krvarma/rpivoice-051857


Perhaps there is in future driver updates in Windows Updates and we no longer have such problems.