Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to link against upstream espeak-ng #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/phonemize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ void phonemize_eSpeak(std::string text, eSpeakPhonemeConfig &config,

std::vector<Phoneme> *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));

const char *remainingTextPointer = inputTextPointer ? inputTextPointer : textCopy.c_str()+textCopy.length()+1;
for (size_t i = -2; remainingTextPointer+i > textCopy.c_str(); i--) {
if ((remainingTextPointer[i]) != ' ') {
terminator = remainingTextPointer[i];
break;
}
}

// Decompose, e.g. "ç" -> "c" + "̧"
auto phonemesNorm = una::norm::to_nfd_utf8(clausePhonemes);
Expand Down Expand Up @@ -105,25 +112,24 @@ 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);
sentencePhonemes->push_back(config.space);
} else if (punctuation == CLAUSE_COLON) {
} else if (terminator == ':') {
sentencePhonemes->push_back(config.colon);
sentencePhonemes->push_back(config.space);
} else if (punctuation == CLAUSE_SEMICOLON) {
} else if (terminator == ';') {
sentencePhonemes->push_back(config.semicolon);
sentencePhonemes->push_back(config.space);
}

if ((terminator & CLAUSE_TYPE_SENTENCE) == CLAUSE_TYPE_SENTENCE) {
if (terminator == '.' || terminator == '?' || terminator == '!') {
// End of sentence
sentencePhonemes = nullptr;
}
Expand Down