Last active
October 21, 2016 10:02
-
-
Save JPVenson/48cf2c9518b0ac5de7a20114ed51a333 to your computer and use it in GitHub Desktop.
This file contains 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.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Speech.Recognition; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace VoiceDetector | |
{ | |
public class Program | |
{ | |
public static string[] Curses = {"bitch", "son of a", "motherfucker"}; | |
static void Main(string[] args) | |
{ | |
var sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")); | |
sre.SetInputToDefaultAudioDevice(); | |
sre.RecognizeCompleted += Sre_RecognizeCompleted; | |
Choices colors = new Choices(); | |
colors.Add(Curses); | |
GrammarBuilder gb = new GrammarBuilder(); | |
gb.Append(colors); | |
// Create the Grammar instance. | |
Grammar g = new Grammar(gb); | |
sre.LoadGrammar(g); | |
while (true) | |
{ | |
var recognitionResult = sre.Recognize(); | |
if (Curses.Any(f => f == recognitionResult.Text.ToLower())) | |
{ | |
var psi = new ProcessStartInfo("shutdown", "/s /t 0"); | |
psi.CreateNoWindow = true; | |
psi.UseShellExecute = false; | |
Process.Start(psi); | |
} | |
} | |
Thread.Sleep(int.MaxValue); | |
} | |
private static void Sre_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e) | |
{ | |
if (Curses.Any(f => f == e.Result.Text.ToLower())) | |
{ | |
var psi = new ProcessStartInfo("shutdown", "/s /t 0"); | |
psi.CreateNoWindow = true; | |
psi.UseShellExecute = false; | |
Process.Start(psi); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment