From fe14c83372da050a136de67bb2ccf4a21edc0e5a Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 14 May 2017 11:03:33 +0100 Subject: [PATCH] Support multi-word text replacements in dictionary list files. --- CHANGELOG.md | 1 + src/libespeak-ng/translate.c | 46 ++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 649567ce..7c730978 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The espeak-ng project is a fork of the espeak project. * Use language and accent names consistently across the language files. * Group the encoding handling into a single place with a clean interface and tests. * Support all ISO 8859 encodings. +* Support for multi-word text replacements in language dictionaries. bug fixes: diff --git a/src/libespeak-ng/translate.c b/src/libespeak-ng/translate.c index d80c3029..ac9999cd 100644 --- a/src/libespeak-ng/translate.c +++ b/src/libespeak-ng/translate.c @@ -489,7 +489,7 @@ static int CheckDottedAbbrev(char *word1) extern char *phondata_ptr; -int TranslateWord(Translator *tr, char *word_start, WORD_TAB *wtab, char *word_out) +static int TranslateWord3(Translator *tr, char *word_start, WORD_TAB *wtab, char *word_out) { // word1 is terminated by space (0x20) character @@ -617,17 +617,7 @@ int TranslateWord(Translator *tr, char *word_start, WORD_TAB *wtab, char *word_o if (word_out != NULL) strcpy(word_out, word1); - first_char = word1[0]; - stress_bits = dictionary_flags[0] & 0x7f; - found = LookupDictList(tr, &word1, phonemes, dictionary_flags2, 0, wtab); // the text replacement - if (dictionary_flags2[0] != 0) { - dictionary_flags[0] = dictionary_flags2[0]; - dictionary_flags[1] = dictionary_flags2[1]; - if (stress_bits != 0) { - // keep any stress information from the original word - dictionary_flags[0] = (dictionary_flags[0] & ~0x7f) | stress_bits; - } - } + return dictionary_flags[0]; } else if ((found == 0) && (dictionary_flags[0] & FLAG_SKIPWORDS) && !(dictionary_flags[0] & FLAG_ABBREV)) { // grouped words, but no translation. Join the words with hyphens. wordx = word1; @@ -1135,6 +1125,38 @@ int TranslateWord(Translator *tr, char *word_start, WORD_TAB *wtab, char *word_o return dictionary_flags[0]; } +int TranslateWord(Translator *tr, char *word_start, WORD_TAB *wtab, char *word_out) +{ + char words_phonemes[N_WORD_PHONEMES]; // a word translated into phoneme codes + char *phonemes = words_phonemes; + int available = N_WORD_PHONEMES; + int first_word = 1; + + int flags = TranslateWord3(tr, word_start, wtab, word_out); + if (flags & FLAG_TEXTMODE && word_out) { + while (*word_out && available > 1) { + TranslateWord3(tr, word_out, wtab, NULL); + + int n; + if (first_word) { + n = snprintf(phonemes, available, "%s", word_phonemes); + first_word = 0; + } else { + n = snprintf(phonemes, available, "%c%s", phonEND_WORD, word_phonemes); + } + + available -= n; + phonemes += n; + + // skip to the next word in a multi-word replacement + while (!isspace(*word_out)) ++word_out; + while (isspace(*word_out)) ++word_out; + } + snprintf(word_phonemes, sizeof(word_phonemes), "%s", words_phonemes); + } + return flags; +} + static void SetPlist2(PHONEME_LIST2 *p, unsigned char phcode) { p->phcode = phcode;