简体   繁体   English

Windows 10语音识别

[英]Windows 10 Speech Recognition

I want to create a WPF application in c# for windows 10. Now, the problem that i had with previous windows versions was that i'm italian and there isn't a support for speech recognition in italian. 我想在c#中为Windows 10创建一个WPF应用程序。现在,我之前的Windows版本的问题是我是意大利语,而且意大利语中没有语音识别支持。 But now there is cortana. 但现在有了神经。 So, how can i use cortana's speech recognition engine for my application? 那么,我如何在我的应用程序中使用cortana的语音识别引擎? If i simply use new SpeechRecognitionEngine(new CultureInfo("it-IT"))); 如果我只是使用new SpeechRecognitionEngine(new CultureInfo("it-IT"))); it gives me an error, 'cause there isn't the simple recongition engine, so i have to use cortana's one. 它给了我一个错误,因为没有简单的recongition引擎,所以我必须使用cortana的一个。 Hope you understood and sorry for my bad english. 希望你理解并抱歉我的英语不好。 Thank you for your answer. 谢谢您的回答。

In order to use the new SpeechRecognition WinRT API released in windows 10, you're going to need to add support for WinRT APIs to your desktop C# application. 为了使用Windows 10中发布的新的SpeechRecognition WinRT API,您需要在桌面C#应用程序中添加对WinRT API的支持。 This doesn't require converting the app to a Windows Store app, however, at least, for some parts. 这不需要将应用程序转换为Windows应用商店应用,但至少对于某些部分而言。 So far as I know, the new engine hasn't been backported to add support into System.Speech.SpeechRecognitionEngine, that still uses a legacy recognizer (I'll check with the speech team here and follow up in this post if I find more on that point.) 据我所知,新的引擎还没有被移植到System.Speech.SpeechRecognitionEngine,它仍然使用传统的识别器(我会在这里与语音团队核实,如果我发现更多,请在这篇文章中跟进)在那一点上。)

Based on the guidance taken from here and here , I was able to create a classic c# WPF app, and implement the following code: 基于此处此处的指导,我能够创建一个经典的c#WPF应用程序,并实现以下代码:

private SpeechRecognizer reco;

    public MainWindow()
    {
        InitializeComponent();

        reco = new SpeechRecognizer();
        List<string> constraints = new List<string>();
        constraints.Add("Yes");
        constraints.Add("No");
        reco.Constraints.Add(new SpeechRecognitionListConstraint(constraints));
        IAsyncOperation<SpeechRecognitionCompilationResult> op = reco.CompileConstraintsAsync();
        op.Completed += HandleCompilationCompleted;
    }

    public void HandleCompilationCompleted(IAsyncOperation<SpeechRecognitionCompilationResult> opInfo, AsyncStatus status)
    {
        if(status == AsyncStatus.Completed)
        {
            System.Diagnostics.Debug.WriteLine("CompilationCompleted");
            var result = opInfo.GetResults();
            System.Diagnostics.Debug.WriteLine(result.Status.ToString());
        }
    }

In order to get this to compile, I added 为了得到这个,我补充道

  <PropertyGroup>
    <TargetPlatformVersion>10.0</TargetPlatformVersion>
  </PropertyGroup>

to the .csproj, and added Windows.Media and Windows.Foundation from the Project -> Add References -> Universal Windows -> Core section, and I also manually added references to 到.csproj,并从Project - > Add References - > Universal Windows - > Core部分添加了Windows.Media和Windows.Foundation,我还手动添加了对

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5.1\System.Runtime.WindowsRuntime.dll

and

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5.1\System.Runtime.InteropServices.WindowsRuntime.dll

via the browse section of Add References. 通过添加引用的浏览部分。

You'll need to check the SpeechRecognizer.SupportedGrammarLanguages to retrieve the it-IT Language object to pass it to the Recognizer constructor, if your system isn't defaulting to it-IT already. 您需要检查SpeechRecognizer.SupportedGrammarLanguages以检索it-IT语言对象,以便将其传递给Recognizer构造函数,如果您的系统不是默认的IT-IT。 (IF you installed an Italian version of windows 10, this should happen by default) (如果您安装了意大利语版本的Windows 10,则默认情况下会发生这种情况)

Now, my code snippet above only compiles a super simple grammar, it doesn't start recognition. 现在,我上面的代码片段只编译一个超级简单的语法,它不会开始识别。 You'll need to consult the rest of the Windows.Media.SpeechRecognition API for that, but it's along the same lines. 您需要查阅Windows.Media.SpeechRecognition API的其余部分,但它也是一样的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM