Cortana应用程序无法在Windows Phone 8.1 Emulator上运行

Cortana应用程序无法在Windows Phone 8.1 Emulator上运行

问题描述:

我正在使用Windows Phone 8.1创建cortana应用程序。在我的应用程序中,我有3-4页,并试图编写能够在内部导航页面的代码。当我运行应用程序它工作正常,当我使用Cortana到
启动应用程序它无法识别语音也我试图键入文本DEVCON SHOW VENUE来启动代码但它是不工作。

I am using Windows Phone 8.1 to create cortana application. In my application i am having 3-4 pages and trying to wrote code which can be able to navigate pages internally. When I am running the application it is working fine, when i am using Cortana to launch the application it is not able to recognize the voice also i have tried to type the text DEVCON SHOW VENUE to launch the code but it is not working.

我附上了以下代码。

请完整填写。

先谢谢

Speech.xml - > VCD.xml

Speech.xml -->VCD.xml

<?xml version =" 1.0" encoding =" utf-8"?>
$


< VoiceCommands xmlns =" http://schemas.microsoft.com/voicecommands/1.1"&gt ;

  < CommandSet xml:lang =" zh-CN">

  &NBSP; < CommandPrefix> DevCon< / CommandPrefix>

  &NBSP; <实施例&GT; show DevCon场地< /示例>



  &NBSP; < Command Name =" ShowMenu">

  &NBSP; &NBSP; &LT;! - <实施例&GT;开放场地< /示例> - >

  &NBSP; &NBSP; &LT; ListenFor&GT; [打开] {menu}< / ListenFor>

  &NBSP; &NBSP; &LT;反馈和GT;显示DevCon {menu}< / Feedback>

  &NBSP; &NBSP; <导航/>

  &NBSP; < / Command>



  &NBSP; < PhraseList Label =" menu">

  &NBSP; &NBSP; &LT;项目&GT;场地< / Item>

  &NBSP; &NBSP; &LT;项目&GT;发言者< / Item>

  &NBSP; &NBSP; &LT;项目&GT;会话< / Item>

  &NBSP; < / PhraseList>



  < / CommandSet>

< / VoiceCommands>



<! - 示例 - >

<! -

$
  &NBSP;前面的例子演示了一个名为"Contoso ROD3O!"的假想游戏,该游戏定义了两个b
  &NBSP;用户可以说的命令是开始新游戏或重放游戏中的三个级别之一。  

  &NBSP;为了发起PlayGame命令,用户可以说"Contoso Rodeo play  new game"。或"Contoso Rodeo

  &NBSP;玩新游戏"这两个短语都会开始一个新游戏。要启动第二个命令,用户可以说

  &NBSP; "Contoso Rodeo重播级别1","Contoso Rodeo重播级别2"或"Contoso Rodeo重播级别 

  &NBSP;三个"。"
  &NBSP;第二个Command演示如何使用带有Command的PhraseList。短语列表可以更新 
  &NBSP;应用程序动态地(例如,如果用户解锁新级别或游戏或功能,您可能希望允许用户在语音命令已经注册后为新功能提供命令。)

  &NBSP;第三个命令演示{*}序列如何与另一个命令并行识别语音

  &NBSP;在CommandSet中没有定义。



 注意:



  &NBSP; &NBSP; [和]表示"和"是可选的。制作像这样的连接词可选

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;可以帮助"Contoso Rodeo,玩新游戏"和"打开Contoso Rodeo并玩
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;一款新游戏"说话很自然。



  &NBSP; &NBSP; {number}与Command分开定义,映射到"one"。或"两个"或"两个"或"三"。



- >

<?xml version="1.0" encoding="utf-8"?>

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1">
  <CommandSet xml:lang="en-US">
    <CommandPrefix>DevCon</CommandPrefix>
    <Example> show DevCon venue </Example>

    <Command Name="ShowMenu">
      <!--<Example> open venue </Example>-->
      <ListenFor> [open] {menu} </ListenFor>
      <Feedback> Showing DevCon {menu} </Feedback>
      <Navigate />
    </Command>

    <PhraseList Label="menu">
      <Item> venue </Item>
      <Item> speakers </Item>
      <Item> sessions </Item>
    </PhraseList>

  </CommandSet>
</VoiceCommands>

<!-- Example -->
<!--

    The preceding example demonstrates a hypothetical game called 'Contoso ROD3O!' which defines two
    Commands that a user can say to either start a new game or replay one of three levels in the game.  
    To initiate the PlayGame command, a user can say "Contoso Rodeo play  a new game" or "Contoso Rodeo
    play new game". Either phrase will start a new game. To initiate the second Command, a user can say
    "Contoso Rodeo replay level one", "Contoso Rodeo replay level two", or "Contoso Rodeo replay level 
    three".
    The second Command demonstrates how to use a PhraseList with a Command. PhraseLists can be updated 
    dynamically by the application (e.g., if a user unlocks a new level or game or feature, you might 
    want to allow the user to give commands for newfeatures after voice commands are already registered.)
    The third Command demonstrates how the {*} sequence can parallel another command to recognize speech
    that is not defined in the CommandSet.

  Note:

      [and] Indicates that "and" is optional. Making connecting words like this optional
            can help both "Contoso Rodeo, play new game" and "open Contoso Rodeo and play
            a new game" feel natural to speak.

      {number} Defined separately from the Command, mapping to "one" or "two" or "three".

-->

------------- -------------------------------------------------- --------

-----------------------------------------------------------------------

关于MainPage.xml的导航和InstallVoiceCommand函数

On Navigation and InstallVoiceCommand function of MainPage.xml

    protected override void OnNavigatedTo(NavigationEventArgs e)

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var args = e.Parameter as VoiceCommandActivatedEventArgs;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(args!= null)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IReadOnlyList&LT;串GT;短语;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(args.Result.SemanticInterpretation.Properties.TryGetValue(" menu",out phrase)))
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Frame rootFrame = Window.Current.Content as Frame;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; switch(phrase.First()。ToLower())

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案件"场地":

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Dispatcher.RunAsync(CoreDispatcherPriority.Normal,

              ()=> this .Frame.Navigate(typeof(venue)));



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例"会话":

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Dispatcher.RunAsync(CoreDispatcherPriority.Normal,

              ()=> this .Frame.Navigate(typeof(sessions)));

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案件"发言者":

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Dispatcher.RunAsync(CoreDispatcherPriority.Normal,

              ()=> this .Frame.Navigate(typeof(speaker)));

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;默认值:

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; this.Frame.Navigate(typeof(MainPage));

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;否则

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; InstallVoiceCommands();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; public async void InstallVoiceCommands()

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(" ms-appx:///speech.xml&quot ;,UriKind.Absolute));

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;试试
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;等待VoiceCommandManager.InstallCommandSetsFromStorageFileAsync(file);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; catch(例外情况)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;新的MessageDialog("错误:" + ex.HResult +" \ n\ n"" + ex.Message);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; }

   protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var args = e.Parameter as VoiceCommandActivatedEventArgs;
            if(args != null)
            {
                IReadOnlyList<string> phrases;
                if (args.Result.SemanticInterpretation.Properties.TryGetValue("menu", out phrases))
                {
                    Frame rootFrame = Window.Current.Content as Frame;
                    switch (phrases.First().ToLower())
                    {
                        case "venue":
                            Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                            () => this.Frame.Navigate(typeof(venue)));

                            break;

                        case "sessions":
                            Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                            () => this.Frame.Navigate(typeof(sessions)));
                            break;

                        case "speakers":
                            Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                            () => this.Frame.Navigate(typeof(speakers)));
                            break;

                        default:
                            this.Frame.Navigate(typeof(MainPage));
                            break;
                    }
                }
            }
            else
            {
                InstallVoiceCommands();
            }
        }

        public async void InstallVoiceCommands()
        {
            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///speech.xml", UriKind.Absolute));
            try
            {
                await VoiceCommandManager.InstallCommandSetsFromStorageFileAsync(file);
            }
            catch(Exception ex)
            {
                new MessageDialog("Error:" + ex.HResult + "\n\n" + ex.Message);
            }
        }

-------------------------------------- -------------------------------------------------- --------

------------------------------------------------------------------------------------------------

On  app.xaml.cs的激活功能

On Activated function of  app.xaml.cs

请尝试在实际设备上运行它,因为有些地方需要测试实际设备。

Please try run it on the actual device cause there are some places where you need an actual device to test.

Muhammad Asad

Muhammad Asad