Creation of Cortana app in Portuguese is not working

2

First I created the following xml:

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

<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
  <CommandSet xml:lang="pt-BR" Name="CommandSet_pt-BR">
    <AppName> App2 </AppName>
    <Example> Esse e um exemplo </Example>

    <Command Name="Dando Oi">
      <Example> testando Oi Aplicativo </Example>
      <ListenFor> testando oi aplicativo </ListenFor>
      <Feedback> Ok, vou te dar um ola</Feedback>
      <Navigate />
    </Command>


  </CommandSet>
</VoiceCommands>

After this creation, I went to register the command in App.xaml.cs, with the following code:

 try
            {
                StorageFile vcd = await Package.Current.InstalledLocation.GetFileAsync(@"teste.xml");
                await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcd);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

Together:

    protected async override void OnActivated(IActivatedEventArgs args)
    {

        base.OnActivated(args);


        if(args.Kind ==  ActivationKind.VoiceCommand)
        {
            VoiceCommandActivatedEventArgs cmd = args as VoiceCommandActivatedEventArgs;
            SpeechRecognitionResult result = cmd.Result;


            string commander = result.RulePath[0];

            MessageDialog dialog = new MessageDialog("");

            switch(commander)
            {
                case "testando oi aplicativo":
                    dialog.Content = "Funcionou";
                    break;

                default:
                    break;

            }

           await dialog.ShowAsync();
        }
    }

Finally, I ran in Release mode. When I test it for my code, it just opens the browser, as if the app had not registered the command.

    
asked by anonymous 04.09.2016 / 06:24

1 answer

4

At first I do not know where you registered xml with the settings of the commands for recognition, but if it was in OnActivated although the name does not run when the application is 'enabled'

The procedure to register the voice command I placed in the OnLaunched method as follows:

protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
    try
    {
        var vcd = await Package.Current.InstalledLocation.GetFileAsync(@"teste.xml");
        await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcd);
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
    }
    ...

In the file xml I made some changes, see how it was:

<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
  <CommandSet xml:lang="pt-BR" Name="CommandSet_pt-BR">
    <CommandPrefix> Aplicativo, </CommandPrefix>
    <Example> Dizendo olá </Example>
    <Command Name="Dando Oi">
      <Example> diga olá </Example>
      <ListenFor> diga olá </ListenFor>
      <Feedback> Ok, vou te dar um ola</Feedback>
      <Navigate/>
    </Command>

  </CommandSet>
</VoiceCommands>
  

Method OnActivated

protected override async void OnActivated(IActivatedEventArgs e)
{

    if (e.Kind != ActivationKind.VoiceCommand) return;
    var cmd = e as VoiceCommandActivatedEventArgs;
    var result = cmd?.Result;


    var commander = result?.RulePath[0];

    var dialog = new MessageDialog("");

    switch (commander)
    {
        case "testando oi aplicativo":
            dialog.Content = "Funcionou";
            break;
    }

    await dialog.ShowAsync();
    Debug.WriteLine("teste");
}

I tried in the debug and release mode the command to call the cut and the results:

  

Voice command: Hey Corta, application say hello

Onlyonesettingismissingcomparedtocase"testando oi aplicativo":

    
08.09.2016 / 03:02