Navit SVN

/work/compile/navit/src/navit/support/espeak/phoneme.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005 to 2007 by Jonathan Duddington                     *
00003  *   email: jonsd@users.sourceforge.net                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 3 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, see:                                 *
00017  *               <http://www.gnu.org/licenses/>.                           *
00018  ***************************************************************************/
00019 
00020 
00021 
00022 // phoneme types
00023 #define phPAUSE   0
00024 #define phSTRESS  1
00025 #define phVOWEL   2
00026 #define phLIQUID  3
00027 #define phSTOP    4
00028 #define phVSTOP   5
00029 #define phFRICATIVE 6
00030 #define phVFRICATIVE 7
00031 #define phNASAL   8
00032 #define phVIRTUAL 9
00033 #define phDELETED 14
00034 #define phINVALID 15
00035 
00036 
00037 // phoneme properties
00038 //   bits 16-19 give place of articulation (not currently used)
00039 #define phWAVE     0x01
00040 #define phUNSTRESSED 0x02
00041 #define phFORTIS   0x08
00042 #define phVOICED   0x10
00043 #define phSIBILANT 0x20
00044 #define phNOLINK   0x40
00045 #define phTRILL    0x80
00046 #define phVOWEL2   0x100   // liquid that is considered a vowel
00047 #define phPALATAL  0x200
00048 #define phAPPENDPH 0x2000  // always insert another phoneme (link_out) after this one
00049 #define phBRKAFTER 0x4000  // [*] add a post-pause
00050 #define phBEFOREPAUSE 0x8000  // replace with the link_out phoneme if the next phoneme is a pause
00051 
00052 #define phALTERNATIVE    0x1c00   // bits 10,11,12  specifying use of alternative_ph
00053 #define phBEFOREVOWEL    0x0000
00054 #define phBEFOREVOWELPAUSE  0x0400
00055 #define phBEFORENOTVOWEL 0x0c00
00056 #define phBEFORENOTVOWEL2 0x1000
00057 #define phSWITCHVOICING  0x0800
00058 #define phBEFORE_R       0x1400
00059 
00060 #define phNONSYLLABIC  0x100000   // don't count this vowel as a syllable when finding the stress position 
00061 #define phLONG         0x200000
00062 #define phLENGTHENSTOP 0x400000  // make the pre-pause slightly longer
00063 #define phRHOTIC       0x800000
00064 
00065 // fixed phoneme code numbers, these can be used from the program code
00066 #define phonCONTROL     1
00067 #define phonSTRESS_U    2
00068 #define phonSTRESS_D    3
00069 #define phonSTRESS_2    4
00070 #define phonSTRESS_3    5
00071 #define phonSTRESS_P    6
00072 #define phonSTRESS_P2   7    // priority stress within a word
00073 #define phonSTRESS_PREV 8
00074 #define phonPAUSE       9
00075 #define phonPAUSE_SHORT 10
00076 #define phonPAUSE_NOLINK 11
00077 #define phonLENGTHEN    12
00078 #define phonSCHWA       13
00079 #define phonSCHWA_SHORT 14
00080 #define phonEND_WORD    15
00081 #define phonSONORANT    16
00082 #define phonDEFAULTTONE 17
00083 #define phonCAPITAL     18
00084 #define phonGLOTTALSTOP 19
00085 #define phonSYLLABIC    20
00086 #define phonSWITCH      21
00087 #define phonX1          22      // a language specific action
00088 #define phonPAUSE_VSHORT 23
00089 #define phonPAUSE_LONG  24
00090 #define phonT_REDUCED   25
00091 #define phonSTRESS_TONIC 26
00092 #define phonPAUSE_CLAUSE 27
00093 
00094 extern const unsigned char pause_phonemes[8];  // 0, vshort, short, pause, long, glottalstop
00095 
00096 // place of articulation
00097 #define phPLACE        0xf0000
00098 #define phPLACE_pla    0x60000
00099 
00100 #define N_PHONEME_TABS     100     // number of phoneme tables
00101 #define N_PHONEME_TAB      256     // max phonemes in a phoneme table
00102 #define N_PHONEME_TAB_NAME  32     // must be multiple of 4
00103 
00104 // main table of phonemes, index by phoneme number (1-254)
00105 typedef struct {
00106         unsigned int mnemonic;        // 1st char is in the l.s.byte
00107         unsigned int phflags;         // bits 28-30 reduce_to level,  bits 16-19 place of articulation
00108                                  // bits 10-11 alternative ph control
00109 
00110         unsigned short std_length;    // for vowels, in mS;  for phSTRESS, the stress/tone type
00111         unsigned short  spect;
00112         unsigned short  before;
00113         unsigned short  after;
00114 
00115         unsigned char  code;          // the phoneme number
00116         unsigned char  type;          // phVOWEL, phPAUSE, phSTOP etc
00117         unsigned char  start_type;
00118         unsigned char  end_type;
00119         
00120         unsigned char  length_mod;     // a length_mod group number, used to access length_mod_tab
00121         unsigned char  reduce_to;      // change to this phoneme if unstressed
00122         unsigned char  alternative_ph; // change to this phoneme if a vowel follows/doesn't follow
00123         unsigned char  link_out;       // insert linking phoneme if a vowel follows
00124         
00125 } PHONEME_TAB;
00126 
00127 
00128 // Several phoneme tables may be loaded into memory. phoneme_tab points to
00129 // one for the current voice
00130 extern int n_phoneme_tab;
00131 extern int current_phoneme_table;
00132 extern PHONEME_TAB *phoneme_tab[N_PHONEME_TAB];
00133 extern unsigned char phoneme_tab_flags[N_PHONEME_TAB];  // bit 0: not inherited
00134 
00135 typedef struct {
00136         char name[N_PHONEME_TAB_NAME];
00137         PHONEME_TAB *phoneme_tab_ptr;
00138         int n_phonemes;
00139         int includes;           // also include the phonemes from this other phoneme table
00140 } PHONEME_TAB_LIST;
00141 
00142 
00143 
00144 // table of phonemes to be replaced with different phonemes, for the current voice
00145 #define N_REPLACE_PHONEMES   60
00146 typedef struct {
00147         unsigned char old_ph;
00148         unsigned char new_ph;
00149         char type;   // 0=always replace, 1=only at end of word
00150 } REPLACE_PHONEMES;
00151 
00152 extern int n_replace_phonemes;
00153 extern REPLACE_PHONEMES replace_phonemes[N_REPLACE_PHONEMES];
00154 
00155 
00156 #define PH(c1,c2)  (c2<<8)+c1          // combine two characters into an integer for phoneme name 
00157 #define PH3(c1,c2,c3) (c3<<16)+(c2<<8)+c1
00158 #define PhonemeCode2(c1,c2)  PhonemeCode((c2<<8)+c1)
00159 int LookupPhonemeString(const char *string);
00160 int PhonemeCode(unsigned int mnem);
00161 
00162 char *EncodePhonemes(char *p, char *outptr, unsigned char *bad_phoneme);
00163 void DecodePhonemes(const char *inptr, char *outptr);
00164 
00165 extern const char *WordToString(unsigned int word);
00166 
00167 extern PHONEME_TAB_LIST phoneme_tab_list[N_PHONEME_TABS];
00168 extern int phoneme_tab_number;