Note that there are some explanatory texts on larger screens.

plurals
  1. POVoice recognition in c#
    primarykey
    data
    text
    <p>Been attempting to do a simple voice recognition form in C# but am facing problems. Quite new to this so please help!</p> <p>Facing 2 errors: 1st error is: "[ expected" 2nd error is: Invalid token ';' in class, struct, or interface member declaration </p> <p>Below is my code:</p> <pre><code>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; using System.Text.RegularExpressions; using System.Diagnostics; namespace Speech { public class Grammar; public partial class Form1 : Form { private SpeechRecognitionEngine recognitionEngine; public Form1() { InitializeComponent(); recognitionEngine = new SpeechRecognitionEngine(); recognitionEngine.SetInputToDefaultAudioDevice(); recognitionEngine.SpeechRecognized += (s, args) =&gt; { string line = ""; foreach (RecognizedWordUnit word in args.Result.Words) { if (word.Confidence &gt; 0.8f) line += word.Text + " "; } string command = Regex.Replace(line, "Start", "").Trim(); switch (command) { case "Notepad": Process.Start("notepad.exe"); break; case "Calculator": Process.Start("calc.exe"); break; case "Paint": Process.Start("mspaint.exe"); break; } txtOutput.Text += line; txtOutput.Text += Environment.NewLine; }; recognitionEngine.LoadGrammar(CreateGrammarObject()); } private void button_start_Click(object sender, EventArgs e) { recognitionEngine.RecognizeAsync(RecognizeMode.Multiple); } private void button_stop_Click(object sender, EventArgs e) { recognitionEngine.RecognizeAsyncStop(); } } private Grammar CreateGrammarObject() { Choices commandChoices = new Choices("Calculator", "Notepad", "Internet Explorer", "Paint"); GrammarBuilder grammarBuilder = new GrammarBuilder("Start"); grammarBuilder.Append(commandChoices); Grammar g = new Grammar(grammarBuilder); return g; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload