| | |
| | | } |
| | | } |
| | | string stamp_str=""; |
| | | for (i=0; i<timestamp_list.size(); i++) { |
| | | stamp_str += std::to_string(timestamp_list[i][0]); |
| | | for (i=0; i<timestamp_merge.size(); i++) { |
| | | stamp_str += std::to_string(timestamp_merge[i][0]); |
| | | stamp_str += ", "; |
| | | stamp_str += std::to_string(timestamp_list[i][1]); |
| | | if(i!=timestamp_list.size()-1){ |
| | | stamp_str += std::to_string(timestamp_merge[i][1]); |
| | | if(i!=timestamp_merge.size()-1){ |
| | | stamp_str += ","; |
| | | } |
| | | } |
| | |
| | | if (char_list.back() == "</s>") { |
| | | char_list.pop_back(); |
| | | } |
| | | |
| | | if (char_list.empty()) { |
| | | return ; |
| | | } |
| | | vector<vector<float>> timestamp_list; |
| | | vector<string> new_char_list; |
| | | vector<float> fire_place; |
| | |
| | | if(num_peak != (int)char_list.size() + 1){ |
| | | float sum = std::accumulate(us_alphas.begin(), us_alphas.end(), 0.0f); |
| | | float scale = sum/((int)char_list.size() + 1); |
| | | if(scale == 0){ |
| | | return; |
| | | } |
| | | cif_peak.clear(); |
| | | sum = 0.0; |
| | | for(auto &alpha:us_alphas){ |
| | |
| | | fire_place.push_back(i + total_offset); |
| | | } |
| | | } |
| | | } |
| | | |
| | | num_peak = fire_place.size(); |
| | | if(fire_place.size() == 0){ |
| | | return; |
| | | } |
| | | |
| | | // begin silence |
| | |
| | | } |
| | | |
| | | // tail token and end silence |
| | | if(timestamp_list.size()==0){ |
| | | LOG(ERROR)<<"timestamp_list's size is 0!"; |
| | | return; |
| | | } |
| | | if (num_frames - fire_place.back() > START_END_THRESHOLD) { |
| | | float _end = (num_frames + fire_place.back()) / 2.0; |
| | | timestamp_list.back()[1] = _end * TIME_RATE; |
| | |
| | | return ""; |
| | | } |
| | | |
| | | string result; |
| | | string result=""; |
| | | try { |
| | | auto outputTensor = m_session_->Run(Ort::RunOptions{nullptr}, m_szInputNames.data(), input_onnx.data(), input_onnx.size(), m_szOutputNames.data(), m_szOutputNames.size()); |
| | | std::vector<int64_t> outputShape = outputTensor[0].GetTensorTypeAndShapeInfo().GetShape(); |
| | |
| | | std::vector<int32_t> hotword_matrix; |
| | | std::vector<int32_t> lengths; |
| | | int hotword_size = 1; |
| | | int real_hw_size = 0; |
| | | if (!hotwords.empty()) { |
| | | std::vector<std::string> hotword_array = split(hotwords, ' '); |
| | | hotword_size = hotword_array.size() + 1; |
| | |
| | | chars.insert(chars.end(), tokens.begin(), tokens.end()); |
| | | } |
| | | } |
| | | if(chars.size()==0){ |
| | | continue; |
| | | } |
| | | std::vector<int32_t> hw_vector(max_hotword_len, 0); |
| | | int vector_len = std::min(max_hotword_len, (int)chars.size()); |
| | | for (int i=0; i<chars.size(); i++) { |
| | |
| | | } |
| | | std::cout << std::endl; |
| | | lengths.push_back(vector_len); |
| | | real_hw_size += 1; |
| | | hotword_matrix.insert(hotword_matrix.end(), hw_vector.begin(), hw_vector.end()); |
| | | } |
| | | hotword_size = real_hw_size + 1; |
| | | } |
| | | std::vector<int32_t> blank_vec(max_hotword_len, 0); |
| | | blank_vec[0] = 1; |