Created
November 26, 2021 09:36
-
-
Save kungfoo/86a908a353705099e13d95378698bfc7 to your computer and use it in GitHub Desktop.
Simplified Falcon BMS Speech Recognition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Speech.Recognition; | |
namespace SpeechRecognitionApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers()) | |
{ | |
Console.WriteLine("Installed recognizer: " + ri.Description); | |
} | |
using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"))) | |
{ | |
recognizer.LoadGrammar(CreateTowerGrammar()); | |
recognizer.LoadGrammar(CreateTankerGrammar()); | |
recognizer.SpeechRecognized += | |
new EventHandler<SpeechRecognizedEventArgs>(CommandRecognized); | |
recognizer.SetInputToDefaultAudioDevice(); | |
recognizer.RecognizeAsync(RecognizeMode.Multiple); | |
while (true) | |
{ | |
Console.ReadLine(); | |
} | |
} | |
} | |
static Grammar CreateTowerGrammar() | |
{ | |
GrammarBuilder towerElement = new GrammarBuilder(new Choices(new string[] { "tower", "approach" })); | |
GrammarBuilder requestLandingPhrase = new GrammarBuilder(); | |
requestLandingPhrase.Append(towerElement); | |
requestLandingPhrase.Append(new GrammarBuilder(new Choices(new string[] { "request", "request permission" }))); | |
requestLandingPhrase.Append(new GrammarBuilder(new Choices(new string[] { "land", "landing", "to land" }))); | |
Choices bothChoices = new Choices(new GrammarBuilder[] { requestLandingPhrase }); | |
Grammar grammar = new Grammar(bothChoices) | |
{ | |
Name = "Tower Grammar" | |
}; | |
return grammar; | |
} | |
static Grammar CreateTankerGrammar() | |
{ | |
GrammarBuilder tankerElement = new GrammarBuilder(new Choices(new string[] { "tanker", "texaco", "copper" })); | |
GrammarBuilder requestRefuelPhrase = new GrammarBuilder(); | |
requestRefuelPhrase.Append(tankerElement); | |
requestRefuelPhrase.Append("request"); | |
requestRefuelPhrase.Append(new GrammarBuilder(new Choices(new string[] { "refuel", "refueling" }))); | |
GrammarBuilder preContactPhrase = new GrammarBuilder(); | |
preContactPhrase.Append(tankerElement); | |
preContactPhrase.Append("ready"); | |
preContactPhrase.Append(new GrammarBuilder(new Choices(new string[] { "pre-contact", "contact" }))); | |
GrammarBuilder doneRefueling = new GrammarBuilder(); | |
doneRefueling.Append(tankerElement); | |
doneRefueling.Append("done"); | |
doneRefueling.Append(new GrammarBuilder(new Choices(new string[] { "refuel", "refueling" }))); | |
Choices choices = new Choices(new GrammarBuilder[] { requestRefuelPhrase, preContactPhrase, doneRefueling }); | |
Grammar grammar = new Grammar(choices) | |
{ | |
Name = "Tanker Grammar" | |
}; | |
return grammar; | |
} | |
static void CommandRecognized(object sender, SpeechRecognizedEventArgs e) | |
{ | |
Console.WriteLine(e.Result.Grammar.Name + ": " + e.Result.Text); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Installed recognizer: Microsoft Speech Recognizer 8.0 for Windows (English - US) | |
Installed recognizer: Microsoft Speech Recognizer 8.0 for Windows (English - UK) | |
Tanker Grammar: texaco request refueling | |
Tanker Grammar: texaco ready pre-contact | |
Tanker Grammar: texaco done refueling | |
Tower Grammar: approach request permission to land |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment