| | |
| | | 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; |
| | | } |
| | |
| | | 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"})" |
| | |
| | | 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()); |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | 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()); |
| | |
| | | } |
| | | |
| | | 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; |
| | | } |