I've been playing quakelive.com and have been getting frustrated by my keyboard bindings and want to bind using voice commands instead.
I thought I'd create a c# console app to run in the background and use the inbuilt speech recognition engine of SAPI for windows 7 64 bit to do all the heavy speech stuff. My program would listen for SpeechRecognized events and respond accordingly. However I'm not sure how to run my console app in the background in-conjuction with ms speech recognition whilst I'm playing the game?
This is what I have written so far:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Speech.Recognition;
using System.Text;
using System.Threading.Tasks;
using AutoItX3Lib;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AutoItX3 autoit = new AutoItX3();
// Create a default dictation grammar.
DictationGrammar defaultDictationGrammar = new DictationGrammar();
defaultDictationGrammar.Name = "default dictation";
defaultDictationGrammar.Enabled = true;
// Create our process
autoit.Run("notepad.exe", "", autoit.SW_MAXIMIZE);
autoit.WinWaitActive("Unbenannt - Editor");
Console.WriteLine("its active");
SpeechRecognizer sr = new SpeechRecognizer();
sr.SpeechRecognized += (s, e) =>
{
foreach (RecognizedWordUnit word in e.Result.Words)
{
Console.WriteLine(word.Text);
if (word.Text.Trim().ToLower() == "one")
autoit.Send(word.Text.ToLower() + "{LCTRL}+{LSHIFT}+a", 0);
else
autoit.Send(word.Text.ToLower() + " ", 0);
}
};
sr.LoadGrammar(defaultDictationGrammar);
}
}
}
Basically I'd like ms speech recognition to be running while my game is running and for my console app to listen for specific words I say. As you can see in my example code, I am listening for the phrase "one" to which I send to notepad using autoIt the text as well as some control characters to select all the text when it's been written.
So far it's not working. It seems like my console app has to have "focus" or be the foreground app and even then when I say words like "one" or "two" ms speech recognition tries to do "console comand" stuff with my app rather than just pass dictation text to it. For example when I say the word "one" it keeps saying "moving" because I think it thinks that console aren't documents so it must be a command and not a dictation.
Can anyone see what I am doing wrong and how to get this working as I want?
The final solution was to send control characters to the running "chrome.exe" process rather than "notepad" because quakelive is run in the browser. So I presume sending keyboard commands via autoIt would be enough for the chrome process to then pass those onto the quakelive plugin as game keyboard game inputs (i.e. keyboard input/keystrokes).
Anyone with any help or advice appreciated.