So I found this program for C# online and started heavily modifying the commands and functions. Side note I only started coding C# because of this program so I am fairly new. I originally had it setup so that you click a mic button and the speech recognition engine started recognizing, but now I want to be able to say a simple voice command, in this case, I would say "Athena" and the engine would start recognising my command, but it's not working at all and I have no idea why.
private void loadGrammarAndCommands()
{
try
{
Choices texts = new Choices();
texts.Add("athena");
string[] lines = File.ReadAllLines(Environment.CurrentDirectory + "\\commands.txt");
foreach (string line in lines)
{
if (line.StartsWith("--") || line == String.Empty) continue;
var parts = line.Split(new char[] { '|' });
words.Add(new Word() { Text = parts[0], AttachedText = parts[1], IsShellCommand = (parts[2] == "true") });
texts.Add(parts[0]);
}
Grammar wordsList = new Grammar(new GrammarBuilder(texts));
speechRecognitionEngine.LoadGrammar(wordsList);
DictationGrammar dict = new DictationGrammar();
speechRecognitionEngine.LoadGrammar(dict);
}
catch (Exception ex)
{
throw ex;
}
}
private string getKnownTextOrExecute(string command)
{
InitializeComponent();
if (!command.StartsWith("athena "))
return "";
else
speechSynthesizer.SpeakAsync("Yes?");
command = command.Replace("athena ", "");
try
{
var cmd = words.Where(c => c.Text == command).First();
if (cmd.IsShellCommand)
{
At this point, I have it so that if it recognizes me saying "Athena" it starts accepting commands, at the moment it says yes but in the future I want it to make a sound (Already know how to) I have the word "Athena" pre built into its vocabulary.