0

I try implement speech reconizer in Raspberry PI 3 using BackgroundApplication. I using SpeechRecognizer class from UWP.

I get this error “Access is denied” when call this function ContinuousRecognitionSession.StartAsync()

What is the problem?

The code is:

class Speech
{
    private static SpeechRecognizer speechRecognizer;
    public async static void Initialize()
    {
        speechRecognizer = new SpeechRecognizer();
        speechRecognizer.Constraints.Add(new SpeechRecognitionListConstraint(new List<String>() { "Hello" }, "Hello"));

        SpeechRecognitionCompilationResult compilationResult = await speechRecognizer.CompileConstraintsAsync();

        speechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated;
    }

    private static void ContinuousRecognitionSession_ResultGenerated(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args)
    {
        throw new NotImplementedException();
    }

    public static async Task<bool> StartRecognition()
    {
        try
        {
            await speechRecognizer.ContinuousRecognitionSession.StartAsync();
        }
        catch (Exception eException)
        {
            return false;
        }

        return true;
    }
}

and

public sealed class StartupTask : IBackgroundTask
{
    BackgroundTaskDeferral _deferral;

    public async void Run(IBackgroundTaskInstance taskInstance)
    {
        _deferral = taskInstance.GetDeferral();
        Speech.Initialize();
        await Speech.StartRecognition();
    }
}
xlm
  • 6,854
  • 14
  • 53
  • 55

1 Answers1

1

As @Tóth Tibor points out, you need declare microphone capability in Package.appxmanifest like this:

  <Capabilities>
    <DeviceCapability Name="microphone" />
  </Capabilities>

For more information you can reference "Set the Microphone device capability" and "Enable device capabilities".

Rita Han
  • 9,574
  • 1
  • 11
  • 24