Skip to content

Commit eb357aa

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents d72edd8 + a9ab94b commit eb357aa

3 files changed

Lines changed: 15 additions & 20 deletions

File tree

src/apps/LyricFA/util/Asr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ namespace LyricFA {
5555

5656
sf.seek(beginFrame, SEEK_SET);
5757
std::vector<float> tmp(frameCount);
58-
const auto bytesWritten = sf.read(tmp.data(), static_cast<sf_count_t>(tmp.size()));
5958

60-
if (bytesWritten > 60 * 16000) {
59+
if (const auto bytesWritten = sf.read(tmp.data(), static_cast<sf_count_t>(tmp.size()));
60+
bytesWritten > 60 * 16000) {
6161
msg = "The audio contains continuous pronunciation segments that exceed 60 seconds. Please manually "
6262
"segment and rerun the recognition program.";
6363
return false;

src/apps/LyricFA/util/AsrThread.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ namespace LyricFA {
1313

1414
void AsrThread::run() {
1515
std::string asrMsg;
16-
const auto asrRes = m_asr->recognize(m_wavPath.toLocal8Bit().toStdString(), asrMsg);
1716

18-
if (!asrRes) {
17+
if (const auto asrRes = m_asr->recognize(m_wavPath.toLocal8Bit().toStdString(), asrMsg); !asrRes) {
1918
Q_EMIT this->oneFailed(m_filename, QString::fromStdString(asrMsg));
2019
return;
2120
}
@@ -28,7 +27,7 @@ namespace LyricFA {
2827
}
2928

3029
QTextStream labIn(&labFile);
31-
if (m_g2p) {
30+
if (m_g2p != nullptr) {
3231
const auto g2pRes = m_g2p->hanziToPinyin(asrMsg, Pinyin::ManTone::NORMAL, Pinyin::Error::Default, true);
3332
asrMsg = g2pRes.toStdStr();
3433
}

src/apps/LyricFA/util/MatchLyric.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ namespace LyricFA {
2727
MatchLyric::~MatchLyric() = default;
2828

2929
static QString get_lyrics_from_txt(const QString &lyricPath) {
30-
QFile lyricFile(lyricPath);
31-
if (lyricFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
30+
if (QFile lyricFile(lyricPath); lyricFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
3231
auto words = QString::fromUtf8(lyricFile.readAll());
33-
words.remove(QRegularExpression(u8"[^\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF]"));
32+
words.remove(QRegularExpression(u8"[^\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF a-zA-Z]"));
3433
return words;
3534
}
3635
return {};
@@ -43,9 +42,8 @@ namespace LyricFA {
4342
}
4443

4544
const QJsonDocument jsonDoc(jsonObject);
46-
const QByteArray jsonData = jsonDoc.toJson();
4745

48-
if (file.write(jsonData) == -1) {
46+
if (const QByteArray jsonData = jsonDoc.toJson(); file.write(jsonData) == -1) {
4947
return false;
5048
}
5149

@@ -72,21 +70,20 @@ namespace LyricFA {
7270

7371
std::vector<std::string> textList, pinyinList;
7472
for (const auto &item : g2pRes) {
75-
textList.push_back(item.hanzi.c_str());
76-
pinyinList.push_back(item.pinyin.c_str());
73+
textList.emplace_back(item.hanzi.c_str());
74+
pinyinList.emplace_back(item.pinyin.c_str());
7775
}
7876
m_lyricDict[lyricName] = lyricInfo{textList, pinyinList};
7977
}
8078
}
8179

8280
bool MatchLyric::match(const QString &filename, const QString &labPath, const QString &jsonPath, QString &msg,
8381
const bool &asr_rectify) const {
84-
const auto lyricName = filename.left(filename.lastIndexOf('_'));
8582

86-
if (m_lyricDict.contains(lyricName)) {
83+
if (const auto lyricName = filename.left(filename.lastIndexOf('_')); m_lyricDict.contains(lyricName)) {
8784
const auto asr_list = get_lyrics_from_txt(labPath).toUtf8().toStdString();
8885
if (asr_list.empty()) {
89-
msg = "filename: Asr res is empty.";
86+
msg = QString("%1: Asr result is empty.").arg(lyricName);
9087
return false;
9188
}
9289
const auto textList = m_lyricDict[lyricName].text;
@@ -106,7 +103,7 @@ namespace LyricFA {
106103

107104
std::vector<std::string> asrPinyins;
108105
for (const auto &item : asrG2pRes)
109-
asrPinyins.push_back(item.pinyin.c_str());
106+
asrPinyins.emplace_back(item.pinyin.c_str());
110107

111108
if (!asrPinyins.empty()) {
112109
auto [match_text, match_pinyin, text_step, pinyin_step] =
@@ -117,14 +114,13 @@ namespace LyricFA {
117114
for (int i = 0; i < asrPinyins.size(); i++) {
118115
const auto asrPinyin = asrPinyins[i];
119116
const auto text = match_text[i];
120-
const auto matchPinyin = match_pinyin[i];
121117

122-
if (asrPinyin != matchPinyin) {
118+
if (const auto matchPinyin = match_pinyin[i]; asrPinyin != matchPinyin) {
123119
const std::vector<std::string> candidates =
124120
m_mandarin->getDefaultPinyin(text, Pinyin::ManTone::NORMAL, true);
125-
const auto it = std::find(candidates.begin(), candidates.end(), asrPinyin);
126121

127-
if (it != candidates.end()) {
122+
if (const auto it = std::find(candidates.begin(), candidates.end(), asrPinyin);
123+
it != candidates.end()) {
128124
asr_rect_list.push_back(asrPinyin);
129125
asr_rect_diff.push_back("(" + matchPinyin + "->" + asrPinyin + ", " + static_cast<char>(i) +
130126
")");

0 commit comments

Comments
 (0)