Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VoiceCommand trigger added to Microsoft.Toolkit.Uwp.UI.Behaviors (#3392) #3661

Draft
wants to merge 9 commits into
base: dev/new-animations
Choose a base branch
from

Conversation

sonnemaf
Copy link
Contributor

@sonnemaf sonnemaf commented Jan 7, 2021

Fixes #3392

This PR implements Issue #3392

PR Type

What kind of change does this PR introduce?

  • Feature
  • Sample app changes

What is the new behavior?

A VoiceCommand triggers an Action using a SpeechRecognizer.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

The XML Comments are not written yet. This PR is there for retrieving initial feedback.

@ghost
Copy link

ghost commented Jan 7, 2021

Thanks sonnemaf for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@sonnemaf
Copy link
Contributor Author

sonnemaf commented Jan 7, 2021

Forgot to add the screenshot from the SampleApp. You can test it using the 'Add', 'Delete', 'Append', 'Move Available/Selected Up/Down/To First/To Last', 'What can I say' speech commands.

image

@ghost ghost added the in progress 🚧 label Jan 7, 2021
@Kyaa-dost Kyaa-dost added this to the 7.0 milestone Jan 7, 2021
@sonnemaf
Copy link
Contributor Author

I have added an IsEnabled property on the VoiceCommand trigger. In the SamplePage I have added a ToggleSwitch 'Voice'. If it is Off the buttons and listbox commands are not working. See:
#3392 (comment)

}
}

public string Text

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to turn this into a list for better maintainability / readability?

So instead of:
<Behaviors:VoiceCommandTrigger Text="Move available to First|Move available too First">

something like:
Behaviors:VoiceCommandTrigger
Behaviors:VoiceCommandTrigger.Commands


</Behaviors:VoiceCommandTrigger.Commands>
</Behaviors:VoiceCommandTrigger>

I have to say that's way more verbose, which isn't great at all.. but might be easier to append a string/voice command to a list programmatically instead of re-formatting a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have thought about this too. I decided not to implement this. It would make localization much harder. With my | (pipe) separator you can easily add or remove alternatives for different languages. This will be very hard if you use a Commands collection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still have the type be a list and use a custom converter to parse the text and split it?

https://timheuer.com/blog/implement-type-converter-uwp-winrt-windows-10-xaml

Would it also make sense to make the delimiter a property that can be overridden? Comma by default seems like a better choice?

SpeechRecognizer sr = null;
foreach (var item in Windows.System.UserProfile.GlobalizationPreferences.Languages)
{
var language = new Language(item);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the language be set-able in the voice command as well (for multi-language use cases) and by default use this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think Language should be a property on the VoiceCommandTrigger. Would love to know what others think though. It's all new for me too.

@Kyaa-dost
Copy link
Contributor

@sonnemaf seems like the app is breaking when I attempt to open it or try to select the Add button in the app.

Attached is the screen-recording.

YZ7e6k5

@sonnemaf
Copy link
Contributor Author

@sonnemaf seems like the app is breaking when I attempt to open it or try to select the Add button in the app.

You are right. The app crashed when you didn't allow the use of the Microphone in this app.

image

I have now fixed this with a new push.

To test the app you can give it permissions to the microphone in the Settings of your computer. Search the App in the 'Apps & Features'.

image

Click on the 'Advanced options' hyperlink. Turn the Microphone toggle switch ON.

image

@michael-hawker
Copy link
Member

Sorry about the build break, we had an issue with a stale config item. I've updated the base branches with the fix, so hopefully this will build again now and be easier for folks to test via NuGet?

@Kyaa-dost
Copy link
Contributor

@sonnemaf tried various times but seems like it keeps breaking the moment I select VoiceCommand in the sample app. Before this update, it would still land to the page allowing me to Add items but now it just crashes directly with the same exception message.

Can you try on your end and see if you are able to repro?

@michael-hawker
Copy link
Member

@sonnemaf can you also ensure you've added the required headers and fixed any StyleCop issues (if any) so that the CI can pass?

@sonnemaf
Copy link
Contributor Author

@michael-hawker I have just pushed a new version with Xml comments and fixed StyleCop issues. I hope (expect) it will now pass.

@@ -0,0 +1,95 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing the headers on the files here, so CI is still failing. You can run the UpdateHeaders command in the build directory to help, though if it somehow touches more files beyond yours, don't commit those.

The build script in the build directory can also do a local test build as if it were in the CI, so that can help to validate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Headers updated. I forgot that I had to do this. I'm a bit rusty, sorry.

@michael-hawker
Copy link
Member

@sonnemaf looks like you provided a '.bind' file for an interactive sample, but then it doesn't actually work because you have x:Class and x:Bind. It's alright not to provide live XAML sample if you don't think there's value in folks modifying the sample (and just showing a demo), but then we shouldn't provide that file in the samples.json. Can you confirm your intent?

If we need to make the sample guidance clearer in any regard, let us know by opening an issue on the wiki repo. Thanks!

It might be good to have a prompt text at the top of the sample to get folks started. I didn't see the microphone prompt pop-up though for me, so I don't think it's working? Is this going to be a problem for folks upgrading apps?

@michael-hawker
Copy link
Member

Is there an API we can use to detect if we have Microphone access so we can help display/troubleshoot?

Also, I just noticed this branch has the same name as the head vs. for the specific feature so it makes it a bit harder to manage. Don't think it'll cause problems, but not sure?

@sonnemaf
Copy link
Contributor Author

@sonnemaf looks like you provided a '.bind' file for an interactive sample, but then it doesn't actually work because you have x:Class and x:Bind. It's alright not to provide live XAML sample if you don't think there's value in folks modifying the sample (and just showing a demo), but then we shouldn't provide that file in the samples.json. Can you confirm your intent?

If we need to make the sample guidance clearer in any regard, let us know by opening an issue on the wiki repo. Thanks!

It might be good to have a prompt text at the top of the sample to get folks started. I didn't see the microphone prompt pop-up though for me, so I don't think it's working? Is this going to be a problem for folks upgrading apps?

I have removed the two .bind files.

I have added a 'What can I say' button to the sample page. It will show you which commands you can speak.

image

@Kyaa-dost
Copy link
Contributor

@sonnemaf I am still not able to see this pop-up and checked everything on my end 🤔

image

@sonnemaf
Copy link
Contributor Author

@Kyaa-dost did you restart the app after turning the setting off?

@sonnemaf sonnemaf closed this Jan 29, 2021
@sonnemaf sonnemaf reopened this Jan 29, 2021
@sonnemaf
Copy link
Contributor Author

Sorry I accidentally hit the 'Close with comment' button. Have reopened it again.

@Kyaa-dost
Copy link
Contributor

@sonnemaf Correct I have tried restarting multiple times but not seeing that at all.

@sonnemaf
Copy link
Contributor Author

sonnemaf commented Feb 1, 2021

@Kyaa-dost I had the same result. It works if you manually uninstall the app. If you then deploy a new version you will get the MessageBox again.

image

@Kyaa-dost
Copy link
Contributor

@sonnemaf I have tried that multiple times in different ways and not seeing at all☹

I will wait for @michael-hawker to confirm and see if he is able to see this popup screen now.

@sonnemaf
Copy link
Contributor Author

sonnemaf commented Feb 2, 2021

@Kyaa-dost Maybe you can try as a last resort a Reset in the settings. Find the apps in Apps & features settings, and click the `Advanced options' hyperlink. There you can find the Reset button if you scroll a bit down. I hope it works. I could test it though. I got this error.

image

@Rosuavio
Copy link
Contributor

Rosuavio commented Feb 4, 2021

I am also not seeing anything requesting the microphone, tried resting, uninstalling. Nothing worked.

@Kyaa-dost
Copy link
Contributor

@sonnemaf I am getting the same error on the Reset button as well. I am not certain what is causing the issue and perhaps something will need more time to investigate 🤔

@sonnemaf
Copy link
Contributor Author

sonnemaf commented Feb 8, 2021

@RosarioPulella, @Kyaa-dost Can you verify if the Microphone capability is turned on in the Package.appxmanifest?

image

@Kyaa-dost
Copy link
Contributor

@sonnemaf Correct it's turned on

image

@Rosuavio
Copy link
Contributor

Rosuavio commented Feb 8, 2021

The option is also enabled for me too.

@Kyaa-dost Kyaa-dost linked an issue Feb 9, 2021 that may be closed by this pull request
@michael-hawker michael-hawker modified the milestones: 7.0, 7.1 Feb 16, 2021
@michael-hawker
Copy link
Member

Moving this to 7.1 for now since we can't understand why the proper permissions aren't being prompted for. There's something very odd going on as we can't even get the proper prompt on a fresh machine for us...

@michael-hawker michael-hawker mentioned this pull request May 25, 2021
27 tasks
@michael-hawker michael-hawker marked this pull request as draft August 10, 2021 16:50
@michael-hawker michael-hawker added the labs 🧪 Marks an issue/PR involved with Toolkit Labs label Aug 31, 2021
@michael-hawker michael-hawker modified the milestones: 7.1, 7.2/8.0? Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VoiceCommand support using SpeechRecognizer
5 participants