From 58f239f5bbff6fa35c221cafd9a5f83fb9779bc3 Mon Sep 17 00:00:00 2001
From: 嘉渊 <wangjiaming.wjm@alibaba-inc.com>
Date: 星期五, 12 五月 2023 16:57:35 +0800
Subject: [PATCH] update repo

---
 funasr/runtime/grpc/paraformer_server.cc |   43 +++++++++++++++++++++++++------------------
 1 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/funasr/runtime/grpc/paraformer_server.cc b/funasr/runtime/grpc/paraformer_server.cc
index e5814a5..f2ab4e0 100644
--- a/funasr/runtime/grpc/paraformer_server.cc
+++ b/funasr/runtime/grpc/paraformer_server.cc
@@ -29,8 +29,8 @@
 using paraformer::Response;
 using paraformer::ASR;
 
-ASRServicer::ASRServicer(const char* model_path, int thread_num) {
-    AsrHanlde=RapidAsrInit(model_path, thread_num);
+ASRServicer::ASRServicer(const char* model_path, int thread_num, bool quantize) {
+    AsrHanlde=RapidAsrInit(model_path, thread_num, quantize);
     std::cout << "ASRServicer init" << std::endl;
     init_flag = 0;
 }
@@ -88,7 +88,7 @@
             res.set_language(req.language());
             stream->Write(res);
         } else if (!req.speaking()) {
-            if (client_buffers.count(req.user()) == 0) {
+            if (client_buffers.count(req.user()) == 0 && req.audio_data().size() == 0) {
                 Response res;
                 res.set_sentence(
                     R"({"success": true, "detail": "waiting_for_voice"})"
@@ -99,14 +99,18 @@
                 stream->Write(res);
             }else {
                 auto begin_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
+                if (req.audio_data().size() > 0) {
+                  auto& buf = client_buffers[req.user()];
+                  buf.insert(buf.end(), req.audio_data().begin(), req.audio_data().end());
+                }
                 std::string tmp_data = this->client_buffers[req.user()];
                 this->clear_states(req.user());
-                
+
                 Response res;
                 res.set_sentence(
                     R"({"success": true, "detail": "decoding data: " + std::to_string(tmp_data.length()) + " bytes"})"
                 );
-		int data_len_int = tmp_data.length();
+                int data_len_int = tmp_data.length();
                 std::string data_len = std::to_string(data_len_int);
                 std::stringstream ss;
                 ss << R"({"success": true, "detail": "decoding data: )" << data_len << R"( bytes")"  << R"("})";
@@ -129,18 +133,18 @@
                     res.set_user(req.user());
                     res.set_action("finish");
                     res.set_language(req.language());
-                    
-                    
-                    
+
+
+
                     stream->Write(res);
                 }
                 else {
-                    RPASR_RESULT Result= RapidAsrRecogPCMBuffer(AsrHanlde, tmp_data.c_str(), data_len_int, RASR_NONE, NULL);   
+                    RPASR_RESULT Result= RapidAsrRecogPCMBuffer(AsrHanlde, tmp_data.c_str(), data_len_int, RASR_NONE, NULL);
                     std::string asr_result = ((RPASR_RECOG_RESULT*)Result)->msg;
 
                     auto end_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
                     std::string delay_str = std::to_string(end_time - begin_time);
-                    
+
                     std::cout << "user: " << req.user() << " , delay(ms): " << delay_str << ", text: " << asr_result << std::endl;
                     Response res;
                     std::stringstream ss;
@@ -150,8 +154,8 @@
                     res.set_user(req.user());
                     res.set_action("finish");
                     res.set_language(req.language());
-                    
-                    
+
+
                     stream->Write(res);
                 }
             }
@@ -165,15 +169,15 @@
             res.set_language(req.language());
             stream->Write(res);
         }
-    }    
+    }
     return Status::OK;
 }
 
 
-void RunServer(const std::string& port, int thread_num, const char* model_path) {
+void RunServer(const std::string& port, int thread_num, const char* model_path, bool quantize) {
     std::string server_address;
     server_address = "0.0.0.0:" + port;
-    ASRServicer service(model_path, thread_num);
+    ASRServicer service(model_path, thread_num, quantize);
 
     ServerBuilder builder;
     builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
@@ -184,12 +188,15 @@
 }
 
 int main(int argc, char* argv[]) {
-    if (argc < 3)
+    if (argc < 5)
     {
-        printf("Usage: %s port thread_num /path/to/model_file\n", argv[0]);
+        printf("Usage: %s port thread_num /path/to/model_file quantize(true or false) \n", argv[0]);
         exit(-1);
     }
 
-    RunServer(argv[1], atoi(argv[2]), argv[3]);
+    // is quantize
+    bool quantize = false;
+    std::istringstream(argv[4]) >> std::boolalpha >> quantize;
+    RunServer(argv[1], atoi(argv[2]), argv[3], quantize);
     return 0;
 }

--
Gitblit v1.9.1