-2

I know there is a lot of thread on this but I'm still trying to figure out what is the best option now in 2018.

  • Is there a kind of built-in method to integration voice control inside my c# WPF application?
  • What is the best solution (free or paid) ?

I just need something to start with and make sure I'm going to the right direction. (since many thread and infos are not recent)

Thanks.

Michel

michelqa
  • 137
  • 1
  • 2
  • 14

1 Answers1

0

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

Copy paste code, convert from winform to WPF and there you go.

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);
    }
  }
}
Paul Swetz
  • 2,234
  • 1
  • 11
  • 28
  • I'ld suggest to call `recognizer.RequestRecognizerUpdate();` before loading the Grammar and then, of course, `recognizer.SetInputToDefaultAudioDevice(); recognizer.RecognizeAsync(RecognizeMode.Multiple);`, after you have registered the `SpeechRecognized` event. – Jimi Jul 12 '18 at 18:12
  • Thanks It works....for some reasons the word "red" is not working at all. So you confirm it is the best voice recognition available for a WPF application ? – michelqa Jul 12 '18 at 18:32
  • Best for something like this is subjective. For all we know you have an accent ;-) Given its a MS framework and you are writing code using MS technology Ill just go with "easiest to use". Also I you can train the engine for better recognition, none of them will be very good right out of the box. – Paul Swetz Jul 12 '18 at 18:57
  • Any idea now for a java (non MS) solution? I'd like to evaluate and try both solutions. Thanks – michelqa Jul 13 '18 at 01:34