diff --git a/demos/TTSArmLinux/src/main.cc b/demos/TTSArmLinux/src/main.cc index 5215b3bf5..f3bd0f7b0 100644 --- a/demos/TTSArmLinux/src/main.cc +++ b/demos/TTSArmLinux/src/main.cc @@ -38,8 +38,8 @@ int main(int argc, char *argv[]) { /////////////////////////// 前端:文本转音素 /////////////////////////// // 实例化文本前端引擎 - speechnn::FrontEngineInterface *front_inst = nullptr; - front_inst = new speechnn::FrontEngineInterface(FLAGS_front_conf); + ppspeech::FrontEngineInterface *front_inst = nullptr; + front_inst = new ppspeech::FrontEngineInterface(FLAGS_front_conf); if ((!front_inst) || (front_inst->init())) { LOG(ERROR) << "Creater tts engine failed!"; if (front_inst != nullptr) { @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) { return -1; } - std::wstring ws_sentence = speechnn::utf8string2wstring(FLAGS_sentence); + std::wstring ws_sentence = ppspeech::utf8string2wstring(FLAGS_sentence); // 繁体转简体 std::wstring sentence_simp; @@ -70,9 +70,9 @@ int main(int argc, char *argv[]) { LOG(INFO) << "Start to get the phoneme and tone id sequence of each sentence"; for(int i = 0; i < sentence_part.size(); i++) { - LOG(INFO) << "Raw sentence is: " << speechnn::wstring2utf8string(sentence_part[i]); + LOG(INFO) << "Raw sentence is: " << ppspeech::wstring2utf8string(sentence_part[i]); front_inst->SentenceNormalize(sentence_part[i]); - s_sentence = speechnn::wstring2utf8string(sentence_part[i]); + s_sentence = ppspeech::wstring2utf8string(sentence_part[i]); LOG(INFO) << "After normalization sentence is: " << s_sentence; if (0 != front_inst->GetSentenceIds(s_sentence, phoneids, toneids)) { diff --git a/demos/TTSCppFrontend/front_demo/front_demo.cpp b/demos/TTSCppFrontend/front_demo/front_demo.cpp index 84a43b1d8..e943fd6f7 100644 --- a/demos/TTSCppFrontend/front_demo/front_demo.cpp +++ b/demos/TTSCppFrontend/front_demo/front_demo.cpp @@ -13,8 +13,8 @@ DEFINE_string(front_conf, "./front_demo/front.conf", "Front conf file"); int main(int argc, char** argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); // 实例化文本前端引擎 - speechnn::FrontEngineInterface *front_inst = nullptr; - front_inst = new speechnn::FrontEngineInterface(FLAGS_front_conf); + ppspeech::FrontEngineInterface *front_inst = nullptr; + front_inst = new ppspeech::FrontEngineInterface(FLAGS_front_conf); if ((!front_inst) || (front_inst->init())) { LOG(ERROR) << "Creater tts engine failed!"; if (front_inst != nullptr) { @@ -24,7 +24,7 @@ int main(int argc, char** argv) { return -1; } - std::wstring ws_sentence = speechnn::utf8string2wstring(FLAGS_sentence); + std::wstring ws_sentence = ppspeech::utf8string2wstring(FLAGS_sentence); // 繁体转简体 std::wstring sentence_simp; @@ -45,9 +45,9 @@ int main(int argc, char** argv) { LOG(INFO) << "Start to get the phoneme and tone id sequence of each sentence"; for(int i = 0; i < sentence_part.size(); i++) { - LOG(INFO) << "Raw sentence is: " << speechnn::wstring2utf8string(sentence_part[i]); + LOG(INFO) << "Raw sentence is: " << ppspeech::wstring2utf8string(sentence_part[i]); front_inst->SentenceNormalize(sentence_part[i]); - s_sentence = speechnn::wstring2utf8string(sentence_part[i]); + s_sentence = ppspeech::wstring2utf8string(sentence_part[i]); LOG(INFO) << "After normalization sentence is: " << s_sentence; if (0 != front_inst->GetSentenceIds(s_sentence, phoneids, toneids)) { diff --git a/demos/TTSCppFrontend/src/base/type_conv.cpp b/demos/TTSCppFrontend/src/base/type_conv.cpp index 19fef3fdb..5d5de43c5 100644 --- a/demos/TTSCppFrontend/src/base/type_conv.cpp +++ b/demos/TTSCppFrontend/src/base/type_conv.cpp @@ -1,6 +1,6 @@ #include "base/type_conv.h" -namespace speechnn { +namespace ppspeech { // wstring to string std::string wstring2utf8string(const std::wstring& str) { diff --git a/demos/TTSCppFrontend/src/base/type_conv.h b/demos/TTSCppFrontend/src/base/type_conv.h index 36784c1a2..9acb7a6d2 100644 --- a/demos/TTSCppFrontend/src/base/type_conv.h +++ b/demos/TTSCppFrontend/src/base/type_conv.h @@ -6,7 +6,7 @@ #include -namespace speechnn { +namespace ppspeech { // wstring to string std::string wstring2utf8string(const std::wstring& str); diff --git a/demos/TTSCppFrontend/src/front/front_interface.cpp b/demos/TTSCppFrontend/src/front/front_interface.cpp index 674f3b38f..5b828ac1b 100644 --- a/demos/TTSCppFrontend/src/front/front_interface.cpp +++ b/demos/TTSCppFrontend/src/front/front_interface.cpp @@ -1,6 +1,6 @@ #include "front/front_interface.h" -namespace speechnn { +namespace ppspeech { int FrontEngineInterface::init() { if (_initialed) { @@ -141,12 +141,12 @@ int FrontEngineInterface::Trand2Simp(const std::wstring &sentence, std::wstring //sentence_simp = sentence; for(int i = 0; i < sentence.length(); i++) { std::wstring temp(1, sentence[i]); - std::string sigle_word = speechnn::wstring2utf8string(temp); + std::string sigle_word = ppspeech::wstring2utf8string(temp); // 单个字是否在繁转简的字典里 if(trand_simp_map.find(sigle_word) == trand_simp_map.end()) { sentence_simp += temp; } else { - sentence_simp += (speechnn::utf8string2wstring(trand_simp_map[sigle_word])); + sentence_simp += (ppspeech::utf8string2wstring(trand_simp_map[sigle_word])); } } @@ -323,7 +323,7 @@ bool FrontEngineInterface::AllToneThree(const std::vector &finals) // 判断词是否是叠词 bool FrontEngineInterface::IsReduplication(const std::string &word) { bool flags = false; - std::wstring word_wstr = speechnn::utf8string2wstring(word); + std::wstring word_wstr = ppspeech::utf8string2wstring(word); int len = word_wstr.length(); if(len == 2 && word_wstr[0] == word_wstr[1]){ flags = true; @@ -355,7 +355,7 @@ int FrontEngineInterface::GetInitialsFinals(const std::string &word, std::vector } } - assert(word_finals.size() == speechnn::utf8string2wstring(word).length() && word_finals.size() == word_initials.size()); + assert(word_finals.size() == ppspeech::utf8string2wstring(word).length() && word_finals.size() == word_initials.size()); return 0; } @@ -372,7 +372,7 @@ int FrontEngineInterface::GetFinals(const std::string &word, std::vector &wordvec) { - std::wstring word_wstr = speechnn::utf8string2wstring(word); + std::wstring word_wstr = ppspeech::utf8string2wstring(word); for(int i = 0; i < word_wstr.length(); i++) { std::wstring word_sigle(1, word_wstr[i]); wordvec.push_back(word_sigle); @@ -525,7 +525,7 @@ std::vector> FrontEngineInterface::MergeThre if(i - 1 >= 0 && AllToneThree(finals[i - 1]) && AllToneThree(finals[i]) && !merge_last[i - 1]) { // if the last word is reduplication, not merge, because reduplication need to be _neural_sandhi if(!IsReduplication(seg_result[i - 1].first) && - (speechnn::utf8string2wstring(seg_result[i - 1].first)).length() + (speechnn::utf8string2wstring(word)).length() <= 3) { + (ppspeech::utf8string2wstring(seg_result[i - 1].first)).length() + (ppspeech::utf8string2wstring(word)).length() <= 3) { result.back().first = result.back().first + seg_result[i].first; merge_last[i] = true; } else { @@ -583,7 +583,7 @@ std::vector> FrontEngineInterface::MergeThre !finals[i].empty() && absl::EndsWith(finals[i].front(), "3") == true && !merge_last[i - 1]) { // if the last word is reduplication, not merge, because reduplication need to be _neural_sandhi if(!IsReduplication(seg_result[i - 1].first) && - (speechnn::utf8string2wstring(seg_result[i - 1].first)).length() + speechnn::utf8string2wstring(word).length() <= 3) { + (ppspeech::utf8string2wstring(seg_result[i - 1].first)).length() + ppspeech::utf8string2wstring(word).length() <= 3) { result.back().first = result.back().first + seg_result[i].first; merge_last[i] = true; } else { @@ -680,7 +680,7 @@ int FrontEngineInterface::YiSandhi(const std::string &word, std::vector &finals) { - std::wstring word_wstr = speechnn::utf8string2wstring(word); + std::wstring word_wstr = ppspeech::utf8string2wstring(word); std::vector wordvec; // 一个词转成向量形式 if(0 != Word2WordVec(word, wordvec)) { @@ -768,7 +768,7 @@ int FrontEngineInterface::NeuralSandhi(const std::string &word, const std::strin finals.back() = finals.back().replace(finals.back().length() - 1, 1, "5"); } else { if(find(must_neural_tone_words.begin(), must_neural_tone_words.end(), word) != must_neural_tone_words.end() - || (word_num >= 2 && find(must_neural_tone_words.begin(), must_neural_tone_words.end(), speechnn::wstring2utf8string(word_wstr.substr(word_num - 2))) != must_neural_tone_words.end())) { + || (word_num >= 2 && find(must_neural_tone_words.begin(), must_neural_tone_words.end(), ppspeech::wstring2utf8string(word_wstr.substr(word_num - 2))) != must_neural_tone_words.end())) { finals.back() = finals.back().replace(finals.back().length() - 1, 1, "5"); } } @@ -782,16 +782,16 @@ int FrontEngineInterface::NeuralSandhi(const std::string &word, const std::strin // 创建对应的 韵母列表 std::vector> finals_list; std::vector finals_temp; - finals_temp.assign(finals.begin(), finals.begin() + speechnn::utf8string2wstring(word_list[0]).length()); + finals_temp.assign(finals.begin(), finals.begin() + ppspeech::utf8string2wstring(word_list[0]).length()); finals_list.push_back(finals_temp); - finals_temp.assign(finals.begin() + speechnn::utf8string2wstring(word_list[0]).length(), finals.end()); + finals_temp.assign(finals.begin() + ppspeech::utf8string2wstring(word_list[0]).length(), finals.end()); finals_list.push_back(finals_temp); finals = {}; for(int i = 0; i < word_list.size(); i++) { - std::wstring temp_wstr = speechnn::utf8string2wstring(word_list[i]); + std::wstring temp_wstr = ppspeech::utf8string2wstring(word_list[i]); if((find(must_neural_tone_words.begin(), must_neural_tone_words.end(), word_list[i]) != must_neural_tone_words.end()) - || (temp_wstr.length() >= 2 && find(must_neural_tone_words.begin(), must_neural_tone_words.end(), speechnn::wstring2utf8string(temp_wstr.substr(temp_wstr.length() - 2))) != must_neural_tone_words.end())) { + || (temp_wstr.length() >= 2 && find(must_neural_tone_words.begin(), must_neural_tone_words.end(), ppspeech::wstring2utf8string(temp_wstr.substr(temp_wstr.length() - 2))) != must_neural_tone_words.end())) { finals_list[i].back() = finals_list[i].back().replace(finals_list[i].back().length() - 1, 1, "5"); } finals.insert(finals.end(), finals_list[i].begin(), finals_list[i].end()); @@ -801,7 +801,7 @@ int FrontEngineInterface::NeuralSandhi(const std::string &word, const std::strin } int FrontEngineInterface::ThreeSandhi(const std::string &word, std::vector &finals) { - std::wstring word_wstr = speechnn::utf8string2wstring(word); + std::wstring word_wstr = ppspeech::utf8string2wstring(word); std::vector> finals_list; std::vector finals_temp; std::vector wordvec; @@ -823,7 +823,7 @@ int FrontEngineInterface::ThreeSandhi(const std::string &word, std::vector> FrontEngineInterface::MergeErhua(const std std::vector new_finals = {}; std::vector> new_initials_finals; std::vector specified_pos = {"a", "j", "nr"}; - std::wstring word_wstr = speechnn::utf8string2wstring(word); + std::wstring word_wstr = ppspeech::utf8string2wstring(word); std::vector wordvec; // 一个词转成向量形式 if(0 != Word2WordVec(word, wordvec)) { @@ -915,7 +915,7 @@ std::vector> FrontEngineInterface::MergeErhua(const std assert(finals.size() == word_num); for(int i = 0; i < finals.size(); i++) { if(i == finals.size() - 1 && wordvec[i] == L"儿" && (finals[i] == "er2" || finals[i] == "er5") && word_num >= 2 && - find(not_erhua.begin(), not_erhua.end(), speechnn::wstring2utf8string(word_wstr.substr(word_wstr.length() - 2))) == not_erhua.end() && !new_finals.empty()) { + find(not_erhua.begin(), not_erhua.end(), ppspeech::wstring2utf8string(word_wstr.substr(word_wstr.length() - 2))) == not_erhua.end() && !new_finals.empty()) { new_finals.back() = new_finals.back().substr(0, new_finals.back().length()-1) + "r" + new_finals.back().substr(new_finals.back().length()-1); } else { new_initials.push_back(initials[i]); diff --git a/demos/TTSCppFrontend/src/front/front_interface.h b/demos/TTSCppFrontend/src/front/front_interface.h index f99fd0c77..8df026c8d 100644 --- a/demos/TTSCppFrontend/src/front/front_interface.h +++ b/demos/TTSCppFrontend/src/front/front_interface.h @@ -12,7 +12,7 @@ #include "absl/strings/str_split.h" -namespace speechnn { +namespace ppspeech { class FrontEngineInterface : public TextNormalizer{ public: diff --git a/demos/TTSCppFrontend/src/front/text_normalize.cpp b/demos/TTSCppFrontend/src/front/text_normalize.cpp index 6d9efe7e4..11a493ba9 100644 --- a/demos/TTSCppFrontend/src/front/text_normalize.cpp +++ b/demos/TTSCppFrontend/src/front/text_normalize.cpp @@ -1,6 +1,6 @@ #include "front/text_normalize.h" -namespace speechnn { +namespace ppspeech { // 初始化 digits_map and unit_map int TextNormalizer::InitMap() { diff --git a/demos/TTSCppFrontend/src/front/text_normalize.h b/demos/TTSCppFrontend/src/front/text_normalize.h index 4646cd72b..20d502b82 100644 --- a/demos/TTSCppFrontend/src/front/text_normalize.h +++ b/demos/TTSCppFrontend/src/front/text_normalize.h @@ -10,7 +10,7 @@ #include "absl/strings/strip.h" #include "base/type_conv.h" -namespace speechnn { +namespace ppspeech { class TextNormalizer { public: