hnluo
2023-08-10 ea2c102e6162c924c682aabfe8a052ce9a766a4d
funasr/runtime/websocket/websocket-server-2pass.cpp
@@ -152,8 +152,10 @@
      } catch (std::exception const& e) {
        LOG(ERROR) << e.what();
      }
      for (auto& vec : punc_cache) {
        vec.clear();
      if(punc_cache.size()>0){
        for (auto& vec : punc_cache) {
          vec.clear();
        }
      }
      if (Result) {
        websocketpp::lib::error_code ec;
@@ -178,7 +180,11 @@
void WebSocketServer::on_open(websocketpp::connection_hdl hdl) {
  scoped_lock guard(m_lock);     // for threads safty
  check_and_clean_connection();  // remove closed connection
  try{
    check_and_clean_connection();  // remove closed connection
  }catch (std::exception const& e) {
    std::cerr << "Error: " << e.what() << std::endl;
  }
  std::shared_ptr<FUNASR_MESSAGE> data_msg =
      std::make_shared<FUNASR_MESSAGE>();  // put a new data vector for new
@@ -320,14 +326,20 @@
        LOG(INFO) << "client done";
        // if it is in final message, post the sample_data to decode
        asio::post(
            io_decoder_,
            std::bind(&WebSocketServer::do_decoder, this,
                      std::move(*(sample_data_p.get())), std::move(hdl),
                      std::ref(msg_data->msg), std::ref(*(punc_cache_p.get())),
                      std::ref(*thread_lock_p), std::move(true),
                      msg_data->msg["wav_name"],
                      std::ref(msg_data->tpass_online_handle)));
        try{
          asio::post(
              io_decoder_,
              std::bind(&WebSocketServer::do_decoder, this,
                        std::move(*(sample_data_p.get())), std::move(hdl),
                        std::ref(msg_data->msg), std::ref(*(punc_cache_p.get())),
                        std::ref(*thread_lock_p), std::move(true),
                        msg_data->msg["wav_name"],
                        std::ref(msg_data->tpass_online_handle)));
        }
        catch (std::exception const &e)
        {
            LOG(ERROR)<<e.what();
        }
      }
      break;
    }
@@ -351,15 +363,22 @@
          // keep remain in sample_data
          sample_data_p->erase(sample_data_p->begin(),
                               sample_data_p->begin() + chunksize * setpsize);
          // post to decode
          asio::post(io_decoder_,
                     std::bind(&WebSocketServer::do_decoder, this,
                               std::move(subvector), std::move(hdl),
                               std::ref(msg_data->msg),
                               std::ref(*(punc_cache_p.get())),
                               std::ref(*thread_lock_p), std::move(false),
                               msg_data->msg["wav_name"],
                               std::ref(msg_data->tpass_online_handle)));
          try{
            // post to decode
            asio::post(io_decoder_,
                      std::bind(&WebSocketServer::do_decoder, this,
                                std::move(subvector), std::move(hdl),
                                std::ref(msg_data->msg),
                                std::ref(*(punc_cache_p.get())),
                                std::ref(*thread_lock_p), std::move(false),
                                msg_data->msg["wav_name"],
                                std::ref(msg_data->tpass_online_handle)));
          }
          catch (std::exception const &e)
          {
              LOG(ERROR)<<e.what();
          }
        }
      } else {
        sample_data_p->insert(sample_data_p->end(), pcm_data,