【问题标题】:How to implement cross-platform SRGs grammar from .NET to UWP如何实现从.NET到UWP的跨平台SRGs语法
【发布时间】: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


    【解决方案1】:

    如果您想要StorageFile,您可以在某个文件夹中创建一个,然后将所有 XML 数据写入其中,如下所示:

    XmlDocument xmlDocument = ...;
    StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("filename.xml");
    await FileIO.WriteTextAsync(file, xmlDocument.ToString());
    

    【讨论】:

      猜你喜欢
      • 2021-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2018-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多