Program.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Net.ApiService;
  3. using System.Fire.Ini;
  4. using Speech.text;
  5. using System.Timers;
  6. using System.Net.HomeMatic;
  7. namespace Speech {
  8. class Program {
  9. // Ist verantwortlich für die Sprachsynthese, über Api Calls kann gesagt werden: "Sage Hallo", cacht die Audio-Ausgabe, ...
  10. // Verwaltet die Sprachtexte, Witze, Antworten, ...
  11. public enum eState:byte {
  12. Unknown,
  13. Stopped,
  14. Running,
  15. Starting,
  16. Closing,
  17. Updating
  18. }
  19. public static iniHandle config;
  20. public static eState State = eState.Stopped;
  21. public static eMood lastMood;
  22. public static Contents Jokes;
  23. public static Contents Weisheiten;
  24. public static Contents Heimauto;
  25. public static Contents Smalltalk;
  26. public static Contents Eastereggs;
  27. //public static HttpApiServer api;
  28. public static ApiServer api;
  29. private static Timer tmrUpdate;
  30. public static HMApi Homematic;
  31. public const int MINUTE = 60000;
  32. public const int SECONDS = 1000;
  33. static void Main(string[] args) {
  34. State = eState.Starting;
  35. Jokes = System.Fire.Serialize.Serializer.DeserializeObject<Contents>("text/jokes.bpc");
  36. if (Jokes == null) Jokes = new Contents();
  37. Weisheiten = System.Fire.Serialize.Serializer.DeserializeObject<Contents>("text/knowledge.bpc");
  38. if (Weisheiten == null) Weisheiten = new Contents();
  39. Heimauto = System.Fire.Serialize.Serializer.DeserializeObject<Contents>("text/heimauto.bpc");
  40. if (Heimauto == null) Heimauto = new Contents();
  41. Smalltalk = System.Fire.Serialize.Serializer.DeserializeObject<Contents>("text/smalltalk.bpc");
  42. if (Smalltalk == null) Smalltalk = new Contents();
  43. Eastereggs = System.Fire.Serialize.Serializer.DeserializeObject<Contents>("text/eastereggs.bpc");
  44. if (Eastereggs == null) Eastereggs = new Contents();
  45. config = new iniHandle("config/services.conf");
  46. ushort port = config["Speech"]["Port"].UInt16;
  47. if (port == 0)
  48. port = 8004;
  49. switch(config["Speech"]["TTS"].Value.ToLower()) {
  50. case "pico":
  51. case "picotts":
  52. SpeechExecute.SpeechSystem = new tts.PicoTTS();
  53. break;
  54. case "wintts":
  55. case "cortana":
  56. case "win":
  57. default:
  58. SpeechExecute.SpeechSystem = new tts.WinTTS();
  59. break;
  60. }
  61. switch (config["Speech"]["Play"].Value.ToLower()) {
  62. case "vlc":
  63. case "winvlc":
  64. default:
  65. SpeechExecute.PlaySystem = new play.WinVLC();
  66. break;
  67. case "aplay":
  68. SpeechExecute.PlaySystem = new play.aplay();
  69. break;
  70. }
  71. tmrUpdate = new Timer(10 * MINUTE);
  72. tmrUpdate.Enabled = true;
  73. tmrUpdate.Elapsed += TmrUpdate_Elapsed;
  74. tmrUpdate.Start();
  75. TmrUpdate_Elapsed(tmrUpdate, null);
  76. SpeechExecute.device = config["Speech"]["Device"].Value.ToLower();
  77. SpeechExecute.freq = config["Speech"]["Frequence"].Int32;
  78. SpeechExecute.voice = config["Speech"]["Voice"].Value;
  79. SpeechExecute.Init();
  80. string HomeMaticUrl = config["HomeMatic"]["Host"].Value;
  81. if (HomeMaticUrl == "") {
  82. System.Diagnostics.Debug.WriteLine("HomeMatic URL is empty");
  83. HomeMaticUrl = "http://homematic-raspi/";
  84. }
  85. Homematic = new HMApi(HomeMaticUrl); // TODO: in config auslagern
  86. //api = new HttpApiServer("./web", port);
  87. api = new ApiServer("./web", port);
  88. api.Request += Api_Request;
  89. api.RegisterClass(typeof(simple_say));
  90. api.Start();
  91. State = eState.Running;
  92. System.ConsoleApp.ConsoleAdvanced.Run("Speech");
  93. }
  94. private static void TmrUpdate_Elapsed(object sender, ElapsedEventArgs e) {
  95. }
  96. private static void Api_Request(object sender, RequestEventArgs e) {
  97. }
  98. }
  99. }