@@ -59,27 +59,26 @@ static FaLayerResult buildFaLayers(const HFA::WordList &words) {
5959 r.phonemeLayer .name = QStringLiteral (" phoneme" );
6060 r.phonemeLayer .type = QStringLiteral (" interval" );
6161
62+ struct WordIds {
63+ int graphemeStartId = 0 ;
64+ std::vector<int > phoneBoundaryIds;
65+ };
66+ std::vector<WordIds> wordIdList;
6267 int nextId = 1 ;
6368
6469 for (const auto &word : words) {
6570 if (word.phones .empty ())
6671 continue ;
6772
73+ WordIds ids;
74+
6875 Boundary graphemeStart;
6976 graphemeStart.id = nextId++;
7077 graphemeStart.pos = secToUs (std::max (0 .0f , word.start ));
7178 graphemeStart.text = QString::fromStdString (word.text );
72- int graphemeStartId = graphemeStart.id ;
79+ ids. graphemeStartId = graphemeStart.id ;
7380 r.graphemeLayer .boundaries .push_back (std::move (graphemeStart));
7481
75- Boundary graphemeEnd;
76- graphemeEnd.id = nextId++;
77- graphemeEnd.pos = secToUs (std::max (0 .0f , word.end ));
78- int graphemeEndId = graphemeEnd.id ;
79- r.graphemeLayer .boundaries .push_back (std::move (graphemeEnd));
80-
81- std::vector<int > childBoundaryIds;
82-
8382 for (size_t pi = 0 ; pi < word.phones .size (); ++pi) {
8483 const auto &phone = word.phones [pi];
8584
@@ -88,28 +87,34 @@ static FaLayerResult buildFaLayers(const HFA::WordList &words) {
8887 phoneB.pos = secToUs (std::max (0 .0f , phone.start ));
8988 phoneB.text = QString::fromStdString (phone.text );
9089
91- childBoundaryIds .push_back (phoneB.id );
90+ ids. phoneBoundaryIds .push_back (phoneB.id );
9291
9392 if (pi == 0 )
94- r.groups .push_back ({graphemeStartId, phoneB.id });
93+ r.groups .push_back ({ids. graphemeStartId , phoneB.id });
9594
9695 r.phonemeLayer .boundaries .push_back (std::move (phoneB));
9796 }
9897
99- if (!word.phones .empty ()) {
100- r.groups .push_back ({graphemeEndId, r.phonemeLayer .boundaries .back ().id });
101- }
98+ wordIdList.push_back (std::move (ids));
99+ }
100+
101+ for (size_t wi = 0 ; wi < wordIdList.size (); ++wi) {
102+ const auto &ids = wordIdList[wi];
102103
103104 LayerDependency dep;
104105 dep.parentLayerName = QStringLiteral (" grapheme" );
105106 dep.childLayerName = QStringLiteral (" phoneme" );
106- dep.parentStartBoundaryId = graphemeStartId;
107- dep.parentEndBoundaryId = graphemeEndId;
108- if (!childBoundaryIds.empty ()) {
109- dep.childStartBoundaryId = childBoundaryIds.front ();
110- dep.childEndBoundaryId = childBoundaryIds.back ();
107+ dep.parentStartBoundaryId = ids.graphemeStartId ;
108+ dep.parentEndBoundaryId = (wi + 1 < wordIdList.size ())
109+ ? wordIdList[wi + 1 ].graphemeStartId
110+ : ids.graphemeStartId ;
111+
112+ if (!ids.phoneBoundaryIds .empty ()) {
113+ dep.childStartBoundaryId = ids.phoneBoundaryIds .front ();
114+ dep.childEndBoundaryId = ids.phoneBoundaryIds .back ();
115+ dep.childBoundaryIds = ids.phoneBoundaryIds ;
111116 }
112- dep. childBoundaryIds = std::move (childBoundaryIds);
117+
113118 r.dependencies .push_back (std::move (dep));
114119 }
115120
@@ -625,7 +630,6 @@ void PhonemeLabelerPage::runFaForSlice(const QString &sliceId) {
625630 }
626631 if (nonSpeechPh.empty ())
627632 nonSpeechPh = {" AP" , " SP" };
628- float wavLen = static_cast <float >(audioDurationSec (doc));
629633 DSFW_LOG_INFO (" fa" , (" FA started: " + sliceId.toStdString ()
630634 + " | audio: " + audioPath.toStdString ()
631635 + " | language: zh"
@@ -635,7 +639,7 @@ void PhonemeLabelerPage::runFaForSlice(const QString &sliceId) {
635639 auto hfaAlive = m_hfaAlive;
636640 QPointer<PhonemeLabelerPage> guard (this );
637641
638- (void ) QtConcurrent::run ([hfa, hfaAlive, audioPath, lyricsText, nonSpeechPh, sliceId, guard, wavLen ]() {
642+ (void ) QtConcurrent::run ([hfa, hfaAlive, audioPath, lyricsText, nonSpeechPh, sliceId, guard]() {
639643 if (!hfaAlive || !*hfaAlive)
640644 return ;
641645 if (!hfa)
@@ -650,11 +654,6 @@ void PhonemeLabelerPage::runFaForSlice(const QString &sliceId) {
650654 result = Err (std::string (" Exception: " ) + e.what ());
651655 }
652656
653- if (result) {
654- words.fill_small_gaps (wavLen, 0 .1f );
655- words.add_SP (wavLen, " SP" );
656- }
657-
658657 if (!guard)
659658 return ;
660659
@@ -929,14 +928,11 @@ void PhonemeLabelerPage::onBatchFA() {
929928 HFA::WordList words;
930929 std::string lyricsText = lyricsQStr.toStdString ();
931930
932- float wavLen = static_cast <float >(audioDurationSec (doc));
933931 DSFW_LOG_INFO (" fa" , (" Batch FA started: " + sliceId.toStdString ()
934932 + " | language: " + lang.toStdString ()
935933 + " | lyrics: " + lyricsText).c_str ());
936934 auto result = hfa->recognize (audioPath.toStdWString (), lang.toStdString (), nonSpeechPh, lyricsText, words);
937935 if (result) {
938- words.fill_small_gaps (wavLen, 0 .1f );
939- words.add_SP (wavLen, " SP" );
940936 auto faResult = buildFaLayers (words);
941937
942938 std::string phonemeDetail;
0 commit comments