77
88namespace HFA {
99
10- Phoneme::Phoneme (const float start, const float end, const std::string &text)
10+ Phone::Phone (const float start, const float end, const std::string &text)
1111 : start(std::max(0 .0f , start)), end(end), text(text) {
1212 if (!(this ->start < this ->end )) {
13- const std::string error_msg = " Phoneme Invalid: text=" + text + " start=" + std::to_string (this ->start ) +
13+ const std::string error_msg = " Phone Invalid: text=" + text + " start=" + std::to_string (this ->start ) +
1414 " , end=" + std::to_string (this ->end );
1515 throw std::runtime_error (error_msg);
1616 }
1717 }
1818
19- Word::Word (const float start, const float end, const std::string &text, const bool init_phoneme )
19+ Word::Word (const float start, const float end, const std::string &text, const bool init_phone )
2020 : start(std::max(0 .0f , start)), end(end), text(text) {
2121 if (!(this ->start < this ->end )) {
2222 const std::string error_msg = " Word Invalid: text=" + text + " start=" + std::to_string (this ->start ) +
2323 " , end=" + std::to_string (this ->end );
2424 throw std::runtime_error (error_msg);
2525 }
2626
27- if (init_phoneme ) {
28- phonemes .emplace_back (this ->start , this ->end , this ->text );
27+ if (init_phone ) {
28+ phones .emplace_back (this ->start , this ->end , this ->text );
2929 }
3030 }
3131
3232 float Word::dur () const {
3333 return end - start;
3434 }
3535
36- void Word::add_phoneme (const Phoneme &phoneme ) {
37- if (phoneme .start == phoneme .end ) {
38- const std::string warning_msg = phoneme .text + " phoneme长度为0 ,非法" ;
36+ void Word::add_phone (const Phone &phone ) {
37+ if (phone .start == phone .end ) {
38+ const std::string warning_msg = phone .text + " phone长度为0 ,非法" ;
3939 _add_log (" WARNING: " + warning_msg);
4040 return ;
4141 }
42- if (phoneme .start >= start && phoneme .end <= end) {
43- phonemes .push_back (phoneme );
42+ if (phone .start >= start && phone .end <= end) {
43+ phones .push_back (phone );
4444 } else {
45- const std::string warning_msg = phoneme .text + " : phoneme边界超出word ,添加失败" ;
45+ const std::string warning_msg = phone .text + " : phone边界超出word ,添加失败" ;
4646 _add_log (" WARNING: " + warning_msg);
4747 }
4848 }
4949
50- void Word::append_phoneme (const Phoneme &phoneme ) {
51- if (phoneme .start == phoneme .end ) {
52- const std::string warning_msg = phoneme .text + " phoneme长度为0 ,非法" ;
50+ void Word::append_phone (const Phone &phone ) {
51+ if (phone .start == phone .end ) {
52+ const std::string warning_msg = phone .text + " phone长度为0 ,非法" ;
5353 _add_log (" WARNING: " + warning_msg);
5454 return ;
5555 }
5656
57- if (phonemes .empty ()) {
58- if (std::abs (phoneme .start - start) < 1e-6 ) {
59- phonemes .push_back (phoneme );
60- end = phoneme .end ;
57+ if (phones .empty ()) {
58+ if (std::abs (phone .start - start) < 1e-6 ) {
59+ phones .push_back (phone );
60+ end = phone .end ;
6161 } else {
62- const std::string warning_msg = phoneme .text + " : phoneme左边界超出word ,添加失败" ;
62+ const std::string warning_msg = phone .text + " : phone左边界超出word ,添加失败" ;
6363 _add_log (" WARNING: " + warning_msg);
6464 }
6565 } else {
66- if (std::abs (phoneme .start - phonemes .back ().end ) < 1e-6 ) {
67- phonemes .push_back (phoneme );
68- end = phoneme .end ;
66+ if (std::abs (phone .start - phones .back ().end ) < 1e-6 ) {
67+ phones .push_back (phone );
68+ end = phone .end ;
6969 } else {
70- const std::string warning_msg = phoneme .text + " : phoneme添加失败 " ;
70+ const std::string warning_msg = phone .text + " : phone添加失败 " ;
7171 _add_log (" WARNING: " + warning_msg);
7272 }
7373 }
7474 }
7575
7676 void Word::move_start (float new_start) {
7777 new_start = std::max (0 .0f , new_start);
78- if (0 <= new_start && new_start < phonemes [0 ].end ) {
78+ if (0 <= new_start && new_start < phones [0 ].end ) {
7979 start = new_start;
80- phonemes [0 ].start = new_start;
80+ phones [0 ].start = new_start;
8181 } else {
8282 const std::string warning_msg = text + " : start >= first_phone_end,无法调整word边界" ;
8383 _add_log (" WARNING: " + warning_msg);
@@ -86,9 +86,9 @@ namespace HFA {
8686
8787 void Word::move_end (float new_end) {
8888 new_end = std::max (0 .0f , new_end);
89- if (new_end > phonemes .back ().start && new_end >= 0 ) {
89+ if (new_end > phones .back ().start && new_end >= 0 ) {
9090 end = new_end;
91- phonemes .back ().end = new_end;
91+ phones .back ().end = new_end;
9292 } else {
9393 const std::string warning_msg = text + " : new_end <= first_phone_start,无法调整word边界" ;
9494 _add_log (" WARNING: " + warning_msg);
@@ -165,7 +165,7 @@ namespace HFA {
165165 }
166166
167167 void WordList::append (const Word &word) {
168- if (word.phonemes .empty ()) {
168+ if (word.phones .empty ()) {
169169 const std::string warning_msg = word.text + " : phones为空,非法word" ;
170170 _add_log (" WARNING: " + warning_msg);
171171 return ;
@@ -186,8 +186,8 @@ namespace HFA {
186186
187187 void WordList::add_AP (const Word &new_word, float min_dur) {
188188 try {
189- if (new_word.phonemes .empty ()) {
190- const std::string warning_msg = new_word.text + " phonemes为空 ,非法word" ;
189+ if (new_word.phones .empty ()) {
190+ const std::string warning_msg = new_word.text + " phones为空 ,非法word" ;
191191 _add_log (" WARNING: " + warning_msg);
192192 return ;
193193 }
@@ -311,10 +311,10 @@ namespace HFA {
311311 }
312312 }
313313
314- std::vector<std::string> WordList::phonemes () const {
314+ std::vector<std::string> WordList::phones () const {
315315 std::vector<std::string> result;
316316 for (const auto &word : words_) {
317- for (const auto &ph : word.phonemes ) {
317+ for (const auto &ph : word.phones ) {
318318 result.push_back (ph.text );
319319 }
320320 }
@@ -332,10 +332,10 @@ namespace HFA {
332332
333333 void WordList::clear_language_prefix () {
334334 for (auto &word : words_) {
335- for (auto &phoneme : word.phonemes ) {
336- const size_t pos = phoneme .text .find_last_of (' /' );
335+ for (auto &phone : word.phones ) {
336+ const size_t pos = phone .text .find_last_of (' /' );
337337 if (pos != std::string::npos) {
338- phoneme .text = phoneme .text .substr (pos + 1 );
338+ phone .text = phone .text .substr (pos + 1 );
339339 }
340340 }
341341 }
@@ -357,44 +357,43 @@ namespace HFA {
357357 return false ;
358358 }
359359
360- if (word.phonemes .empty ()) {
361- const std::string warning_msg = " Word '" + word.text + " ' has no phonemes " ;
360+ if (word.phones .empty ()) {
361+ const std::string warning_msg = " Word '" + word.text + " ' has no phones " ;
362362 _add_log (" WARNING: " + warning_msg);
363363 return false ;
364364 }
365365
366- if (std::abs (word.phonemes [0 ].start - word.start ) > 1e-6 ) {
367- const std::string warning_msg = " Word '" + word.text + " ' first phoneme start(" +
368- std::to_string (word.phonemes [0 ].start ) + " ) != word start(" +
366+ if (std::abs (word.phones [0 ].start - word.start ) > 1e-6 ) {
367+ const std::string warning_msg = " Word '" + word.text + " ' first phone start(" +
368+ std::to_string (word.phones [0 ].start ) + " ) != word start(" +
369369 std::to_string (word.start ) + " )" ;
370370 _add_log (" WARNING: " + warning_msg);
371371 return false ;
372372 }
373373
374- if (std::abs (word.phonemes .back ().end - word.end ) > 1e-6 ) {
375- const std::string warning_msg = " Word '" + word.text + " ' last phoneme end(" +
376- std::to_string (word.phonemes .back ().end ) + " ) != word end(" +
374+ if (std::abs (word.phones .back ().end - word.end ) > 1e-6 ) {
375+ const std::string warning_msg = " Word '" + word.text + " ' last phone end(" +
376+ std::to_string (word.phones .back ().end ) + " ) != word end(" +
377377 std::to_string (word.end ) + " )" ;
378378 _add_log (" WARNING: " + warning_msg);
379379 return false ;
380380 }
381381
382- for (size_t j = 0 ; j < word.phonemes .size (); j++) {
383- if (!(word.phonemes [j].start < word.phonemes [j].end )) {
382+ for (size_t j = 0 ; j < word.phones .size (); j++) {
383+ if (!(word.phones [j].start < word.phones [j].end )) {
384384 const std::string warning_msg =
385- " Word '" + word.text + " ' phoneme '" + word.phonemes [j].text +
386- " ' has invalid time order: start=" + std::to_string (word.phonemes [j].start ) +
387- " , end=" + std::to_string (word.phonemes [j].end );
385+ " Word '" + word.text + " ' phone '" + word.phones [j].text +
386+ " ' has invalid time order: start=" + std::to_string (word.phones [j].start ) +
387+ " , end=" + std::to_string (word.phones [j].end );
388388 _add_log (" WARNING: " + warning_msg);
389389 return false ;
390390 }
391391
392- if (j < word.phonemes .size () - 1 &&
393- std::abs (word.phonemes [j].end - word.phonemes [j + 1 ].start ) > 1e-6 ) {
394- const std::string warning_msg = " Word '" + word.text + " ' phoneme '" + word.phonemes [j].text +
395- " ' end(" + std::to_string (word.phonemes [j].end ) +
396- " ) != next phoneme '" + word.phonemes [j + 1 ].text + " ' start(" +
397- std::to_string (word.phonemes [j + 1 ].start ) + " )" ;
392+ if (j < word.phones .size () - 1 && std::abs (word.phones [j].end - word.phones [j + 1 ].start ) > 1e-6 ) {
393+ const std::string warning_msg = " Word '" + word.text + " ' phone '" + word.phones [j].text +
394+ " ' end(" + std::to_string (word.phones [j].end ) +
395+ " ) != next phone '" + word.phones [j + 1 ].text + " ' start(" +
396+ std::to_string (word.phones [j + 1 ].start ) + " )" ;
398397 _add_log (" WARNING: " + warning_msg);
399398 return false ;
400399 }
0 commit comments