Program.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Collections.Specialized;
  2. using WebSocketSpace;
  3. namespace FunASRWSClient_Offline
  4. {
  5. /// <summary>
  6. /// /主程序入口
  7. /// </summary>
  8. public class Program
  9. {
  10. private static void Main()
  11. {
  12. WSClient_Offline m_funasrclient = new WSClient_Offline();
  13. m_funasrclient.FunASR_Main();
  14. }
  15. }
  16. public class WSClient_Offline
  17. {
  18. public static string host = "0.0.0.0";
  19. public static string port = "10095";
  20. private static CWebSocketClient m_websocketclient = new CWebSocketClient();
  21. [STAThread]
  22. public async void FunASR_Main()
  23. {
  24. loadconfig();
  25. //初始化通信连接
  26. string errorStatus = string.Empty;
  27. string commstatus = ClientConnTest();
  28. if (commstatus != "通信连接成功")
  29. errorStatus = commstatus;
  30. //程序初始监测异常--报错、退出
  31. if (errorStatus != string.Empty)
  32. {
  33. //报错方式待加
  34. Environment.Exit(0);
  35. }
  36. //循环输入推理文件
  37. while (true)
  38. {
  39. Console.WriteLine("请输入转录文件路径:");
  40. string filepath = Console.ReadLine();
  41. if (filepath != string.Empty && filepath != null)
  42. {
  43. await m_websocketclient.ClientSendFileFunc(filepath);
  44. }
  45. }
  46. }
  47. private void loadconfig()
  48. {
  49. string filePath = "config.ini";
  50. NameValueCollection settings = new NameValueCollection();
  51. using (StreamReader reader = new StreamReader(filePath))
  52. {
  53. string line;
  54. while ((line = reader.ReadLine()) != null)
  55. {
  56. // 忽略空行和注释
  57. if (string.IsNullOrEmpty(line) || line.StartsWith(";") || line.StartsWith("#"))
  58. continue;
  59. // 解析键值对
  60. int equalsIndex = line.IndexOf('=');
  61. if (equalsIndex > 0)
  62. {
  63. string key = line.Substring(0, equalsIndex).Trim();
  64. string value = line.Substring(equalsIndex + 1).Trim();
  65. if (key == "host")
  66. host = value;
  67. else if (key == "port")
  68. port = value;
  69. }
  70. }
  71. }
  72. }
  73. private static string ClientConnTest()
  74. {
  75. //WebSocket连接状态监测
  76. Task<string> websocketstatus = m_websocketclient.ClientConnTest();
  77. if (websocketstatus != null && websocketstatus.Result.IndexOf("成功") == -1)
  78. return websocketstatus.Result;
  79. return "通信连接成功";
  80. }
  81. }
  82. }