SpeechFormat.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Speech {
  5. public class SpeechFormat {
  6. public static string Pronounce(string s) {
  7. return s;
  8. }
  9. public static string Format(string s) {
  10. if (s.Contains("{now.")) {
  11. s = s.Replace("{now.hour}", DateTime.Now.Hour.ToString());
  12. s = s.Replace("{now.h}", DateTime.Now.Hour.ToString());
  13. s = s.Replace("{now.minute}", DateTime.Now.Minute.ToString());
  14. s = s.Replace("{now.i}", DateTime.Now.Minute.ToString());
  15. s = s.Replace("{now.second}", DateTime.Now.Second.ToString());
  16. s = s.Replace("{now.s}", DateTime.Now.Second.ToString());
  17. s = s.Replace("{now.day}", DateTime.Now.Day.ToString());
  18. s = s.Replace("{now.d}", DateTime.Now.Day.ToString());
  19. s = s.Replace("{now.month}", DateTime.Now.Month.ToString());
  20. s = s.Replace("{now.monthname}", getMonthName(DateTime.Now.Month));
  21. s = s.Replace("{now.m}", DateTime.Now.Month.ToString());
  22. s = s.Replace("{now.M}", getMonthName(DateTime.Now.Month));
  23. s = s.Replace("{now.year}", DateTime.Now.Year.ToString());
  24. s = s.Replace("{now.y}", DateTime.Now.Year.ToString());
  25. s = s.Replace("{now.w}", DayOfWeek(DateTime.Now.DayOfWeek));
  26. s = s.Replace("{now.datetime}", DayOfWeek(DateTime.Now.DayOfWeek)+", den " + DateTime.Now.Day.ToString() + "ten "+ getMonthName(DateTime.Now.Month)+" "+ DateTime.Now.Year.ToString() + " " + TimeFormat(DateTime.Now));
  27. s = s.Replace("{now.time}", TimeFormat(DateTime.Now));
  28. s = s.Replace("{now.date}", DayOfWeek(DateTime.Now.DayOfWeek) + ", den " + DateTime.Now.Day.ToString() + "ten " + getMonthName(DateTime.Now.Month) + " " + DateTime.Now.Year.ToString());
  29. }
  30. if (s.Contains("{person.")) {
  31. // TODO: Connect to addressbook, fetch data of person.(.+) and replace
  32. // Schema: {person.Patrick.phone}, {person.Patrick.Name}, ...
  33. }
  34. if (s.Contains("{web")) {
  35. // TODO: Fetch web Data and return the value of a tag/id/class
  36. // Schema: To be decided
  37. }
  38. if (s.Contains("{system.")) {
  39. // TODO: System Variablen
  40. }
  41. if (s.Contains("{service.")) {
  42. // TODO: Service states
  43. }
  44. if (s.Contains("{homematic.")) {
  45. // homematic.lights.
  46. // homematic.rooms.
  47. // homematic.variable.
  48. // homematic.temperature.(hottest,coldest, ...)
  49. // TODO: Homematic Variablen
  50. }
  51. if (s.Contains("{network.")) {
  52. // TODO: Network stuff like traffic, connections, ...
  53. }
  54. return s;
  55. }
  56. public static string getMonthName(int m) {
  57. switch (m) {
  58. case 1: return "Januar";
  59. case 2: return "Februar";
  60. case 3: return "März";
  61. case 4: return "April";
  62. case 5: return "Mai";
  63. case 6: return "Juni";
  64. case 7: return "Juli";
  65. case 8: return "August";
  66. case 9: return "September";
  67. case 10: return "Oktober";
  68. case 11: return "November";
  69. case 12: return "Dezember";
  70. }
  71. return "";
  72. }
  73. public static string DayOfWeek(DayOfWeek d) {
  74. switch (d) {
  75. case System.DayOfWeek.Monday: return "Montag";
  76. case System.DayOfWeek.Tuesday: return "Dienstag";
  77. case System.DayOfWeek.Wednesday: return "Mittwoch";
  78. case System.DayOfWeek.Thursday: return "Donnerstag";
  79. case System.DayOfWeek.Friday: return "Freitag";
  80. case System.DayOfWeek.Saturday: return "Samstag";
  81. case System.DayOfWeek.Sunday: return "Sonntag";
  82. }
  83. return "";
  84. }
  85. public static string TimeFormat(DateTime dt) {
  86. int m = dt.Minute;
  87. switch (m) {
  88. case 0: return "Punkt " + dt.Hour + " Uhr";
  89. case 1: return dt.Hour + " Uhr";
  90. case 15: return "Viertel nach " + dt.Hour;
  91. case 30:
  92. if (dt.Hour == 11 || dt.Hour == 23) {
  93. return "Halb zwölf";
  94. } else {
  95. return "Halb " + ((dt.Hour % 12) + 1);
  96. }
  97. case 45:
  98. return "Viertel vor " + ((dt.Hour % 12) + 1);
  99. case 50:
  100. return "Zehn vor " + ((dt.Hour % 12) + 1);
  101. case 55:
  102. return "Fünf vor " + ((dt.Hour % 12) + 1);
  103. case 58:
  104. case 59:
  105. return "Kurz vor " + ((dt.Hour % 12) + 1);
  106. default:
  107. if (m <= 10) {
  108. return dt.Minute + " nach " + dt.Hour;
  109. }
  110. if(m>=50){
  111. return (60 - dt.Minute) + " vor " + ((dt.Hour % 12) + 1);
  112. }
  113. return dt.Hour + " Uhr " + dt.Minute;
  114. }
  115. }
  116. }
  117. }