mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-19 10:58:30 +00:00
Lang=hr, transliterate Cyrillic characters to Latin using TranslateChar().
TranslateChar() can now substitute a character by two replacement characters. Lang=cs, more difference between long and short vowels, less length differnence beteeen stressed and unstressed syllables. git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@7 d46cf337-b52f-0410-862d-fd96e6ae7743
This commit is contained in:
+47
-22
@@ -876,6 +876,7 @@ void Translator::SetWordStress(char *output, unsigned int dictionary_flags, int
|
||||
int final_ph;
|
||||
int mnem;
|
||||
int post_tonic;
|
||||
int opt_length;
|
||||
|
||||
unsigned char vowel_stress[N_WORD_PHONEMES/2];
|
||||
char syllable_type[N_WORD_PHONEMES/2];
|
||||
@@ -1143,19 +1144,20 @@ void Translator::SetWordStress(char *output, unsigned int dictionary_flags, int
|
||||
tonic = langopts.unstressed_wd2; /* more than one syllable, used secondary stress as the main stress */
|
||||
}
|
||||
|
||||
max_stress = 0;
|
||||
max_stress_posn = 0;
|
||||
for(v=1; v<vowel_count; v++)
|
||||
{
|
||||
if(vowel_stress[v] >= max_stress)
|
||||
{
|
||||
max_stress = vowel_stress[v];
|
||||
max_stress_posn = v;
|
||||
}
|
||||
}
|
||||
|
||||
if(tonic >= 0)
|
||||
{
|
||||
/* find position of highest stress, and replace it by 'tonic' */
|
||||
max_stress = 0;
|
||||
max_stress_posn = 0;
|
||||
for(v=1; v<vowel_count; v++)
|
||||
{
|
||||
if(vowel_stress[v] >= max_stress)
|
||||
{
|
||||
max_stress = vowel_stress[v];
|
||||
max_stress_posn = v;
|
||||
}
|
||||
}
|
||||
|
||||
/* don't disturb an explicitly set stress by 'unstress-at-end' flag */
|
||||
if((tonic > max_stress) || (max_stress <= 4))
|
||||
@@ -1303,20 +1305,36 @@ void Translator::SetWordStress(char *output, unsigned int dictionary_flags, int
|
||||
break;
|
||||
}
|
||||
|
||||
if(langopts.param[LOPT_IT_LENGTHEN] && (*p == phonLENGTHEN))
|
||||
{
|
||||
// remove lengthen indicator from non-stressed syllables
|
||||
if(v_stress < 4)
|
||||
p++;
|
||||
else
|
||||
if((langopts.param[LOPT_IT_LENGTHEN]==2) && (v != (vowel_count - 2)))
|
||||
p++; // LANG=Italian, remove lengthen indicator from non-penultimate syllables
|
||||
}
|
||||
|
||||
if(vowel_stress[v] > max_stress)
|
||||
{
|
||||
max_stress = vowel_stress[v];
|
||||
}
|
||||
|
||||
if((*p == phonLENGTHEN) && ((opt_length = langopts.param[LOPT_IT_LENGTHEN]) != 0))
|
||||
{
|
||||
// remove lengthen indicator from non-stressed syllables
|
||||
int shorten=0;
|
||||
|
||||
if(opt_length & 0x10)
|
||||
{
|
||||
// only allow lengthen indicator on the highest stress syllable in the word
|
||||
if(v != max_stress_posn)
|
||||
shorten = 1;
|
||||
}
|
||||
else
|
||||
if(v_stress < 4)
|
||||
{
|
||||
// only allow lengthen indicator if stress >= 4.
|
||||
shorten = 1;
|
||||
}
|
||||
|
||||
if(((opt_length & 0xf)==2) && (v != (vowel_count - 2)))
|
||||
shorten = 1; // LANG=Italian, remove lengthen indicator from non-penultimate syllables
|
||||
|
||||
if(shorten)
|
||||
p++;
|
||||
}
|
||||
|
||||
v++;
|
||||
}
|
||||
|
||||
@@ -1553,6 +1571,7 @@ void Translator::MatchRule(char *word[], const char *group, char *rule, MatchRec
|
||||
int letter_group;
|
||||
int distance_right;
|
||||
int distance_left;
|
||||
int lg_pts;
|
||||
|
||||
MatchRecord match;
|
||||
static MatchRecord best;
|
||||
@@ -1682,7 +1701,10 @@ void Translator::MatchRule(char *word[], const char *group, char *rule, MatchRec
|
||||
letter_group = *rule++ - 'A';
|
||||
if(IsLetter(letter_w,letter_group))
|
||||
{
|
||||
match.points += (20-distance_right);
|
||||
lg_pts = 20;
|
||||
if(letter_group==2)
|
||||
lg_pts = 19; // fewer points for C, general consonant
|
||||
match.points += (lg_pts-distance_right);
|
||||
post_ptr += letter_xbytes;
|
||||
}
|
||||
else
|
||||
@@ -1830,7 +1852,10 @@ void Translator::MatchRule(char *word[], const char *group, char *rule, MatchRec
|
||||
letter_group = *rule++ - 'A';
|
||||
if(IsLetter(letter_w,letter_group))
|
||||
{
|
||||
match.points += (20-distance_left);
|
||||
lg_pts = 20;
|
||||
if(letter_group==2)
|
||||
lg_pts = 19; // fewer points for C, general consonant
|
||||
match.points += (lg_pts-distance_left);
|
||||
pre_ptr -= letter_xbytes;
|
||||
}
|
||||
else
|
||||
|
||||
+3
-1
@@ -267,7 +267,9 @@ static TONE_TABLE tone_table[N_TONE_TABLE] = {
|
||||
{PITCHfrise, 38,10, PITCHfrise2, 36,10, // comma, or question
|
||||
20, 25, 34, 20, drops_0, 3, 3, 15, 25, 0},
|
||||
|
||||
{PITCHdrop, 38, 1, PITCHdrop, 42,25, // exclamation
|
||||
// {PITCHdrop, 38, 1, PITCHdrop, 42,25, // exclamation
|
||||
// 20, 25, 34, 22, drops_0, 3, 3, 12, 8, 0},
|
||||
{PITCHfall, 30, 5, PITCHfall, 30, 7, // statement
|
||||
20, 25, 34, 22, drops_0, 3, 3, 12, 8, 0},
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@
|
||||
#include "translate.h"
|
||||
#include "wave.h"
|
||||
|
||||
const char *version_string = "1.24.04 08.May.07";
|
||||
const char *version_string = "1.24.06 10.May.07";
|
||||
const int version_phdata = 0x012201;
|
||||
|
||||
int option_device_number = -1;
|
||||
|
||||
+50
-10
@@ -241,8 +241,8 @@ Translator *SelectTranslator(const char *name)
|
||||
case L('h','i'):
|
||||
{
|
||||
static const char dev_consonants2[] = {0x02,0x03,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f};
|
||||
static wchar_t replace_chars_hi[11] = {0x966,0x967,0x968,0x969,0x96a,0x96b,0x96c,0x96d,0x96e,0x96f,0}; // digits 0-9
|
||||
static wchar_t replacement_chars_hi[11] = {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0};
|
||||
static const wchar_t replace_chars_hi[11] = {0x966,0x967,0x968,0x969,0x96a,0x96b,0x96c,0x96d,0x96e,0x96f,0}; // digits 0-9
|
||||
static const unsigned int replacement_chars_hi[11] = {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0};
|
||||
static int stress_lengths_hi[8] = {190, 190, 210, 210, 0, 0, 230, 250};
|
||||
static int stress_amps_hi[8] = {17,14, 20,20, 20,24, 24,22 };
|
||||
|
||||
@@ -269,8 +269,8 @@ Translator *SelectTranslator(const char *name)
|
||||
{
|
||||
static int stress_amps_hu[8] = {16,16, 20,20, 20,24, 24,22 };
|
||||
static int stress_lengths_hu[8] = {180,150, 200,180, 0,0, 230,270};
|
||||
static wchar_t replace_chars_hu[] = {0xd4,0xf4,0xdb,0xfb,0};
|
||||
static wchar_t replacement_chars_hu[] = {0x150,0x151,0x170,0x171,0}; // allow o,u-circumflex for o,u-double-acute
|
||||
static const wchar_t replace_chars_hu[] = {0xd4,0xf4,0xdb,0xfb,0};
|
||||
static const unsigned int replacement_chars_hu[] = {0x150,0x151,0x170,0x171,0}; // allow o,u-circumflex for o,u-double-acute
|
||||
|
||||
tr = new Translator();
|
||||
SetupTranslator(tr,stress_lengths_hu,stress_amps_hu);
|
||||
@@ -290,6 +290,26 @@ Translator *SelectTranslator(const char *name)
|
||||
}
|
||||
break;
|
||||
|
||||
case L('i','s'): // Icelandic
|
||||
{
|
||||
static int stress_amps_is[] = {16,16, 20,20, 20,24, 24,22 };
|
||||
static int stress_lengths_is[8] = {180,140, 200,200, 0,0, 240,260};
|
||||
static const wchar_t is_L08[] = {'c','f','h','k','p','s','t','x',0xfe,0}; // voiceless conants, including 'þ'
|
||||
|
||||
tr = new Translator();
|
||||
SetupTranslator(tr,stress_lengths_is,stress_amps_is);
|
||||
tr->langopts.stress_rule = 1;
|
||||
tr->langopts.param[LOPT_IT_LENGTHEN] = 0x11; // remove lengthen indicator from unstressed vowels
|
||||
|
||||
SetLetterBits(tr,4,"kpst"); // Letter group F
|
||||
SetLetterBits(tr,3,"jvr"); // Letter group H
|
||||
tr->letter_groups[8] = is_L08;
|
||||
SetLetterVowel(tr,'y');
|
||||
tr->langopts.numbers = 0xe9;
|
||||
tr->langopts.numbers2 = 0x2;
|
||||
}
|
||||
break;
|
||||
|
||||
case L('i','t'): // Italian
|
||||
{
|
||||
static int stress_lengths_it[8] = {150, 140, 180, 180, 0, 0, 270, 320};
|
||||
@@ -378,8 +398,8 @@ Translator *SelectTranslator(const char *name)
|
||||
{
|
||||
static int stress_lengths_ro[8] = {170, 170, 180, 180, 0, 0, 240, 260};
|
||||
static int stress_amps_ro[8] = {15,13, 18,18, 20,22, 22,22 };
|
||||
static wchar_t replace_chars_ro[5] = {0x218,0x219,0x21a,0x21b,0};
|
||||
static wchar_t replacement_chars_ro[5] = {0x15e,0x15f,0x162,0x163,0}; // replace s-comma, t-comma by s-cedilla, t-cedilla
|
||||
static const wchar_t replace_chars_ro[5] = {0x218,0x219,0x21a,0x21b,0};
|
||||
static const unsigned int replacement_chars_ro[5] = {0x15e,0x15f,0x162,0x163,0}; // replace s-comma, t-comma by s-cedilla, t-cedilla
|
||||
|
||||
tr = new Translator();
|
||||
SetupTranslator(tr,stress_lengths_ro,stress_amps_ro);
|
||||
@@ -403,9 +423,24 @@ Translator *SelectTranslator(const char *name)
|
||||
case L('c','s'): // Czech
|
||||
case L('h','r'): // Croatian
|
||||
{
|
||||
static const wchar_t replace_chars_hr[] =
|
||||
{0x430,0x431,0x446,0x45b,0x447,0x434,0x452,0x45f,
|
||||
0x435,0x444,0x433,0x445,0x438,0x458,0x43a,0x43b,
|
||||
0x459,0x43c,0x43d,0x45a,0x43e,0x43f,0x440,0x441,
|
||||
0x448,0x442,0x443,0x432,0x437,0x436,
|
||||
0x453,0x455,0x45c,0}; // ѓ ѕ ќ
|
||||
|
||||
static const unsigned int replacement_chars_hr[] =
|
||||
{'a','b','c',0x107,0x10d,'d',0x111,'d'+(0x17e<<16),
|
||||
'e','f','g','h','i','j','k','l',
|
||||
'l'+('j'<<16),'m','n','n'+('j'<<16),'o','p','r','s',
|
||||
0x161,'t','u','v','z',0x17e,
|
||||
0x111,'d'+('z'<<16),0x107,0};
|
||||
|
||||
static int stress_amps_sk[8] = {16,16, 20,20, 20,24, 24,22 };
|
||||
static int stress_lengths_sk[8] = {180,180, 200,180, 0,0, 220,230};
|
||||
static char *sk_voiced = "bdgjlmnrvwzaeiouy";
|
||||
// static int stress_lengths_sk[8] = {180,180, 200,200, 0,0, 210,220};
|
||||
static int stress_lengths_sk[8] = {190,190, 210,210, 0,0, 210,210};
|
||||
static char *sk_voiced = "bdgjlmnrvwzaeiouy";
|
||||
|
||||
tr = new Translator();
|
||||
SetupTranslator(tr,stress_lengths_sk,stress_amps_sk);
|
||||
@@ -420,7 +455,12 @@ Translator *SelectTranslator(const char *name)
|
||||
|
||||
tr->langopts.numbers = 0x1c0d + 0x84000;
|
||||
if(name2 == L('h','r'))
|
||||
{
|
||||
tr->langopts.numbers2 = 0xa; // variant numbers before thousands,milliards
|
||||
tr->langopts.replace_chars = replace_chars_hr;
|
||||
tr->langopts.replacement_chars = replacement_chars_hr;
|
||||
}
|
||||
|
||||
if(name2 == L('c','s'))
|
||||
tr->langopts.numbers2 = 0x8; // variant numbers before milliards
|
||||
|
||||
@@ -835,8 +875,8 @@ Translator_Afrikaans::Translator_Afrikaans() : Translator()
|
||||
}
|
||||
|
||||
|
||||
int Translator_Afrikaans::TranslateChar(char *ptr, int prev_in, int c, int next_in)
|
||||
{//===============================================================================
|
||||
int Translator_Afrikaans::TranslateChar(char *ptr, int prev_in, int c, int next_in, int *insert)
|
||||
{//=============================================================================================
|
||||
// look for 'n and replace by a special character (unicode: schwa)
|
||||
|
||||
if(!iswalpha(prev_in))
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ class Translator_Afrikaans: public Translator
|
||||
public:
|
||||
Translator_Afrikaans();
|
||||
private:
|
||||
int TranslateChar(char *ptr, int prev_in, int c, int next_in);
|
||||
int TranslateChar(char *ptr, int prev_in, int c, int next_in, int *insert);
|
||||
|
||||
}; // end of class Translator_Afrikaans
|
||||
|
||||
|
||||
+30
-7
@@ -393,7 +393,7 @@ Translator::Translator()
|
||||
SetLetterBits(this,1,"bcdfgjklmnpqstvxz"); // B hard consonants, excluding h,r,w
|
||||
SetLetterBits(this,2,"bcdfghjklmnpqrstvwxz"); // C all consonants
|
||||
SetLetterBits(this,3,"hlmnr"); // H 'soft' consonants
|
||||
|
||||
SetLetterBits(this,4,"cfhkpqstx"); // F voiceless consonants
|
||||
SetLetterBits(this,5,"bdgjlmnrvwyz"); // G voiced
|
||||
SetLetterBits(this,6,"eiy"); // Letter group Y, front vowels
|
||||
SetLetterBits(this,7,"aeiouy"); // vowels, including y
|
||||
@@ -1470,18 +1470,28 @@ static int EmbeddedCommand(unsigned int &source_index)
|
||||
|
||||
|
||||
|
||||
int Translator::TranslateChar(char *ptr, int prev_in, int c, int next_in)
|
||||
{//======================================================================
|
||||
int Translator::TranslateChar(char *ptr, int prev_in, int c, int next_in, int *insert)
|
||||
{//===================================================================================
|
||||
// To allow language specific examination and replacement of characters
|
||||
|
||||
const wchar_t *p;
|
||||
unsigned int new_c;
|
||||
|
||||
if(c == 0) return(0);
|
||||
|
||||
if(langopts.replace_chars != NULL)
|
||||
{
|
||||
// there is a list of character codes to be substituted with alternative codes
|
||||
if((p = wcschr(langopts.replace_chars,c)) != NULL)
|
||||
{
|
||||
return(langopts.replacement_chars[p - langopts.replace_chars]);
|
||||
new_c = langopts.replacement_chars[p - langopts.replace_chars];
|
||||
if(new_c & 0xffe00000)
|
||||
{
|
||||
// there is a second character to be inserted
|
||||
*insert = (new_c >> 16);
|
||||
new_c &= 0xffff;
|
||||
}
|
||||
return(new_c);
|
||||
}
|
||||
}
|
||||
return(c);
|
||||
@@ -1500,6 +1510,7 @@ void *Translator::TranslateClause(FILE *f_text, const void *vp_input, int *tone_
|
||||
int prev_out2;
|
||||
int prev_in2=0;
|
||||
int next_in;
|
||||
int char_inserted=0;
|
||||
int clause_pause;
|
||||
int pre_pause=0;
|
||||
int pre_pause_add=0;
|
||||
@@ -1626,9 +1637,19 @@ void *Translator::TranslateClause(FILE *f_text, const void *vp_input, int *tone_
|
||||
utf8_in(&prev_in,&source[source_index-1],1); // prev_in = source[source_index-1];
|
||||
}
|
||||
prev_source_index = source_index;
|
||||
source_index += utf8_in(&cc,&source[source_index],0); // cc = source[source_index++];
|
||||
c = cc;
|
||||
|
||||
if(char_inserted)
|
||||
{
|
||||
c = char_inserted;
|
||||
char_inserted = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
source_index += utf8_in(&cc,&source[source_index],0); // cc = source[source_index++];
|
||||
c = cc;
|
||||
}
|
||||
utf8_in(&next_in,&source[source_index],0);
|
||||
|
||||
if((c == CTRL_EMBEDDED) || (c == ctrl_embedded))
|
||||
{
|
||||
// start of embedded command in the text
|
||||
@@ -1705,7 +1726,9 @@ if((c == '/') && (langopts.testing & 2) && isdigit(next_in) && IsAlpha(prev_out)
|
||||
c = '\'';
|
||||
}
|
||||
|
||||
c = TranslateChar(&source[source_index],prev_in,c,next_in); // optional language specific function
|
||||
c = TranslateChar(&source[source_index], prev_in,c, next_in, &char_inserted); // optional language specific function
|
||||
if(char_inserted)
|
||||
next_in = char_inserted;
|
||||
|
||||
if(!IsAlpha(c) && !iswspace(c) && (c != '\''))
|
||||
{
|
||||
|
||||
+4
-3
@@ -212,6 +212,7 @@ extern const int param_defaults[N_SPEECH_PARAM];
|
||||
#define N_LOPTS 12
|
||||
#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
|
||||
#define LOPT_IT_LENGTHEN 2
|
||||
// 1=german
|
||||
#define LOPT_PREFIXES 3
|
||||
@@ -295,8 +296,8 @@ typedef struct {
|
||||
char tone_numbers;
|
||||
char ideographs; // treat as separate words
|
||||
int testing; // testing options: bit 1= specify stressed syllable in the form: "outdoor/2"
|
||||
const wchar_t *replace_chars; // characters to be substitutes
|
||||
const wchar_t *replacement_chars; // substitutes for replace_chars
|
||||
const wchar_t *replace_chars; // characters to be substitutes
|
||||
const unsigned int *replacement_chars; // substitutes for replace_chars
|
||||
} LANGUAGE_OPTIONS;
|
||||
|
||||
|
||||
@@ -392,7 +393,7 @@ protected:
|
||||
virtual int Unpronouncable(char *word);
|
||||
virtual void SetWordStress(char *output, unsigned int dictionary_flags, int tonic, int prev_stress);
|
||||
virtual int RemoveEnding(char *word, int end_type, char *word_copy);
|
||||
virtual int TranslateChar(char *ptr, int prev_in, int c, int next_in);
|
||||
virtual int TranslateChar(char *ptr, int prev_in, int c, int next_in, int *insert);
|
||||
virtual int TranslateNumber(char *word1, char *ph_out, unsigned int *flags, int wflags);
|
||||
virtual int ChangePhonemes(PHONEME_LIST2 *phlist, int n_ph, int index, PHONEME_TAB *ph, CHANGEPH *ch);
|
||||
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ MNEM_TAB genders [] = {
|
||||
{NULL, 0 }};
|
||||
|
||||
//int tone_points[10] = {250,140, 1200,110, -1,0, -1,0, -1,0};
|
||||
int tone_points[10] = {600,180, 1200,140, 2000,110, 3000,110, -1,0};
|
||||
int tone_points[10] = {600,170, 1200,135, 2000,110, 3000,110, -1,0};
|
||||
|
||||
// limit the rate of change for each formant number
|
||||
//static int formant_rate_22050[9] = {50, 104, 165, 230, 220, 220, 220, 220, 220}; // values for 22kHz sample rate
|
||||
|
||||
Reference in New Issue
Block a user