Voice Commands
This service allows us to register keywords that the speech recognition service will detect, enabling us to take actions when this occurs. 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 use PressableButtonSpeechHandler defined in MRTK or ToggleButtonSpeechHandler defined in XRV to activate a button when the associated voice command is recognized.
Note
The current implementation supports voice commands for HoloLens 2 (UWP) only. The speech recognition service must be enabled, or command recognition will not occur. Please note that you should add an explicit reference to the Evergine.Xrv.Core NuGet package for your UWP Mixed Reality project. This is necessary to ensure the correct implementation of the speech service for the UWP platform.
Users can also activate or deactivate voice command recognition in the Configuration -> General section.
Associate Voice Commands Programmatically
You have two options to add custom voice commands:
- Specify voice commands in the 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,
};
}
}
- Use the Voice System API to programmatically register voice commands. Please note that this should only be invoked at application startup.
var voiceSystem = this.xrvService.VoiceSystem;
voiceSystem.RegisterCommands(new[] { "one command", "other command" });
Create a Custom Speech Handler
public MySpeechRecognizer : SpeechHandler
{
protected override void InternalOnSpeechKeywordRecognized(string keyword)
{
base.InternalOnSpeechKeywordRecognized(keyword);
// Perform an action depending on the matching command
}
}