【问题标题】:ContinuousRecognitionSession.StartAsync() return "Access is denied"ContinuousRecognitionSession.StartAsync() 返回“访问被拒绝”
【发布时间】:2017-08-09 15:36:28
【问题描述】:

我尝试使用 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();
    }
}

【问题讨论】:

  • 您是否在 package.appxmanifest 中添加了麦克风功能?

标签: c# uwp raspberry-pi3 windowsiot background-application


【解决方案1】:

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

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

更多信息可以参考"Set the Microphone device capability""Enable device capabilities"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-13
    • 2021-09-04
    • 1970-01-01
    • 2023-03-21
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    相关资源
    最近更新 更多