我尝试使用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();
}
}
答案 0 :(得分:1)
正如@TóthTibor所指出的,你需要在Package.appxmanifest中声明麦克风功能,如下所示:
<Capabilities>
<DeviceCapability Name="microphone" />
</Capabilities>
有关详情,请参阅"Set the Microphone device capability"和"Enable device capabilities"。