From 5e0cc6f5b5ab20c0c6b09caf8d5458dd51c39eed Mon Sep 17 00:00:00 2001 From: leso-kn Date: Tue, 11 Jul 2023 23:39:28 +0200 Subject: [PATCH] Allow to link against upstream espeak-ng --- src/phonemize.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/phonemize.cpp b/src/phonemize.cpp index 2df0d4a..71d68ea 100644 --- a/src/phonemize.cpp +++ b/src/phonemize.cpp @@ -35,14 +35,20 @@ void phonemize_eSpeak(std::string text, eSpeakPhonemeConfig &config, std::vector *sentencePhonemes = nullptr; const char *inputTextPointer = textCopy.c_str(); - int terminator = 0; while (inputTextPointer != NULL) { - // Modified espeak-ng API to get access to clause terminator - std::string clausePhonemes(espeak_TextToPhonemesWithTerminator( + int terminator = 0; + std::string clausePhonemes(espeak_TextToPhonemes( (const void **)&inputTextPointer, /*textmode*/ espeakCHARS_AUTO, - /*phonememode = IPA*/ 0x02, &terminator)); + /*phonememode = IPA*/ 0x02)); + + for (size_t i = -2; inputTextPointer && inputTextPointer+i > textCopy.c_str(); i--) { + if (inputTextPointer[i] != ' ') { + terminator = inputTextPointer[i]; + break; + } + } // Decompose, e.g. "ç" -> "c" + "̧" auto phonemesNorm = una::norm::to_nfd_utf8(clausePhonemes); @@ -105,22 +111,21 @@ void phonemize_eSpeak(std::string text, eSpeakPhonemeConfig &config, } // Add appropriate punctuation depending on terminator type - int punctuation = terminator & 0x000FFFFF; - if (punctuation == CLAUSE_PERIOD) { + if (terminator == '.') { sentencePhonemes->push_back(config.period); - } else if (punctuation == CLAUSE_QUESTION) { + } else if (terminator == '?') { sentencePhonemes->push_back(config.question); - } else if (punctuation == CLAUSE_EXCLAMATION) { + } else if (terminator == '!') { sentencePhonemes->push_back(config.exclamation); - } else if (punctuation == CLAUSE_COMMA) { + } else if (terminator == ',') { sentencePhonemes->push_back(config.comma); - } else if (punctuation == CLAUSE_COLON) { + } else if (terminator == ':') { sentencePhonemes->push_back(config.colon); - } else if (punctuation == CLAUSE_SEMICOLON) { + } else if (terminator == ';') { sentencePhonemes->push_back(config.semicolon); } - if ((terminator & CLAUSE_TYPE_SENTENCE) == CLAUSE_TYPE_SENTENCE) { + if (terminator == '.' || terminator == '?' || terminator == '!') { // End of sentence sentencePhonemes = nullptr; }