Using patched espeak-ng

This commit is contained in:
Michael Hansen
2023-04-13 14:18:50 -05:00
parent 5b64824eea
commit cbed19e1b4
10 changed files with 50 additions and 23 deletions
+4 -2
View File
@@ -32,8 +32,10 @@ struct eSpeakConfig {
// Characters that eSpeak uses to break apart paragraphs/sentences
set<Phoneme> clauseBreakers{U'.', U'?', U'!', U',', U';', U':'};
// Characters that piper will use to split utterances
set<Phoneme> sentenceBreakers{U'.', U'?', U'!'};
Phoneme fullStop = U'.';
Phoneme comma = U',';
Phoneme question = U'?';
Phoneme exclamation = U'!';
};
struct PhonemizeConfig {
+2 -1
View File
@@ -53,7 +53,8 @@ int main(int argc, char *argv[]) {
RunConfig runConfig;
parseArgs(argc, argv, runConfig);
auto exePath = filesystem::path(argv[0]);
// NOTE: This won't work for Windows (need GetModuleFileName)
auto exePath = filesystem::canonical("/proc/self/exe");
piper::initialize(exePath.parent_path());
piper::Voice voice;
+28 -11
View File
@@ -15,6 +15,13 @@
#include "config.hpp"
#include "utf8.h"
#define CLAUSE_INTONATION_FULL_STOP 0x00000000
#define CLAUSE_INTONATION_COMMA 0x00001000
#define CLAUSE_INTONATION_QUESTION 0x00002000
#define CLAUSE_INTONATION_EXCLAMATION 0x00003000
#define CLAUSE_TYPE_SENTENCE 0x00080000
using namespace std;
namespace piper {
@@ -54,13 +61,15 @@ void phonemize(string text, PhonemizeConfig &phonemizeConfig,
vector<Phoneme> *sentencePhonemes = nullptr;
const char *inputTextPointer = textCopy.c_str();
size_t clauseBreakerIndex = 0;
int terminator = 0;
while (inputTextPointer != NULL) {
// Modified espeak-ng API to get access to clause terminator
string clausePhonemes(
espeak_TextToPhonemes((const void **)&inputTextPointer,
espeak_TextToPhonemes2((const void **)&inputTextPointer,
/*textmode*/ espeakCHARS_AUTO,
/*phonememode = IPA*/ 0x02));
/*phonememode = IPA*/ 0x02,
&terminator));
utf8::iterator phonemeIter(clausePhonemes.begin(), clausePhonemes.begin(),
clausePhonemes.end());
@@ -74,17 +83,25 @@ void phonemize(string text, PhonemizeConfig &phonemizeConfig,
}
sentencePhonemes->insert(sentencePhonemes->end(), phonemeIter, phonemeEnd);
if (clauseBreakerIndex < textClauseBreakers.size()) {
auto clauseBreaker = textClauseBreakers[clauseBreakerIndex];
sentencePhonemes->push_back(clauseBreaker);
if (phonemizeConfig.eSpeak->sentenceBreakers.contains(clauseBreaker)) {
// Add appropriate puntuation depending on terminator type
int intonation = terminator & 0x0000F000;
if (intonation == CLAUSE_INTONATION_FULL_STOP) {
sentencePhonemes->push_back(phonemizeConfig.eSpeak->fullStop);
} else if (intonation == CLAUSE_INTONATION_COMMA) {
sentencePhonemes->push_back(phonemizeConfig.eSpeak->comma);
} else if (intonation == CLAUSE_INTONATION_QUESTION) {
sentencePhonemes->push_back(phonemizeConfig.eSpeak->question);
} else if (intonation == CLAUSE_INTONATION_EXCLAMATION) {
sentencePhonemes->push_back(phonemizeConfig.eSpeak->exclamation);
}
if ((terminator & CLAUSE_TYPE_SENTENCE) == CLAUSE_TYPE_SENTENCE) {
// End of sentence
sentencePhonemes = nullptr;
}
clauseBreakerIndex++;
}
}
} // while inputTextPointer != NULL
} /* phonemize */
+1 -1
View File
@@ -30,7 +30,7 @@ struct Voice {
void initialize(std::filesystem::path cwd) {
const char *dataPath = NULL;
auto cwdDataPath = cwd.append("espeak-ng-data");
auto cwdDataPath = std::filesystem::absolute(cwd.append("espeak-ng-data"));
if (std::filesystem::is_directory(cwdDataPath)) {
dataPath = cwdDataPath.c_str();
}