雾聪
2024-09-25 d62d237a76e423fd1eec31e662162c135d2f93f5
runtime/onnxruntime/src/util.cpp
@@ -365,9 +365,13 @@
  }
}
std::string VectorToString(const std::vector<std::vector<int>>& vec) {
std::string VectorToString(const std::vector<std::vector<int>>& vec, bool out_empty) {
    if(vec.size() == 0){
        return "";
        if(out_empty){
            return "";
        }else{
            return "[]";
        }
    }
    std::ostringstream out;
    out << "[";
@@ -584,10 +588,11 @@
                }
            }
            // format
            ts_sent += "{'text':'" + text_seg + "',";
            ts_sent += "'start':'" + to_string(start) + "',";
            ts_sent += "'end':'" + to_string(end) + "',";
            ts_sent += "'ts_list':" + VectorToString(ts_seg) + "}";
            ts_sent += "{\"text_seg\":\"" + text_seg + "\",";
            ts_sent += "\"punc\":\"" + characters[idx_str] + "\",";
            ts_sent += "\"start\":" + to_string(start) + ",";
            ts_sent += "\"end\":" + to_string(end) + ",";
            ts_sent += "\"ts_list\":" + VectorToString(ts_seg, false) + "}";
            
            if (idx_str == characters.size()-1){
                ts_sentences += ts_sent;
@@ -620,10 +625,11 @@
            end = ts_seg[ts_seg.size()-1][1];
        }
        // format
        ts_sent += "{'text':'" + text_seg + "',";
        ts_sent += "'start':'" + to_string(start) + "',";
        ts_sent += "'end':'" + to_string(end) + "',";
        ts_sent += "'ts_list':" + VectorToString(ts_seg) + "}";
        ts_sent += "{\"text_seg\":\"" + text_seg + "\",";
        ts_sent += "\"punc\":\"\",";
        ts_sent += "\"start\":" + to_string(start) + ",";
        ts_sent += "\"end\":" + to_string(end) + ",";
        ts_sent += "\"ts_list\":" + VectorToString(ts_seg, false) + "}";
        ts_sentences += ts_sent;
    }
@@ -638,6 +644,21 @@
    elems.push_back(item);
  }
  return elems;
}
std::vector<std::string> SplitStr(const std::string &s, string delimiter) {
    std::vector<std::string> tokens;
    size_t start = 0;
    size_t end = s.find(delimiter);
    while (end != std::string::npos) {
        tokens.push_back(s.substr(start, end - start));
        start = end + delimiter.length();
        end = s.find(delimiter, start);
    }
    tokens.push_back(s.substr(start, end - start));
    return tokens;
}
template<typename T>
@@ -864,6 +885,15 @@
                sum -=(1.0 - 1e-4);
            }            
        }
        // fix case: sum > 1
        int cif_idx = cif_peak.size()-1;
        while(sum>=1.0 - 1e-4 && cif_idx >= 0 ){
            if(cif_peak[cif_idx] < 1.0 - 1e-4){
                cif_peak[cif_idx] = sum;
                sum -=(1.0 - 1e-4);
            }
            cif_idx--;
        }
        fire_place.clear();
        for (int i = 0; i < num_frames; i++) {