【发布时间】:2019-01-17 23:44:38
【问题描述】:
我有两个相互远程通信的应用程序。一个应用程序(称为“A”)需要为在远程 UWP 应用程序(称为该应用程序“B”)中运行的语音识别引擎定义一些自定义语法。我想使用一个自定义类来封装语法规则以及其他一些辅助数据,并且由于这个类必须在完整的 .NET 框架(4.7)和 UWP 框架之间交叉,我正在考虑将它实现到 .NET 中两个应用程序都引用的标准 2.0 类库。至于语法,最好的方法似乎是将 SRGS 约束指定为 XML (https://docs.microsoft.com/en-us/windows/uwp/design/input/define-custom-recognition-constraints),因为应用程序 A 和 B 都可以创建 Xml。我预计 Xml 要么以编程方式创建,要么从文件加载。封装的自定义语法对象将在应用程序 A 上创建,然后传输到应用程序 B,通常看起来像这样:
public class MyCustomGrammarStuff()
{
public Int32 Data1 { get; set; }
public Int32 Data2 { get; set; }
public String Stuff { get; set; }
public XmlDocument GrammarRules {get; set; } // Loaded from file or created in code.
}
当应用程序 A 收到此对象时,它必须使用“MyCustomGrammarStuff”对象中的“GrammarRules”实例化一个“SpeechRecognitionGrammarFileConstraint”对象。根据此类 (https://docs.microsoft.com/en-us/uwp/api/Windows.Media.SpeechRecognition.SpeechRecognitionGrammarFileConstraint) 的文档,构造函数采用“Windows.Storage.StorageFile”类型的参数。
我的问题是如何获取 XmlDocument 对象并使用它以编程方式实例化 StorageFile 对象?我不想开始做一些事情,比如从临时文件写入/加载。
【问题讨论】:
标签: uwp linq-to-xml speech-recognition xmldocument speech