应用程序内部语音控制的语音识别

时间:2018-07-12 18:02:46

标签: java c# wpf speech-recognition voice-recognition

我知道这方面有很多话题,但我仍在努力找出2018年现在的最佳选择。

  • 在c#WPF应用程序中是否存在一种内置的方法来集成语音控制?
  • 最好的解决方案是什么(免费或付费)?

我只需要开始做一些事情,并确保我朝着正确的方向前进。 (因为许多线程和信息不是最近的)

谢谢。

米歇尔

1 个答案:

答案 0 :(得分:0)

https://docs.microsoft.com/en-us/previous-versions/office/developer/speech-technologies/hh361683(v=office.14)

复制粘贴代码,从winform转换为WPF,然后就可以了。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;

namespace WindowsFormsApplication1
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

      // Create a new SpeechRecognitionEngine instance.
      SpeechRecognizer recognizer = new SpeechRecognizer();

      // Create a simple grammar that recognizes "red", "green", or "blue".
      Choices colors = new Choices();
      colors.Add(new string[] { "red", "green", "blue" });

      // Create a GrammarBuilder object and append the Choices object.
      GrammarBuilder gb = new GrammarBuilder();
      gb.Append(colors);

      // Create the Grammar instance and load it into the speech recognition engine.
      Grammar g = new Grammar(gb);
      recognizer.LoadGrammar(g);

      // Register a handler for the SpeechRecognized event.
      recognizer.SpeechRecognized +=
        new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
    }

    // Create a simple handler for the SpeechRecognized event.
    void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
      MessageBox.Show("Speech recognized: " + e.Result.Text);
    }
  }
}