From 2552e8559e032329b9ccb02ee7331786d5a57a77 Mon Sep 17 00:00:00 2001 From: leso-kn Date: Tue, 11 Jul 2023 17:07:01 +0200 Subject: [PATCH] Allow to link against upstream espeak-ng --- CMakeLists.txt | 1 + src/phonemize.cpp | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db9add7..dd86a34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ target_link_directories( target_link_libraries( piper_phonemize ${ESPEAK_NG_LIBRARIES} + libespeak-ng.a onnxruntime ) diff --git a/src/phonemize.cpp b/src/phonemize.cpp index 2df0d4a..13c856b 100644 --- a/src/phonemize.cpp +++ b/src/phonemize.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -8,6 +9,21 @@ #include "phonemize.hpp" #include "uni_algo.h" +#ifdef __GLIBC__ +#define OFFSET_CLAUSE_TERMINATOR (8 + sizeof(int)) +#else +#define OFFSET_CLAUSE_TERMINATOR sizeof(int) +#endif + +typedef struct { + int clause_terminator() { + // get memory address of espeak::Translator->clause_terminator field + return *(int*)((unsigned long)(this + malloc_usable_size(this) - OFFSET_CLAUSE_TERMINATOR) & -8); + } +} Translator; + +extern Translator *translator; + namespace piper { // language -> phoneme -> [phoneme, ...] @@ -39,10 +55,12 @@ void phonemize_eSpeak(std::string text, eSpeakPhonemeConfig &config, while (inputTextPointer != NULL) { // Modified espeak-ng API to get access to clause terminator - std::string clausePhonemes(espeak_TextToPhonemesWithTerminator( + std::string clausePhonemes(espeak_TextToPhonemes( (const void **)&inputTextPointer, /*textmode*/ espeakCHARS_AUTO, - /*phonememode = IPA*/ 0x02, &terminator)); + /*phonememode = IPA*/ 0x02)); + + terminator = translator->clause_terminator(); // Decompose, e.g. "ç" -> "c" + "̧" auto phonemesNorm = una::norm::to_nfd_utf8(clausePhonemes);