Cortana app creation in English is not working

Asked

Viewed 196 times

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 the Port for my code, it only opens the browser, as if the app had not registered the command.

  • To facilitate help post the corresponding code snippet and explain exactly what you are trying to do.

  • 1

    Ready, Done :)

1 answer

4


At first I don’t know where you registered the xml with the command settings for recognition, but if OnActivated although the name is not executed when the application is 'enabled'

The procedure to register the voice command I put in the method OnLaunched as far as below:

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 archive xmlI made some changes, see how it turned out:

<?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 tested in the mode debug and release the command to call the cut and the results:

Voice command: Hey Cortana, application say hello

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

All that’s missing is an adjustment in comparison to case "testando oi aplicativo":

Browser other questions tagged

You are not signed in. Login or sign up in order to post.