VoiceRSS.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. namespace Speech.tts {
  5. class VoiceRSS {
  6. public Process GenerateTTS(string path, string voiceName, string lang, string sentance) {
  7. Process p = new Process();
  8. string key = "1234567890";
  9. p.StartInfo.FileName = "java org.openhab.voice.voicerss.tool.CreateTTSCache --api-key "+key+" "+path+" "+lang+" \""+sentance+"\"";
  10. p.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
  11. p.StartInfo.CreateNoWindow = true;
  12. return p;
  13. }
  14. public string GetName() {
  15. return "Voice RSS";
  16. }
  17. public string generateFileName() {
  18. Random rnd = new Random();
  19. return this.DateTimeToCrypt() + "_" + rnd.Next(0, 999999).ToString().PadLeft(6, '0') + ".tmp";
  20. }
  21. public string generateFileName(string file_extention) {
  22. string cr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  23. Random rnd = new Random();
  24. return this.DateTimeToCrypt() + "_" + cr.Substring(rnd.Next(0, cr.Length - 1)) + cr.Substring(rnd.Next(0, cr.Length - 1)) + cr.Substring(rnd.Next(0, cr.Length - 1)) + cr.Substring(rnd.Next(0, cr.Length - 1)) + rnd.Next(0, 999999).ToString().PadLeft(6, '0') + "." + file_extention;
  25. }
  26. protected string DateTimeToCrypt() {
  27. return this.DateTimeToCrypt(DateTime.Now);
  28. }
  29. protected string DateTimeToCrypt(DateTime dt) {
  30. string cr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  31. int y = dt.Year;
  32. int M = dt.Month;
  33. int d = dt.Day;
  34. int h = dt.Hour;
  35. int i = dt.Minute;
  36. int s = dt.Second;
  37. int f = dt.Millisecond;
  38. int y1 = (int)Math.Floor((decimal)(y / cr.Length));
  39. int y2 = y - (y1 * cr.Length);
  40. int sum1 = (M * d) % (cr.Length - 1);
  41. int sum2 = (h * i * s) % (cr.Length - 1);
  42. return cr.Substring(y1, 1) + cr.Substring(y2, 1) +
  43. cr.Substring(M, 1) +
  44. cr.Substring(d, 1) +
  45. cr.Substring(h, 1) +
  46. cr.Substring(i, 1) +
  47. cr.Substring(s, 1) +
  48. cr.Substring(f % (cr.Length - 1), 1) +
  49. cr.Substring(sum1, 1) +
  50. cr.Substring(sum2, 1)
  51. ;
  52. }
  53. }
  54. }