From 0cf3ee564c3fd33fe1c1c5504a2252daf7bcfedd Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sun, 21 Feb 2021 14:54:02 +0200 Subject: [PATCH] Code cleanup: remove param2 from langopts and rename keyword option in language files. - param2[] is only used to set a second value to LOPT_BRACKET_PAUSE. It is simpler to have two values in param[] instead. This simplifies the codebase. - Instead of setting "option bracket X Y" in language files, use keywords "brackets X" and "bracketsAnnounced Y" instead to follow the naming convention of other keywords. - Add missing documentation to docs/voices.md. --- docs/voices.md | 18 ++++++++++++++++++ espeak-ng-data/lang/urj/hu | 3 ++- src/libespeak-ng/dictionary.c | 6 +++--- src/libespeak-ng/tr_languages.c | 2 +- src/libespeak-ng/translate.h | 8 +++++--- src/libespeak-ng/voices.c | 23 ++--------------------- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/docs/voices.md b/docs/voices.md index f689a108..db24eff8 100644 --- a/docs/voices.md +++ b/docs/voices.md @@ -21,6 +21,8 @@ - [speed](#speed) - [words](#words) - [Language Attributes](#language-attributes) + - [brackets](#brackets) + - [bracketsAnnounced](#bracketsAnnounced) - [phonemes](#phonemes) - [dictionary](#dictionary) - [dictrules](#dictrules) @@ -335,6 +337,22 @@ vowel and the next start with a vowel. ## Language Attributes +### brackets + + brackets + +Default value: 4 + +Increases the pause when reading brackets. Example: "Pause (with brackets)". + +### bracketsAnnounced + + bracketsAnnounced + +Default value: 2 + +Increases the pause when reading brackets when --punct is set to read bracket names. Example: "Pause (with brackets)". + ### phonemes phonemes diff --git a/espeak-ng-data/lang/urj/hu b/espeak-ng-data/lang/urj/hu index 5ece4b1b..f5bb2958 100644 --- a/espeak-ng-data/lang/urj/hu +++ b/espeak-ng-data/lang/urj/hu @@ -1,6 +1,7 @@ name Hungarian language hu -option bracket 0 0 +brackets 0 +bracketsAnnounced 0 pitch 81 117 diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index 1b914f9e..5d4d66f4 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -2309,9 +2309,9 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c // is it a bracket ? if (letter == 0xe000+'(') { - if (pre_pause < tr->langopts.param2[LOPT_BRACKET_PAUSE]) - pre_pause = tr->langopts.param2[LOPT_BRACKET_PAUSE]; // a bracket, already spoken by AnnouncePunctuation() - } + if (pre_pause < tr->langopts.param[LOPT_BRACKET_PAUSE_ANNOUNCED]) + pre_pause = tr->langopts.param[LOPT_BRACKET_PAUSE_ANNOUNCED]; // a bracket, already spoken by AnnouncePunctuation() + } if (IsBracket(letter)) { if (pre_pause < tr->langopts.param[LOPT_BRACKET_PAUSE]) pre_pause = tr->langopts.param[LOPT_BRACKET_PAUSE]; diff --git a/src/libespeak-ng/tr_languages.c b/src/libespeak-ng/tr_languages.c index 982a18ac..7ed230b1 100644 --- a/src/libespeak-ng/tr_languages.c +++ b/src/libespeak-ng/tr_languages.c @@ -291,7 +291,7 @@ static Translator *NewTranslator(void) tr->langopts.param[LOPT_MAXAMP_EOC] = 19; tr->langopts.param[LOPT_UNPRONOUNCABLE] = 's'; // don't count this character at start of word tr->langopts.param[LOPT_BRACKET_PAUSE] = 4; // pause at bracket - tr->langopts.param2[LOPT_BRACKET_PAUSE] = 2; // pauses when announcing bracket names + tr->langopts.param[LOPT_BRACKET_PAUSE_ANNOUNCED] = 2; // pauses when announcing bracket names tr->langopts.max_initial_consonants = 3; tr->langopts.replace_chars = NULL; tr->langopts.alt_alphabet_lang = L('e', 'n'); diff --git a/src/libespeak-ng/translate.h b/src/libespeak-ng/translate.h index 1437378e..d9f79b4a 100644 --- a/src/libespeak-ng/translate.h +++ b/src/libespeak-ng/translate.h @@ -285,7 +285,7 @@ typedef struct { #define AL_NOT_CODE 0x08 // don't speak the character code #define AL_NO_SYMBOL 0x10 // don't repeat "symbol" or "character" -#define N_LOPTS 21 +#define N_LOPTS 22 #define LOPT_DIERESES 1 // 1=remove [:] from unstressed syllables, 2= remove from unstressed or non-penultimate syllables // bit 4=0, if stress < 4, bit 4=1, if not the highest stress in the word @@ -339,7 +339,7 @@ typedef struct { // bit 1: stressed syllable: $alt change [e],[o] to [E],[O], $alt2 change [E],[O] to [e],[o] #define LOPT_ALT 15 -// pause for bracket (default=4), pause when announcing bracket names (default=2) +// pause for bracket (default=4), also see LOPT_BRACKET_PAUSE_ANNOUNCED #define LOPT_BRACKET_PAUSE 16 // bit 1, don't break clause before annoucning . ? ! @@ -355,6 +355,9 @@ typedef struct { // bit 1 Apostrophe at end of word is part of the word #define LOPT_APOSTROPHE 20 +// pause when announcing bracket names (default=2), also see LOPT_BRACKET_PAUSE +#define LOPT_BRACKET_PAUSE_ANNOUNCED 21 + // stress_rule #define STRESSPOSN_1L 0 // 1st syllable #define STRESSPOSN_2L 1 // 2nd syllable @@ -428,7 +431,6 @@ typedef struct { int unstressed_wd1; // stress for $u word of 1 syllable int unstressed_wd2; // stress for $u word of >1 syllable int param[N_LOPTS]; - int param2[N_LOPTS]; unsigned char *length_mods; unsigned char *length_mods0; diff --git a/src/libespeak-ng/voices.c b/src/libespeak-ng/voices.c index a7f411ec..03626559 100644 --- a/src/libespeak-ng/voices.c +++ b/src/libespeak-ng/voices.c @@ -102,7 +102,6 @@ enum { V_STRESSRULE, V_STRESSOPT, V_NUMBERS, - V_OPTION, V_MBROLA, V_KLATT, @@ -116,11 +115,6 @@ enum { V_CONSONANTS }; -static MNEM_TAB options_tab[] = { - { "bracket", LOPT_BRACKET_PAUSE }, - { NULL, -1 } -}; - static MNEM_TAB keyword_tab[] = { { "name", V_NAME }, { "language", V_LANGUAGE }, @@ -154,7 +148,6 @@ static MNEM_TAB keyword_tab[] = { { "breath", V_BREATH }, { "breathw", V_BREATHW }, { "numbers", V_NUMBERS }, - { "option", V_OPTION }, { "mbrola", V_MBROLA }, { "consonants", V_CONSONANTS }, { "klatt", V_KLATT }, @@ -170,6 +163,8 @@ static MNEM_TAB keyword_tab[] = { { "l_sonorant_min", 0x100+LOPT_SONORANT_MIN }, { "l_length_mods", 0x100+LOPT_LENGTH_MODS }, { "apostrophe", 0x100+LOPT_APOSTROPHE }, + { "brackets", 0x100+LOPT_BRACKET_PAUSE }, + { "bracketsAnnounced", 0x100+LOPT_BRACKET_PAUSE_ANNOUNCED }, { NULL, 0 } }; @@ -490,7 +485,6 @@ voice_t *LoadVoice(const char *vname, int control) int ix; int n; int value; - int value2; int langix = 0; int tone_only = control & 2; bool language_set = false; @@ -508,7 +502,6 @@ voice_t *LoadVoice(const char *vname, int control) char translator_name[40]; char new_dictionary[40]; char phonemes_name[40]; - char option_name[40]; const char *language_type; char buf[sizeof(path_home)+30]; char path_voices[sizeof(path_home)+12]; @@ -771,18 +764,6 @@ voice_t *LoadVoice(const char *vname, int control) else fprintf(stderr, "Cannot set stressrule: language not set, or is invalid.\n"); break; - case V_OPTION: - if (langopts) { - value2 = 0; - if (((sscanf(p, "%s %d %d", option_name, &value, &value2) >= 2) && ((ix = LookupMnem(options_tab, option_name)) >= 0)) || - ((sscanf(p, "%d %d %d", &ix, &value, &value2) >= 2) && (ix < N_LOPTS))) { - langopts->param[ix] = value; - langopts->param2[ix] = value2; - } else - fprintf(stderr, "Bad voice option: %s %s\n", buf, p); - } else - fprintf(stderr, "Cannot set option: language not set, or is invalid.\n"); - break; case V_ECHO: // echo. suggest: 135mS 11% value = 0;