Voice Commands
Provides a service where we can register key words, that the speech recognition service will detect and we can take actions when this happens. It is based on MRTK, so you should work with SpeechHandler if you want to create handlers for your custom controls. If you are only interested in buttons and toggle buttons, you can make use of PressableButtonSpeechHandler defined in MRTK, or ToggleButtonSpeechHandler defined in XRV, to activate a button if associated voice command is recognized.
Note
Current implementation supports voice commands for HoloLens 2 (UWP) only. Speech recognition service must be enabled or command recognition will never be fired. Please, note that you should add an explicit reference to Evergine.Xrv.Core NuGet package for your UWP Mixed Reality project. This is necessary in order to take correct implementation of speech service for UWP platform.
User can also activate or deactivate voice command recognition in Configuration -> General section.
Associate voice commands programmatically
You have two options to add custom voice commands:
- Specify voice commands in menu button description for module definition.
public MyModule : Module
{
private const string VoiceCommandShow = "Show feature";
private const string VoiceCommandHide = "Hide feature";
public override IEnumerable<string> VoiceCommands => new[] { VoiceCommandShow, VoiceCommandHide };
public override void Initialize(Scene scene)
{
this.HandMenuButton = new MenuButtonDescription()
{
VoiceCommandOff = VoiceCommandShow,
VoiceCommandOn = VoiceCommandHide,
};
}
}
- Using Voice System API to programmatically register voice commands. Please, note that this should only be invoked on application startup.
var voiceSystem = this.xrvService.VoiceSystem;
voiceSystem.RegisterCommands(new [] { "one command", "other command" });
Create custom speech handler
public MySpeechRecognizer : SpeechHandler
{
protected override void InternalOnSpeechKeywordRecognized(string keyword)
{
base.InternalOnSpeechKeywordRecognized(keyword);
// Do something depending on matching command
}
}