Skip to content

Instantly share code, notes, and snippets.

@factormystic
Created June 3, 2012 21:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save factormystic/2865139 to your computer and use it in GitHub Desktop.
Save factormystic/2865139 to your computer and use it in GitHub Desktop.
Using speech recognition, speech synthesis, and the Wolfram Alpha API to make a simple Siri clone
var WA_API_KEY = @"";
var VoiceOut = new System.Speech.Synthesis.SpeechSynthesizer();
VoiceOut.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult, 0, CultureInfo.CurrentCulture);
VoiceOut.SetOutputToDefaultAudioDevice();
var WA = new WAClient(WA_API_KEY);
WA.OnResultReceived += (WAResult, input) =>
{
try
{
var result = WAResult.Pods.First(p => p.Title == "Result").SubPods.First().PlainText;
Debug.WriteLine(result);
VoiceOut.SpeakAsync(result);
}
catch (Exception ex)
{
VoiceOut.SpeakAsync("I don't know");
}
};
var VoiceIn = new SpeechRecognitionEngine();
VoiceIn.LoadGrammar(new DictationGrammar("grammar:dictation"));
VoiceIn.SetInputToDefaultAudioDevice();
VoiceIn.SpeechRecognized += (s, e) =>
{
Debug.WriteLine(e.Result.Text);
WA.GetResultAsync(e.Result.Text);
VoiceOut.SpeakAsync("Let me check");
};
VoiceIn.RecognizeAsync(RecognizeMode.Multiple);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment