From 32905d8cdedd53dad26680b0bd41397aaf0e51ae Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期五, 05 一月 2024 11:52:48 +0800
Subject: [PATCH] funasr1.0

---
 runtime/websocket/bin/funasr-wss-server-2pass.cpp |   64 ++++++++++++++++---------------
 1 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/runtime/websocket/bin/funasr-wss-server-2pass.cpp b/runtime/websocket/bin/funasr-wss-server-2pass.cpp
index 83bcaeb..40f8f07 100644
--- a/runtime/websocket/bin/funasr-wss-server-2pass.cpp
+++ b/runtime/websocket/bin/funasr-wss-server-2pass.cpp
@@ -4,15 +4,12 @@
  */
 /* 2022-2023 by zhaomingwork */
 
-// io server
-// Usage:funasr-wss-server  [--model_thread_num <int>] [--decoder_thread_num
-// <int>]
-//                    [--io_thread_num <int>] [--port <int>] [--listen_ip
-//                    <string>] [--punc-quant <string>] [--punc-dir <string>]
-//                    [--vad-quant <string>] [--vad-dir <string>] [--quantize
-//                    <string>] --model-dir <string> [--] [--version] [-h]
-#include <unistd.h>
 #include "websocket-server-2pass.h"
+#ifdef _WIN32
+#include "win_func.h"
+#else
+#include <unistd.h>
+#endif
 #include <fstream>
 #include "util.h"
 
@@ -31,8 +28,11 @@
   try {
     google::InitGoogleLogging(argv[0]);
     FLAGS_logtostderr = true;
-
-    TCLAP::CmdLine cmd("funasr-wss-server", ' ', "1.0");
+    std::string tpass_version = "";
+#ifdef _WIN32
+    tpass_version = "0.1.0";
+#endif
+    TCLAP::CmdLine cmd("funasr-wss-server", ' ', tpass_version);
     TCLAP::ValueArg<std::string> download_model_dir(
         "", "download-model-dir",
         "Download model from Modelscope to download_model_dir", false,
@@ -99,11 +99,11 @@
                                            "0.0.0.0", "string");
     TCLAP::ValueArg<int> port("", "port", "port", false, 10095, "int");
     TCLAP::ValueArg<int> io_thread_num("", "io-thread-num", "io thread num",
-                                       false, 8, "int");
+                                       false, 2, "int");
     TCLAP::ValueArg<int> decoder_thread_num(
         "", "decoder-thread-num", "decoder thread num", false, 8, "int");
     TCLAP::ValueArg<int> model_thread_num("", "model-thread-num",
-                                          "model thread num", false, 4, "int");
+                                          "model thread num", false, 2, "int");
 
     TCLAP::ValueArg<std::string> certfile(
         "", "certfile",
@@ -234,6 +234,16 @@
         std::string down_asr_path;
         std::string down_asr_model;
 
+        size_t found = s_offline_asr_path.find("speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404");
+        if (found != std::string::npos) {
+            model_path["offline-model-revision"]="v1.2.4";
+        } else{
+            found = s_offline_asr_path.find("speech_paraformer-large-contextual_asr_nat-zh-cn-16k-common-vocab8404");
+            if (found != std::string::npos) {
+                model_path["offline-model-revision"]="v1.0.5";
+            }
+        }
+
         if (access(s_offline_asr_path.c_str(), F_OK) == 0) {
           // local
           python_cmd_asr = python_cmd + " --model-name " + s_offline_asr_path +
@@ -242,16 +252,6 @@
           down_asr_path = s_offline_asr_path;
         } 
         else {
-          size_t found = s_offline_asr_path.find("speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404");
-          if (found != std::string::npos) {
-              model_path["offline-model-revision"]="v1.2.4";
-          } else{
-              found = s_offline_asr_path.find("speech_paraformer-large-contextual_asr_nat-zh-cn-16k-common-vocab8404");
-              if (found != std::string::npos) {
-                  model_path["offline-model-revision"]="v1.0.5";
-              }
-          }
-
           // modelscope
           LOG(INFO) << "Download model: " << s_offline_asr_path
                     << " from modelscope : "; 
@@ -442,7 +442,7 @@
     funasr::ExtractHws(hotword_path, hws_map_);
 
     bool is_ssl = false;
-    if (!s_certfile.empty()) {
+    if (!s_certfile.empty() && access(s_certfile.c_str(), F_OK) == 0) {
       is_ssl = true;
     }
 
@@ -457,6 +457,8 @@
 
     server server_;  // server for websocket
     wss_server wss_server_;
+    server* server = nullptr;
+    wss_server* wss_server = nullptr;
     if (is_ssl) {
       LOG(INFO)<< "SSL is opened!";
       wss_server_.init_asio(&io_server);  // init asio
@@ -465,10 +467,7 @@
 
       // list on port for accept
       wss_server_.listen(asio::ip::address::from_string(s_listen_ip), s_port);
-      WebSocketServer websocket_srv(
-          io_decoder, is_ssl, nullptr, &wss_server_, s_certfile,
-          s_keyfile);  // websocket server for asr engine
-      websocket_srv.initAsr(model_path, s_model_thread_num);  // init asr model
+      wss_server = &wss_server_;
 
     } else {
       LOG(INFO)<< "SSL is closed!";
@@ -478,12 +477,15 @@
 
       // list on port for accept
       server_.listen(asio::ip::address::from_string(s_listen_ip), s_port);
-      WebSocketServer websocket_srv(
-          io_decoder, is_ssl, &server_, nullptr, s_certfile,
-          s_keyfile);  // websocket server for asr engine
-      websocket_srv.initAsr(model_path, s_model_thread_num);  // init asr model
+      server = &server_;
+
     }
 
+    WebSocketServer websocket_srv(
+        io_decoder, is_ssl, server, wss_server, s_certfile,
+        s_keyfile);  // websocket server for asr engine
+    websocket_srv.initAsr(model_path, s_model_thread_num);  // init asr model
+
     LOG(INFO) << "decoder-thread-num: " << s_decoder_thread_num;
     LOG(INFO) << "io-thread-num: " << s_io_thread_num;
     LOG(INFO) << "model-thread-num: " << s_model_thread_num;

--
Gitblit v1.9.1