Skip to content

Commit

Permalink
Allow to link against upstream espeak-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
leso-kn committed Jul 11, 2023
1 parent 244657a commit 2552e85
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ target_link_directories(
target_link_libraries(
piper_phonemize
${ESPEAK_NG_LIBRARIES}
libespeak-ng.a
onnxruntime
)

Expand Down
22 changes: 20 additions & 2 deletions src/phonemize.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <malloc.h>
#include <map>
#include <string>
#include <vector>
Expand All @@ -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, ...]
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2552e85

Please sign in to comment.