Skip to content

Commit 65c5c77

Browse files
committed
fixed a tts parsing bug
1 parent 60308ed commit 65c5c77

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

otherarch/tts_adapter.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,14 @@ static std::string process_text(const std::string & text, TTS_VER ver) {
336336
std::transform(processed_text.begin(), processed_text.end(),
337337
processed_text.begin(), ::tolower);
338338

339+
// replace multiple punctuation with single
340+
processed_text = std::regex_replace(processed_text, std::regex(R"(([,.!?])\1+)"), "$1");
341+
//handle words connected by periods, replace the matches with " dot ".
342+
processed_text = std::regex_replace(processed_text, std::regex(R"((\S)\.(\S))"), "$1 dot $2");
343+
339344
if(ver==TTS_VER_2)
340345
{
341-
std::regex special_chars(R"([-_/,\.\\])");
346+
std::regex special_chars(R"([\(\)\[\]\{\}\:-_/,\.\\])");
342347
processed_text = std::regex_replace(processed_text, special_chars, " ");
343348
std::regex non_alpha(R"([^a-z\s])");
344349
processed_text = std::regex_replace(processed_text, non_alpha, "");
@@ -347,7 +352,7 @@ static std::string process_text(const std::string & text, TTS_VER ver) {
347352
processed_text = std::regex_replace(processed_text, std::regex(R"(^\s+|\s+$)"), "");
348353
processed_text = std::regex_replace(processed_text, std::regex(R"(\s)"), "<|text_sep|>");
349354
} else {
350-
std::regex special_chars(R"([-_/\\])");
355+
std::regex special_chars(R"([\(\)\[\]\{\}\:-_/\\])");
351356
processed_text = std::regex_replace(processed_text, special_chars, " ");
352357
std::regex non_alpha(R"([^a-z\s.,?!])");
353358
processed_text = std::regex_replace(processed_text, non_alpha, "");
@@ -647,11 +652,12 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
647652

648653
// convert the input text into the necessary format expected by OuteTTS
649654
std::string prompt_clean = process_text(prompt,ttsver);
655+
bool empty_check = (process_text(prompt,TTS_VER_2).size()==0); //if there is no audio, will crash, so prevent that
650656

651657
//further clean it by keeping only the last 300 words
652658
prompt_clean = trim_words(prompt_clean,(ttsver==TTS_VER_3?"<|space|>":"<|text_sep|>"),300);
653659

654-
if(prompt_clean.size()==0)
660+
if(empty_check)
655661
{
656662
//no input
657663
if(!inputs.quiet)

0 commit comments

Comments
 (0)