Created
June 3, 2012 21:47
-
-
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
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
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