SpeechFormat.cs 5.7 KB

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