mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-16 18:22:37 +00:00
[1.25.14] Added feature to define collections of letter sequences in *_rules files for use in rules.
lang=pt Reduce phoneme [&~] to [&] in unstressed syllables. git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@30 d46cf337-b52f-0410-862d-fd96e6ae7743
This commit is contained in:
+4
-2
@@ -532,13 +532,15 @@ int Compile::NextItem(int type)
|
||||
{
|
||||
item_string[ix++] = c;
|
||||
c = fgetc(f_in);
|
||||
if(feof(f_in))
|
||||
break;
|
||||
if(item_string[ix-1] == '=')
|
||||
break;
|
||||
}
|
||||
ungetc(c,f_in);
|
||||
item_string[ix] = 0;
|
||||
|
||||
if(feof(f_in)) return(-1);
|
||||
if(!feof(f_in))
|
||||
ungetc(c,f_in);
|
||||
|
||||
keyword = -1;
|
||||
|
||||
|
||||
+54
-5
@@ -665,7 +665,7 @@ void copy_rule_string(char *string, int &state)
|
||||
c = *p++ - '0';
|
||||
value = *p++ - '0';
|
||||
c = c * 10 + value;
|
||||
if((value < 0) || (value > 9) || (c <= 0) || (c >= N_LETTER_TYPES))
|
||||
if((value < 0) || (value > 9) || (c <= 0) || (c >= N_LETTER_GROUPS))
|
||||
{
|
||||
c = 0;
|
||||
fprintf(f_log,"%5d: Expected 2 digits after 'L'",linenum);
|
||||
@@ -676,11 +676,11 @@ void copy_rule_string(char *string, int &state)
|
||||
{
|
||||
// pre-rule, put the group number before the RULE_LETTERGP command
|
||||
output[ix++] = c;
|
||||
c = RULE_LETTERGP;
|
||||
c = RULE_LETTERGP2;
|
||||
}
|
||||
else
|
||||
{
|
||||
output[ix++] = RULE_LETTERGP;
|
||||
output[ix++] = RULE_LETTERGP2;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1076,8 +1076,47 @@ void output_rule_group(FILE *f_out, int n_rules, char **rules, char *name)
|
||||
|
||||
|
||||
|
||||
int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp)
|
||||
{//=============================================================
|
||||
static int compile_lettergroup(char *input, FILE *f_out)
|
||||
{//=====================================================
|
||||
char *p;
|
||||
int group;
|
||||
|
||||
p = input;
|
||||
if(!isdigit(p[0]) || !isdigit(p[1]))
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
group = atoi(&p[1]);
|
||||
if(group >= N_LETTER_GROUPS)
|
||||
return(1);
|
||||
|
||||
while(!isspace2(*p)) p++;
|
||||
|
||||
fputc(RULE_GROUP_START,f_out);
|
||||
fputc(RULE_LETTERGP2,f_out);
|
||||
fputc(group + 'A', f_out);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
while(isspace2(*p)) p++;
|
||||
if(*p == 0)
|
||||
break;
|
||||
|
||||
while((*p & 0xff) > ' ')
|
||||
{
|
||||
fputc(*p++, f_out);
|
||||
}
|
||||
fputc(0,f_out);
|
||||
}
|
||||
fputc(RULE_GROUP_END,f_out);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
static int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp)
|
||||
{//====================================================================
|
||||
char *prule;
|
||||
unsigned char *p;
|
||||
int ix;
|
||||
@@ -1108,6 +1147,16 @@ int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp)
|
||||
buf = fgets(buf1,sizeof(buf1),f_in);
|
||||
if((buf != NULL) && (buf[0] == '\r')) buf++; // ignore extra \r in \r\n
|
||||
|
||||
if((buf != NULL) && (memcmp(buf,".L",2)==0))
|
||||
{
|
||||
if(compile_lettergroup(&buf[2], f_out) != 0)
|
||||
{
|
||||
fprintf(f_log,"%5d: Bad lettergroup\n",linenum);
|
||||
error_count++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if((buf == NULL) || (memcmp(buf,".group",6)==0))
|
||||
{
|
||||
// next .group or end of file, write out the previous group
|
||||
|
||||
+89
-37
@@ -213,6 +213,7 @@ void Translator::InitGroups(void)
|
||||
groups2_count[ix]=0;
|
||||
groups2_start[ix]=255; // indicates "not set"
|
||||
}
|
||||
memset(letterGroups,0,sizeof(letterGroups));
|
||||
|
||||
p = data_dictrules;
|
||||
while(*p != 0)
|
||||
@@ -223,30 +224,44 @@ void Translator::InitGroups(void)
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
len = strlen(p);
|
||||
p_name = p;
|
||||
c = p_name[0];
|
||||
|
||||
p += (len+1);
|
||||
if(len == 1)
|
||||
{
|
||||
groups1[c] = p;
|
||||
}
|
||||
else
|
||||
if(len == 0)
|
||||
{
|
||||
groups1[0] = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(groups2_start[c] == 255)
|
||||
groups2_start[c] = n_groups2;
|
||||
|
||||
groups2_count[c]++;
|
||||
groups2[n_groups2] = p;
|
||||
c2 = p_name[1];
|
||||
groups2_name[n_groups2++] = (c + (c2 << 8));
|
||||
if(p[0] == RULE_LETTERGP2)
|
||||
{
|
||||
ix = p[1] - 'A';
|
||||
p += 2;
|
||||
if((ix >= 0) && (ix < N_LETTER_GROUPS))
|
||||
{
|
||||
letterGroups[ix] = p;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
len = strlen(p);
|
||||
p_name = p;
|
||||
c = p_name[0];
|
||||
|
||||
p += (len+1);
|
||||
if(len == 1)
|
||||
{
|
||||
groups1[c] = p;
|
||||
}
|
||||
else
|
||||
if(len == 0)
|
||||
{
|
||||
groups1[0] = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(groups2_start[c] == 255)
|
||||
groups2_start[c] = n_groups2;
|
||||
|
||||
groups2_count[c]++;
|
||||
groups2[n_groups2] = p;
|
||||
c2 = p_name[1];
|
||||
groups2_name[n_groups2++] = (c + (c2 << 8));
|
||||
}
|
||||
}
|
||||
|
||||
// skip over all the rules in this group
|
||||
rule_count = 0;
|
||||
while(*p != RULE_GROUP_END)
|
||||
@@ -589,6 +604,31 @@ return(0);
|
||||
|
||||
|
||||
|
||||
int Translator::IsLetterGroup(char *word, int group)
|
||||
{//=================================================
|
||||
// match the word against a list of utf-8 strings
|
||||
char *p;
|
||||
char *w;
|
||||
|
||||
p = letterGroups[group];
|
||||
|
||||
while(*p != 0)
|
||||
{
|
||||
w = word;
|
||||
while(*p == *w)
|
||||
{
|
||||
*w++;
|
||||
*p++;
|
||||
}
|
||||
if(*p == 0)
|
||||
return(w-word); // matched a complete string
|
||||
|
||||
while(*p++ != 0); // skip to end of string
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
int Translator::IsLetter(int letter, int group)
|
||||
{//============================================
|
||||
if(letter_groups[group] != NULL)
|
||||
@@ -1412,8 +1452,9 @@ char *Translator::DecodeRule(const char *group, char *rule)
|
||||
static char output[60];
|
||||
|
||||
static char symbols[] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',
|
||||
'@','&','%','+','#','S','D','Z','A','B','C','H','F','G','Y','N','K','V','L','T','X','?','W'};
|
||||
'@','&','%','+','#','S','D','Z','A','L',' ',' ',' ',' ',' ','N','K','V',' ','T','X','?','W'};
|
||||
|
||||
static char symbols_lg[] = {'A','B','C','H','F','G','Y'};
|
||||
|
||||
match_type = 0;
|
||||
buf_pre[0] = 0;
|
||||
@@ -1465,25 +1506,23 @@ char *Translator::DecodeRule(const char *group, char *rule)
|
||||
}
|
||||
else
|
||||
if(rb == RULE_LETTERGP)
|
||||
{
|
||||
c = symbols_lg[*rule++ - 'A'];
|
||||
}
|
||||
else
|
||||
if(rb == RULE_LETTERGP2)
|
||||
{
|
||||
value = *rule++ - 'A';
|
||||
if(value >= 8)
|
||||
{
|
||||
p[0] = 'L';
|
||||
p[1] = (value / 10) + '0';
|
||||
c = (value % 10) + '0';
|
||||
p[0] = 'L';
|
||||
p[1] = (value / 10) + '0';
|
||||
c = (value % 10) + '0';
|
||||
|
||||
if(match_type == RULE_PRE)
|
||||
{
|
||||
p[0] = c;
|
||||
c = 'L';
|
||||
}
|
||||
p+=2;
|
||||
}
|
||||
else
|
||||
if(match_type == RULE_PRE)
|
||||
{
|
||||
c = symbols[value + RULE_LETTER_GROUPS];
|
||||
p[0] = c;
|
||||
c = 'L';
|
||||
}
|
||||
p+=2;
|
||||
}
|
||||
else
|
||||
if(rb <= RULE_LAST_RULE)
|
||||
@@ -1611,6 +1650,7 @@ void Translator::MatchRule(char *word[], const char *group, char *rule, MatchRec
|
||||
int distance_right;
|
||||
int distance_left;
|
||||
int lg_pts;
|
||||
int n_bytes;
|
||||
|
||||
MatchRecord match;
|
||||
static MatchRecord best;
|
||||
@@ -1626,6 +1666,7 @@ void Translator::MatchRule(char *word[], const char *group, char *rule, MatchRec
|
||||
if(rule == NULL)
|
||||
{
|
||||
match_out->points = 0;
|
||||
(*word)++;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1752,6 +1793,17 @@ void Translator::MatchRule(char *word[], const char *group, char *rule, MatchRec
|
||||
failed = 1;
|
||||
break;
|
||||
|
||||
case RULE_LETTERGP2: // match against a list of utf-t strings
|
||||
letter_group = *rule++ - 'A';
|
||||
if((n_bytes = IsLetterGroup(post_ptr-1,letter_group)) >0)
|
||||
{
|
||||
match.points += (20-distance_right);
|
||||
post_ptr += (n_bytes-1);
|
||||
}
|
||||
else
|
||||
failed =1;
|
||||
break;
|
||||
|
||||
case RULE_NOTVOWEL:
|
||||
if(!IsLetter(letter_w,0))
|
||||
{
|
||||
|
||||
@@ -419,6 +419,22 @@ if((ph->mnemonic == 't') && ((prev->type == phVOWEL) || (prev->mnemonic == 'n'))
|
||||
}
|
||||
#endif
|
||||
|
||||
if((ph->reduce_to != 0) && (ph->type != phVOWEL) && !(plist2->synthflags & SFLAG_DICTIONARY))
|
||||
{
|
||||
// reduction for vowels has already been done in SetWordStress
|
||||
int reduce_level;
|
||||
|
||||
if(next->type == phVOWEL)
|
||||
{
|
||||
reduce_level = (ph->phflags >> 28) & 7;
|
||||
if((&plist2[1])->stress < reduce_level)
|
||||
{
|
||||
// look at the stress of the following vowel
|
||||
ph = phoneme_tab[ph->reduce_to];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((plist2+1)->synthflags & SFLAG_LENGTHEN)
|
||||
{
|
||||
static char types_double[] = {phFRICATIVE,phVFRICATIVE,phNASAL,phLIQUID,0};
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@
|
||||
#include "translate.h"
|
||||
#include "wave.h"
|
||||
|
||||
const char *version_string = "1.25.13 30.May.07";
|
||||
const int version_phdata = 0x012501;
|
||||
const char *version_string = "1.25.14 31.May.07";
|
||||
const int version_phdata = 0x012514;
|
||||
|
||||
int option_device_number = -1;
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ Translator *SelectTranslator(const char *name)
|
||||
{
|
||||
static int stress_amps_is[] = {16,16, 20,20, 20,24, 24,22 };
|
||||
static int stress_lengths_is[8] = {180,155, 200,200, 0,0, 240,250};
|
||||
static const wchar_t is_L08[] = {'c','f','h','k','p','t','x',0xfe,0}; // voiceless conants, including 'þ' ?? 's'
|
||||
static const wchar_t is_lettergroup_B[] = {'c','f','h','k','p','t','x',0xfe,0}; // voiceless conants, including 'þ' ?? 's'
|
||||
|
||||
tr = new Translator();
|
||||
SetupTranslator(tr,stress_lengths_is,stress_amps_is);
|
||||
@@ -356,7 +356,7 @@ Translator *SelectTranslator(const char *name)
|
||||
ResetLetterBits(tr,0x18);
|
||||
SetLetterBits(tr,4,"kpst"); // Letter group F
|
||||
SetLetterBits(tr,3,"jvr"); // Letter group H
|
||||
tr->letter_groups[8] = is_L08;
|
||||
tr->letter_groups[1] = is_lettergroup_B;
|
||||
SetLetterVowel(tr,'y');
|
||||
tr->langopts.numbers = 0xe9;
|
||||
tr->langopts.numbers2 = 0x2;
|
||||
@@ -656,10 +656,6 @@ Translator_Russian::Translator_Russian() : Translator()
|
||||
static const char ru_voiced[] = {0x11,0x12,0x13,0x14,0x16,0x17,0}; // letter group G (voiced obstruents)
|
||||
static const char ru_ivowels[] = {0x2c,0x15,0x31,0x18,0x2e,0x2f,0}; // letter group Y (iotated vowels & soft-sign)
|
||||
|
||||
// these are unicode character codes
|
||||
static const wchar_t ru_L08[] = {0x43a,0x43f,0x441,0x442,0x444,0x445,0}; // кпстфх
|
||||
static const wchar_t ru_L09[] = {0x431,0x433,0x434,0x436,0x43b,0x43c,0x43d,0x440,0}; // бгджзлмнр
|
||||
|
||||
SetupTranslator(this,stress_lengths_ru,stress_amps_ru);
|
||||
|
||||
charset_a0 = charsets[18]; // KOI8-R
|
||||
@@ -678,9 +674,6 @@ Translator_Russian::Translator_Russian() : Translator()
|
||||
SetLetterBits(this,6,ru_ivowels);
|
||||
SetLetterBits(this,7,ru_vowels);
|
||||
|
||||
letter_groups[8] = ru_L08; // This is L08 in ru_rules
|
||||
letter_groups[9] = ru_L09; // This is L09 in ru_rules
|
||||
|
||||
langopts.param[LOPT_UNPRONOUNCABLE] = 0x432; // [v] don't count this character at start of word
|
||||
langopts.param[LOPT_REGRESSIVE_VOICING] = 1;
|
||||
langopts.param[LOPT_KEEP_UNSTR_VOWEL] = 1;
|
||||
|
||||
+7
-11
@@ -29,6 +29,8 @@
|
||||
#define N_RULE_GROUP2 120 // max num of two-letter rule chains
|
||||
#define N_HASH_DICT 1024
|
||||
#define N_CHARSETS 20
|
||||
#define N_LETTER_GROUPS 20
|
||||
|
||||
|
||||
/* flags from word dictionary */
|
||||
// bits 0-3 stressed syllable, 7=unstressed
|
||||
@@ -110,18 +112,11 @@
|
||||
#define RULE_ENDING 14
|
||||
#define RULE_DIGIT 15 // D digit
|
||||
#define RULE_NONALPHA 16 // Z non-alpha
|
||||
#define RULE_LETTER_GROUPS 17 // 17 to 23
|
||||
#define RULE_LETTER1 17 // A vowels
|
||||
#define RULE_LETTER2 18 // B 'hard' consonants
|
||||
#define RULE_LETTER3 19 // C all consonants
|
||||
#define RULE_LETTER4 20 // H letter group
|
||||
#define RULE_LETTER5 21 // F letter group
|
||||
#define RULE_LETTER6 22 // G letter group
|
||||
#define RULE_LETTER7 23 // Y letter group
|
||||
#define RULE_LETTERGP 17 // A B C H F G Y letter group number
|
||||
#define RULE_LETTERGP2 18 // L + letter group number
|
||||
#define RULE_NO_SUFFIX 24 // N
|
||||
#define RULE_NOTVOWEL 25 // K
|
||||
#define RULE_IFVERB 26 // V
|
||||
#define RULE_LETTERGP 27 // L + letter group number
|
||||
#define RULE_ALT1 28 // T word has $alt attribute
|
||||
#define RULE_NOVOWELS 29 // X no vowels up to word boundary
|
||||
#define RULE_SPELLING 31 // W while spelling letter-by-letter
|
||||
@@ -355,8 +350,7 @@ public:
|
||||
// holds properties of characters: vowel, consonant, etc for pronunciation rules
|
||||
unsigned char letter_bits[256];
|
||||
int letter_bits_offset;
|
||||
#define N_LETTER_TYPES 20
|
||||
const wchar_t *letter_groups[N_LETTER_TYPES];
|
||||
const wchar_t *letter_groups[8];
|
||||
|
||||
/* index1=option, index2 by 0=. 1=, 2=?, 3=! 4=none */
|
||||
unsigned char punct_to_tone[4][5];
|
||||
@@ -394,6 +388,7 @@ private:
|
||||
void ApplySpecialAttribute(char *phonemes, int dict_flags);
|
||||
|
||||
int IsLetter(int letter, int group);
|
||||
int IsLetterGroup(char *word, int group);
|
||||
|
||||
void CalcPitches_Tone(int clause_tone);
|
||||
|
||||
@@ -420,6 +415,7 @@ protected:
|
||||
|
||||
unsigned char groups2_count[256]; // number of 2 letter groups for this initial letter
|
||||
unsigned char groups2_start[256]; // index into groups2
|
||||
char *letterGroups[N_LETTER_GROUPS];
|
||||
|
||||
int n_ph_list2;
|
||||
PHONEME_LIST2 ph_list2[N_PHONEME_LIST]; // first stage of text->phonemes
|
||||
|
||||
+6
-2
@@ -378,7 +378,6 @@ void FindPhonemesUsed(void)
|
||||
int hash;
|
||||
char *p;
|
||||
char *start;
|
||||
char *group;
|
||||
char *next;
|
||||
unsigned char c;
|
||||
int count = 0;
|
||||
@@ -397,7 +396,12 @@ void FindPhonemesUsed(void)
|
||||
}
|
||||
if(*p == RULE_GROUP_START)
|
||||
{
|
||||
group = p;
|
||||
if(p[1] == RULE_LETTERGP2)
|
||||
{
|
||||
while(*p != RULE_GROUP_END) p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
p += (strlen(p)+1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user