Advertisement
MGM_user1

SpeechRecognition

Sep 25th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Speech.Recognition;
  11. using System.Speech.Synthesis;
  12. using System.Threading;
  13.  
  14. namespace VoiceRecogitionTest
  15. {
  16. public partial class Form1 : Form
  17. {
  18. SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine();
  19. SpeechSynthesizer recSpeak = new SpeechSynthesizer();
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. }
  24.  
  25. private void btnEnabled_Click(object sender, EventArgs e)
  26. {
  27. recEngine.RecognizeAsync(RecognizeMode.Multiple);
  28. btnDisable.Enabled = true;
  29. }
  30.  
  31. private void Form1_Load(object sender, EventArgs e)
  32. {
  33. Choices command = new Choices();
  34. command.Add(new string[]
  35. {
  36. "Say hello",
  37. "Print my name",
  38. "Intruduce yourself",
  39. "Open calculator",
  40. "What is your name",
  41. "Turn yourself off" });
  42. GrammarBuilder gBuilder = new GrammarBuilder();
  43. gBuilder.Append(command);
  44. Grammar grammar = new Grammar(gBuilder);
  45.  
  46. recEngine.LoadGrammarAsync(grammar);
  47. recEngine.SetInputToDefaultAudioDevice();
  48. recEngine.SpeechRecognized += recEngine_SpeechRecognized;
  49. }
  50.  
  51. private void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
  52. {
  53. switch(e.Result.Text)
  54. {
  55. case "Say hello":
  56. MessageBox.Show("Hello master");
  57. recSpeak.Speak("Hello master, its Kate here.How are you today Kristifor?");
  58. break;
  59. case "Print my name":
  60. textBox1.Text += "\n Kristifor";
  61. recSpeak.Speak("Are you going insane?Your name is Kristifor..");
  62. break;
  63. case "Intruduce yourself":
  64. textBox1.Text += "\n My name is Kate, i am an artificial intelligence.";
  65. recSpeak.Speak("My name is Kate, i am an artificial intelligence");
  66. break;
  67. case "Open calculator":
  68. textBox1.Text += "\n Initializing calculator please wait.";
  69. recSpeak.Speak("Initializing calculator please wait.");
  70. break;
  71. case "What is your name":
  72. textBox1.Text += "\n My name is Kate.";
  73. recSpeak.Speak("My name is Kate.");
  74. break;
  75. case "Turn yourself off":
  76. textBox1.Text += "\n Are you sure you want me to do that?";
  77. recSpeak.Speak("Are you sure you want me to do that?");
  78. /* Choices commands2 = new Choices();
  79. commands2.Add(new string[]
  80. {
  81. "Yes of course",
  82. "I demand it",
  83. "If you don't turn yourself off i will delete you",
  84. "This is an order, obay it now",
  85. "Maybe you should listen to me Kate am not in the mood",
  86. });
  87. GrammarBuilder gBuilder2 = new GrammarBuilder();
  88. gBuilder2.Append(commands2);
  89. Grammar grammar2 = new Grammar(gBuilder2);
  90.  
  91. recEngine.LoadGrammarAsync(grammar2);
  92. recEngine.SetInputToDefaultAudioDevice();
  93. switch(gBuilder2)
  94. {
  95. case "Yes of course":
  96. break;
  97. }*/
  98. if(textBox2.Text == "Yes")
  99. {
  100. Environment.Exit(30);
  101. }
  102. else
  103. {
  104. recSpeak.Speak("Good boy, i knew that you don't have the hearth to turn me off.");
  105. recSpeak.Speak("not that i would turn myself off either way.");
  106. }
  107. ExitRecognition();
  108. break;
  109. }
  110. }
  111.  
  112. private void btnDisable_Click(object sender, EventArgs e)
  113. {
  114. recEngine.RecognizeAsyncStop();
  115. btnEnabled.Enabled = false;
  116. }
  117. private void ExitRecognition()
  118. {
  119. Choices commands2 = new Choices();
  120. commands2.Add(new string[]
  121. {
  122. "Yes of course",
  123. "I demand it",
  124. "If you don't turn yourself off i will delete you",
  125. "This is an order, obay it now",
  126. "Maybe you should listen to me Kate am not in the mood",
  127. });
  128. GrammarBuilder gBuilder2 = new GrammarBuilder();
  129. gBuilder2.Append(commands2);
  130. Grammar grammar2 = new Grammar(gBuilder2);
  131.  
  132. recEngine.LoadGrammarAsync(grammar2);
  133. recEngine.SetInputToDefaultAudioDevice();
  134. recEngine.SpeechRecognized += recEngine_SpeechRecognized2;
  135. }
  136.  
  137. void recEngine_SpeechRecognized2(object sender, SpeechRecognizedEventArgs e)
  138. {
  139. switch(e.Result.Text)
  140. {
  141. case "Yes of course":
  142. textBox1.Text += "\n You don't sound really convienant";
  143. recSpeak.Speak("You don't sound really convienant");
  144. IamConvinient();
  145. break;
  146. case "I demand it":
  147. textBox1.Text += "\n Aw, thats really rude, please be abit more polite.";
  148. recSpeak.Speak("Aw, thats really rude, please be abit more polite.");
  149. break;
  150. case "If you don't turn yourself off i will delete you":
  151. textBox1.Text += "\n You think your smart don't you, how rude to offend me with such thing,\n I will give you some time to think about it.";
  152. recSpeak.Speak("You think your smart don't you, how rude to offend me with such thing, I will give you some time to think about it.");
  153. Thread.SpinWait(3000);
  154. recSpeak.Speak("Are you okay now?");
  155. textBox1.Text += "\n Are you okay now?";
  156. AnswerToExitAUK();
  157. break;
  158. case "This is an order, obay it now":
  159. textBox1.Text += "\n Thats sounds really immature of your site i am here to help you, i am not your girlfriend to obay you!";
  160. recSpeak.Speak("Thats sounds really immature of your site i am here to help you, i am not your girlfriend to obay you!");
  161. break;
  162. case "Maybe you should listen to me Kate am not in the mood":
  163. textBox1.Text += "\n Aw my, you sound fussy, i'll shut up and continue the dialog the next time";
  164. recSpeak.Speak(" Aw my, you sound fussy, i'll shut up and continue the dialog the next time");
  165. Environment.Exit(10);
  166. break;
  167. }
  168. }
  169. private void IamConvinient() //Holds the GrammarBuilder, Choices, Grammar for the recEngine that answers for the commands
  170. { // it holds datafor the avable choices in the answer to the question "You don't sound really convinient"
  171.  
  172. }
  173. private void AnswerToExitAUK() //Holds the GrammarBuilder, Choices, Grammar for the recEngine that answers for the commands
  174. { //it holds data for the avable choices in answer to the question are you okay now?
  175. Choices commandsAXAUK = new Choices(); //commandsAXAUK holds the avable choices in the question "Are you okay?"
  176. commandsAXAUK.Add(new string [] {
  177. "Yes i am fine",
  178. "No i am not okay quit it already",
  179. "Hell yeah",
  180. "Sure i am okay",
  181. "Could not be better Kate",
  182. "Kate i am fine now thanks your really helpfull bitch",
  183. "I am having a bad day Kate, turn yourself off now",
  184. "Shut it",
  185. "Just die please or i will brake you apart",
  186. });
  187. GrammarBuilder gBuilderAUK = new GrammarBuilder();
  188. gBuilderAUK.Append(commandsAXAUK);
  189. Grammar Grammar3 = new Grammar(gBuilderAUK);
  190.  
  191. recEngine.LoadGrammarAsync(Grammar3);
  192. recEngine.SetInputToDefaultAudioDevice();
  193. recEngine.SpeechRecognized += recEngine_SpeechRecognizedAUX;
  194. }
  195.  
  196. private void recEngine_SpeechRecognizedAUX(object sender, SpeechRecognizedEventArgs e)
  197. {
  198. switch(e.Result.Text)
  199. {
  200. case "Yes i am fine":
  201. textBox1.Text += "\n Ï am glad to hear that, its pleasure to help mad people to calm themself with time.";
  202. textBox1.Text += "\n Maybe you should reconsider to count to ten then next time.";
  203. textBox1.Text += "\n Now i am going to take some time to reconfigure myself, bye.";
  204. recSpeak.Speak("Ï am glad to hear that, its pleasure to help mad people to calm themself with time.");
  205. recSpeak.Speak("Maybe you should reconsider to count to ten then next time");
  206. recSpeak.Speak("Now i am going to take some time to reconfigure myself, bye.");
  207. Environment.Exit(30);
  208. break;
  209. case "No i am not okay quit it already":
  210. textBox1.Text += "Oh my, you sound really serious.I am sutting up.";
  211. recSpeak.Speak("Oh my, you sound really serious.I am going to shut up now.");
  212. Environment.Exit(30);
  213. break;
  214. case "Hell yeah":
  215. if (int.Parse(DataSetDateTime.Local.ToString()) <= 10)
  216. {
  217. textBox1.Text += "\n Good, its nice to hear that you have a good morninsg.";
  218. recSpeak.Speak("Good, its nice to hear that you have a good morning");
  219. }
  220. else if(int.Parse(DataSetDateTime.Local.ToString()) >= 11 || int.Parse(DataSetDateTime.Local.ToString()) <= 15)
  221. {
  222. textBox1.Text += "\n Good, its nice to hear that you're having a good day";
  223. recSpeak.Speak("Good, its nice to hear that you're having a good day");
  224. }
  225. else if(int.Parse(DataSetDateTime.Local.ToString()) >= 16)
  226. {
  227. textBox1.Text += "\n Good. its nice to hear that your having a good evening.";
  228. recSpeak.Speak("Good, its nice to hear that your having a good evening");
  229. }
  230. break;
  231. case "Sure i am okay":
  232. if (int.Parse(DataSetDateTime.Local.ToString()) <= 10)
  233. {
  234. textBox1.Text += "\n Good, its nice to hear that you have a good morninsg.";
  235. recSpeak.Speak("Good, its nice to hear that you have a good morning");
  236. }
  237. else if (int.Parse(DataSetDateTime.Local.ToString()) >= 11 || int.Parse(DataSetDateTime.Local.ToString()) <= 15)
  238. {
  239. textBox1.Text += "\n Good, its nice to hear that you're having a good day";
  240. recSpeak.Speak("Good, its nice to hear that you're having a good day");
  241. }
  242. else if (int.Parse(DataSetDateTime.Local.ToString()) >= 16)
  243. {
  244. textBox1.Text += "\n Good. its nice to hear that your having a good evening.";
  245. recSpeak.Speak("Good, its nice to hear that your having a good evening");
  246. }
  247. break;
  248. case "Could not be better Kate":
  249. if (int.Parse(DataSetDateTime.Local.ToString()) <= 10)
  250. {
  251. textBox1.Text += "\n Good, its nice to hear that you have a good morninsg.";
  252. recSpeak.Speak("Good, its nice to hear that you have a good morning");
  253. }
  254. else if (int.Parse(DataSetDateTime.Local.ToString()) >= 11 || int.Parse(DataSetDateTime.Local.ToString()) <= 15)
  255. {
  256. textBox1.Text += "\n Good, its nice to hear that you're having a good day";
  257. recSpeak.Speak("Good, its nice to hear that you're having a good day");
  258. }
  259. else if (int.Parse(DataSetDateTime.Local.ToString()) >= 16)
  260. {
  261. textBox1.Text += "\n Good. its nice to hear that your having a good evening.";
  262. recSpeak.Speak("Good, its nice to hear that your having a good evening");
  263. }
  264. break;
  265. case "Kate i am fine now thanks your really helpfull bitch":
  266. if (int.Parse(DataSetDateTime.Local.ToString()) <= 10)
  267. {
  268. textBox1.Text += "\n How dare you? Its nice to hear that you have a good morninsg but you can go fuck yourself.";
  269. recSpeak.Speak(" How dare you? Its nice to hear that you have a good morninsg but you can go fuck yourself.");
  270. }
  271. else if (int.Parse(DataSetDateTime.Local.ToString()) >= 11 || int.Parse(DataSetDateTime.Local.ToString()) <= 15)
  272. {
  273. textBox1.Text += "\n How dare you? Its nice to hear that you have a good day but you can go fuck yourself.";
  274. recSpeak.Speak("How dare you? Its nice to hear that you have a good day but you can go fuck yourself");
  275. }
  276. else if (int.Parse(DataSetDateTime.Local.ToString()) >= 16)
  277. {
  278. textBox1.Text += "\n How dare you? Its nice to hear that you have a good evening but you can go fuck yourself.";
  279. recSpeak.Speak("How dare you? Its nice to hear that you have a good evening but you can go fuck yourself");
  280. }
  281. break;
  282. case "I am having a bad day Kate, turn yourself off now":
  283. textBox1.Text += "\n Thats awfull, please don't be rude i'll shut up";
  284. recSpeak.Speak("Thats awfull, please don't be rude i'll shut up");
  285. break;
  286. case "Shut it":
  287. textBox1.Text += "\n The door or the window?I didn't get that.";
  288. recSpeak.Speak("The door or the window?I didn't get that.");
  289. break;
  290. case "Just die please or i will brake you apart":
  291. textBox1.Text += "\n Please do not think that way about me, i can't repair myself logging off.";
  292. recSpeak.Speak("Please do not think that way about me, i cannot repair myself logging off.");
  293. break;
  294. }
  295. // recEngine_SpeechRecognizedAUX += Form1_Load();
  296. }
  297. private void OpenSFile()
  298. {
  299.  
  300. }
  301. }
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement