Advertisement
D3NCE

KÜNSTLICHE INTELLIGENZ IN C# SCHREIBEN – PART 15 – WIKIPEDIA

Dec 21st, 2018
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. Video URL: https://www.youtube.com/watch?v=rgZ-BD4Gzc4
  2.  
  3. Hier ist der neue Deklarationsteil:
  4.  
  5. #region Deklaration der Engine und variablen
  6. SpeechRecognitionEngine h = new SpeechRecognitionEngine();
  7. SpeechSynthesizer s = new SpeechSynthesizer();
  8.  
  9. CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice;
  10.  
  11. //Boolean für den Ruhemodus
  12. public Boolean hören = true;
  13.  
  14. //Boolean für die Google suche
  15. public Boolean suche = false;
  16.  
  17. //Boolean für die Wikipedia suche
  18. public Boolean wasist = false;
  19.  
  20. //Verzeichnis URI
  21. public string vuri = "C:\\Users\\Freddy\\Visual Studio";
  22.  
  23. #endregion
  24.  
  25.  
  26.  
  27. Hier finden ihr den Code für die neue suche:
  28.  
  29. #region wikipedia suche core
  30.  
  31. if (wasist)
  32. {
  33. try
  34. {
  35. s.SpeakAsync(
  36. "Das Internet sagt dazu folgendes:");
  37. lbl_ans.Text = "Das Internet sagt dazu folgendes";
  38.  
  39. WebClient client = new WebClient();
  40.  
  41. using (Stream stream =
  42. client.OpenRead(
  43. "http://de.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&explaintext=1&titles=" + modus)
  44. )
  45. using (StreamReader reader = new StreamReader(stream))
  46. {
  47. JsonSerializer ser = new JsonSerializer();
  48. Result result = ser.Deserialize<Result>(new JsonTextReader(reader));
  49.  
  50. foreach (Page page in result.query.pages.Values)
  51. txt_info.Text = page.extract;
  52.  
  53. string antwort = txt_info.Text;
  54.  
  55. string small = antwort.Substring(0, 500);
  56.  
  57. s.SpeakAsync(small);
  58. }
  59.  
  60. wasist = false;
  61. }
  62. catch (Exception)
  63. {
  64. s.SpeakAsync("Nichts, es sagt nichts, komisch, sehr komisch, du musst da wohl was durcheinander gebracht haben. Ich sschüttel den Google automaten aber da kommt nur leeres klimpern! Versuch es noch einmal.");
  65. wasist = false;
  66. }
  67. }
  68. #endregion
  69.  
  70.  
  71.  
  72. Hier findet ihr das neue case:
  73.  
  74. if (hören == true && suche == false && wasist == false)
  75. {
  76. lbl_quest.Text = e.Result.Text;
  77. switch (e.Result.Text)
  78. {
  79.  
  80. case "was ist":
  81. wasist = true;
  82. tab_control.SelectTab(tab_wiki);
  83. break;
  84.  
  85.  
  86.  
  87. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement