0

我尝试使用 BackgroundApplication 在 Raspberry PI 3 中实现语音识别器。我使用 UWP 中的 SpeechRecognizer 类。

调用此函数时出现此错误“访问被拒绝”ContinuousRecognitionSession.StartAsync()

问题是什么?

代码是:

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;
    }
}

public sealed class StartupTask : IBackgroundTask
{
    BackgroundTaskDeferral _deferral;

    public async void Run(IBackgroundTaskInstance taskInstance)
    {
        _deferral = taskInstance.GetDeferral();
        Speech.Initialize();
        await Speech.StartRecognition();
    }
}
4

1 回答 1

1

正如@Tóth Tibor 指出的那样,您需要在 Package.appxmanifest 中声明麦克风功能,如下所示:

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

有关详细信息,您可以参考“设置麦克风设备功能”“启用设备功能”

于 2017-03-22T03:24:01.217 回答