Skip to content

Commit 2db67b3

Browse files
committed
fix LFA
1 parent eed5245 commit 2db67b3

2 files changed

Lines changed: 32 additions & 25 deletions

File tree

src/apps/LyricFA/util/LyricAligner.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ namespace LyricFA {
3636
const int n = referencePronunciation.size();
3737
const int m = searchPronunciation.size();
3838

39-
// 修复: 处理n < m的情况
4039
if (n < m) {
4140
return {0, std::min(n, m), {}, {}};
4241
}
@@ -52,7 +51,7 @@ namespace LyricFA {
5251
}
5352

5453
const int currentMatchLength = longestCommonSubsequence(searchPronunciation, window);
55-
if (currentMatchLength >= maxMatchLength) { // 修复: 使用>=而不是>
54+
if (currentMatchLength >= maxMatchLength) {
5655
maxMatchLength = currentMatchLength;
5756
bestStartIdx = startIdx;
5857
}
@@ -171,13 +170,14 @@ namespace LyricFA {
171170
std::vector<std::string> formattedOps;
172171
for (size_t position = 0; position < operations.size(); ++position) {
173172
const auto &[original, modified] = operations[position];
174-
175-
if (!original.empty() && modified.empty() && showDel) {
176-
formattedOps.push_back("(" + original + "->, " + std::to_string(position) + ")");
177-
} else if (original.empty() && !modified.empty() && showIns) {
178-
formattedOps.push_back("(->" + modified + ", " + std::to_string(position) + ")");
179-
} else if (!original.empty() && !modified.empty() && showSub) {
180-
formattedOps.push_back("(" + original + "->" + modified + ", " + std::to_string(position) + ")");
173+
if (original != modified) {
174+
if (!original.empty() && modified.empty() && showDel) {
175+
formattedOps.push_back("(" + original + "->, " + std::to_string(position) + ")");
176+
} else if (original.empty() && !modified.empty() && showIns) {
177+
formattedOps.push_back("(->" + modified + ", " + std::to_string(position) + ")");
178+
} else if (!original.empty() && !modified.empty() && showSub) {
179+
formattedOps.push_back("(" + modified + "->" + original + ", " + std::to_string(position) + ")");
180+
}
181181
}
182182
}
183183
return join(formattedOps, " ");
@@ -232,8 +232,8 @@ namespace LyricFA {
232232
while (i > 0 || j > 0) {
233233
if (i > 0 && j > 0 && sourcePronunciation[i - 1] == targetPronunciation[j - 1]) {
234234
pronunciationOperations.insert(pronunciationOperations.begin(),
235-
{sourcePronunciation[i - 1], targetPronunciation[j - 1]});
236-
textOperations.insert(textOperations.begin(), {referenceTextTokens[i - 1], searchText[j - 1]});
235+
{targetPronunciation[j - 1], targetPronunciation[j - 1]});
236+
textOperations.insert(textOperations.begin(), {referenceTextTokens[i - 1], referenceTextTokens[i - 1]});
237237
i--;
238238
j--;
239239
} else {
@@ -282,15 +282,21 @@ namespace LyricFA {
282282
const auto &pOp = pronOps[idx];
283283
const auto &tOp = textOps[idx];
284284

285-
if (!pOp.original.empty() && !pOp.modified.empty() && pOp.original != pOp.modified) {
286-
alignedPronunciation.push_back(pOp.modified);
287-
alignedText.push_back(tOp.modified);
285+
if (pOp.original == pOp.modified) {
286+
// 匹配操作:添加参考文本和参考发音
287+
alignedText.push_back(tOp.original);
288+
alignedPronunciation.push_back(pOp.original);
288289
} else if (pOp.original.empty() && !pOp.modified.empty()) {
289-
alignedPronunciation.push_back(pOp.modified);
290+
// 插入操作:添加目标文本和目标发音
290291
alignedText.push_back(tOp.modified);
291-
} else if (!pOp.original.empty() && pOp.modified.empty()) {
292292
alignedPronunciation.push_back(pOp.modified);
293-
alignedText.push_back(tOp.modified);
293+
} else if (!pOp.original.empty() && pOp.modified.empty()) {
294+
// 删除操作:跳过,不添加
295+
// 什么也不做
296+
} else if (!pOp.original.empty() && !pOp.modified.empty()) {
297+
// 替换操作:添加参考文本和参考发音
298+
alignedText.push_back(tOp.original);
299+
alignedPronunciation.push_back(pOp.original);
294300
}
295301
}
296302

src/apps/LyricFA/util/MatchLyric.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,25 @@ namespace LyricFA {
8484
const auto lyricName = filename.left(filename.lastIndexOf('_'));
8585

8686
if (m_lyricDict.contains(lyricName)) {
87-
const auto asr_list = get_lyrics_from_txt(labPath);
88-
if (asr_list.isEmpty()) {
87+
const auto asr_list = get_lyrics_from_txt(labPath).toUtf8().toStdString();
88+
if (asr_list.empty()) {
8989
msg = "filename: Asr res is empty.";
9090
return false;
9191
}
9292
const auto textList = m_lyricDict[lyricName].text;
9393
const auto pinyinList = m_lyricDict[lyricName].pinyin;
9494

95-
const auto asrTextU16str = Pinyin::utf8strToU16str(asr_list.toUtf8().toStdString());
95+
const auto asrTextU16str = Pinyin::utf8strToU16str(asr_list);
9696
const auto asrTextVecU16str = splitString(asrTextU16str);
9797

98-
std::vector<std::string> asrTextVec(asrTextVecU16str.size());
98+
std::vector<std::string> asrTextVec;
9999
for (const auto &item : asrTextVecU16str) {
100-
asrTextVec.push_back(Pinyin::u16strToUtf8str(item.c_str()));
100+
if (!item.empty())
101+
asrTextVec.push_back(Pinyin::u16strToUtf8str(item.c_str()));
101102
}
102103

103-
const auto asrG2pRes = m_mandarin->hanziToPinyin(asr_list.toUtf8().toStdString(), Pinyin::ManTone::NORMAL,
104-
Pinyin::Error::Default, false, true);
104+
const auto asrG2pRes =
105+
m_mandarin->hanziToPinyin(asrTextVec, Pinyin::ManTone::NORMAL, Pinyin::Error::Default, false, true);
105106

106107
std::vector<std::string> asrPinyins;
107108
for (const auto &item : asrG2pRes)
@@ -139,7 +140,7 @@ namespace LyricFA {
139140
if (asrPinyins != match_pinyin && !pinyin_step.empty()) {
140141
msg += "\n";
141142
msg += "filename: " + filename + "\n";
142-
msg += "asr_lab: " + LyricAligner::join(asrPinyins, " ") + "\n";
143+
msg += "asr_lab: " + LyricAligner::join(asrTextVec, " ") + "\n";
143144
msg += "text_res: " + LyricAligner::join(match_text, " ") + "\n";
144145
msg += "pyin_res: " + LyricAligner::join(match_pinyin, " ") + "\n";
145146
msg += "text_step: " + text_step + "\n";

0 commit comments

Comments
 (0)