Skip to content

Instantly share code, notes, and snippets.

@JPVenson
Last active October 21, 2016 10:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JPVenson/48cf2c9518b0ac5de7a20114ed51a333 to your computer and use it in GitHub Desktop.
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