在我的情况下,按钮是在运行时创建的。这些将通过语音命令单击。因此,我尝试找出如何在运行时添加语音命令。但我找不到任何方法。
我尝试过的事情:我用两种方法IMixedRealitySpeechSystem
和RefreshRecognition
扩展了接口AddSpeechCommand
:
/// <summary>
/// Refresh recognition after adding new commands
/// </summary>
void RefreshRecognition();
/// <summary>
/// Add command to already existing commands[]
/// </summary>
/// <param name="command"></param>
void AddSpeechCommand(SpeechCommands command);
我已经在WindowsSpeechInputProvider: MixedRealitySpeechSystem
类中实现了这些。但是有两个问题。
First:我无法进入WindowsSpeechInputProvider。我以为我可以尝试一下:
private IMixedRealitySpeechSystem SpeechSystem
{
get
{
if(_speechSystem is null)
{
MixedRealityServiceRegistry.TryGetService(out _speechSystem);
}
return _speechSystem;
}
}
public void SomeMethod()
{
SpeechCommands command = new SpeechCommands("TestCommand", default, default, null);
SpeechSystem.AddSpeechCommand(command);
SpeechSystem.RefreshRecognition();
}
但是问题是MixedRealityServiceRegistry
不包含该服务的实例,或者确切地说,它甚至都不是服务。
第二:即使这可行,也不是一个好方法。因为我更改了MRTK,并且又升级到了新版本,所以这些行被覆盖。
我的问题:那么如何在运行时访问和添加命令?
我发现了问题。我忽略了这些行,却没有意识到选择了.jpeg作为格式:
public void FromData(Bitmap bitmap)
{
using (var ms = new MemoryStream())
{
bitmap.Save(ms, ImageFormat.Jpeg);
//...