Windows 10通用语音命令命令前缀

时间:2017-01-13 14:56:42

标签: unity3d win-universal-app windows-10-universal voice-recognition cortana

您好我有一个关于在Windows 10 UA中使用语音命令的问题。我已将一个Voice Command Definition文件添加到Unity3D创建的Universal应用程序中,并添加了必要的代码以便在首次运行时安装它。但是,当第一次启动时,它从不响应语音命令。我添加了一个命令前缀,它应该允许某人通过说出该前缀来启动应用程序,但是当我这样做时它只会打开Cortana搜索。

我不知道为什么会这样。

以下是代码的重要部分:

XML:

<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">

  <CommandSet xml:lang="en-gb">
    <CommandPrefix>Unity Battle</CommandPrefix>
    <Example>Speak to the game</Example>

    <Command Name="startWithText">
      <Example>Say the message you want to appear in the game</Example>
      <ListenFor> {naturalLanguage} </ListenFor>
      <Feedback> Starting Game... </Feedback>
      <Navigate/>
    </Command>

  <PhraseTopic Label="naturalLanguage" Scenario="Natural Language"/>

  </CommandSet>

</VoiceCommands>

安装代码:

protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            try
            {
                Windows.Storage.StorageFile vcdStorageFile =
                    await Package.Current.InstalledLocation.GetFileAsync(@"VoiceCommandDefinition.xml");

                await
                    Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinitionManager
                        .InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Installing Voice Commands Failed: " + ex.ToString());
            }
}

开启已激活:

protected override void OnActivated(IActivatedEventArgs args)
        {
            string appArgs = "";

            switch (args.Kind)
            {
                case ActivationKind.Protocol:
                    ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
                    splashScreen = eventArgs.SplashScreen;
                    appArgs += string.Format("Uri={0}", eventArgs.Uri.AbsoluteUri);
                    break;
                case ActivationKind.VoiceCommand:
                    SpeechHelper.HandleSpeechCommand(args);
                    break;
            }
            InitializeUnity(appArgs);
        }

我已经使用附带的调试器运行了代码,但它从未遇到过OnActivated(..)方法。

0 个答案:

没有答案