00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef EKHO_DICT
00018 #define EKHO_DICT
00019
00020 #include "character.h"
00021 #include "zhy_symbol_map.h"
00022 #include "zh_symbol_map.h"
00023 #include <map>
00024 #include <list>
00025 #include <sndfile.h>
00026 using namespace std;
00027
00028 namespace ekho {
00029 typedef enum {
00030 CANTONESE = 1,
00031 MANDARIN = 2,
00032 ENGLISH = 3,
00033 KOREAN = 4,
00034 } Language;
00035
00036 struct DictItem {
00037 DictItem() {
00038 wordList = 0;
00039 }
00040 ~DictItem() {
00041 if (wordList) {
00042 delete wordList;
00043 wordList = 0;
00044 }
00045 }
00046 Character character;
00047 list< list<Character> > *wordList;
00048 };
00049
00050 class Dict {
00051 public:
00052 Dict(void);
00053 Dict(Language lang);
00054 ~Dict(void);
00055
00056 static bool mDebug;
00057 string mDataPath;
00058 string mVoiceFileType;
00059 SF_INFO mSfinfo;
00060 const static int SYMBOL_ARRAY_SIZE = 8000;
00061
00065 static PhoneticSymbol mSymbolArray[SYMBOL_ARRAY_SIZE];
00066
00067 int setLanguage(Language lang);
00068 inline Language getLanguage(void) { return mLanguage; };
00069 int setVoice(string voice);
00070 inline string getVoice(void) { return mVoice; };
00071 PhoneticSymbol* lookup(Character &c);
00072 inline PhoneticSymbol* lookup(unsigned int code) {
00073 Character c(code);
00074 return lookup(c);
00075 };
00076 inline list<PhoneticSymbol*> lookup(string &text) {
00077 list<Character> charList = Character::split(text);
00078 return lookup(charList);
00079 }
00080 list<PhoneticSymbol*> lookup(list<Character> &charList);
00081 inline list<PhoneticSymbol*> lookup(const char *text) {
00082 string str(text);
00083 return lookup(str);
00084 };
00085 int loadEspeakDict(const char *path);
00086 inline int loadEspeakDict(const string &path) {
00087 return loadEspeakDict(path.c_str());
00088 };
00089 int saveEkhoDict(const char *path);
00090 inline int saveEkhoDict(const string &path) {
00091 return saveEkhoDict(path.c_str());
00092 };
00093 int loadEkhoDict(const char *path);
00094 inline int loadEkhoDict(const string &path) {
00095 return loadEkhoDict(path.c_str());
00096 };
00097 inline PhoneticSymbol* getFullPause(void) { return mFullPause; };
00098 inline PhoneticSymbol* getHalfPause(void) { return mHalfPause; };
00099 inline PhoneticSymbol* getQuaterPause(void) { return mQuaterPause; };
00100
00101 private:
00105 DictItem mDictItemArray[65536];
00106 map<int,DictItem> mExtraDictItemMap;
00107
00108 string mVoice;
00109 int mFullPausePcmSize;
00110 char *mFullPausePcm;
00111 char *mHalfPausePcm;
00112 char *mQuaterPausePcm;
00113 Language mLanguage;
00114 PhoneticSymbol *mFullPause;
00115 PhoneticSymbol *mHalfPause;
00116 PhoneticSymbol *mQuaterPause;
00117
00118 void init(void);
00119 string getDefaultDataPath(void);
00120 void addSpecialSymbols(void);
00121
00122 inline PhoneticSymbol* getZhyPhon(const char *sym) {
00123 return &mSymbolArray[ZHY_PHash::in_word_set(sym, strlen(sym))->code];
00124 }
00125
00126 inline PhoneticSymbol* getZhPhon(const char *sym) {
00127 return &mSymbolArray[ZH_PHash::in_word_set(sym, strlen(sym))->code];
00128 }
00129
00130 inline void addDictItem(unsigned short code, PhoneticSymbol* phonSymbol) {
00131 mDictItemArray[code].character.code = code;
00132 mDictItemArray[code].character.phonSymbol = phonSymbol;
00133 }
00134 };
00135
00136 }
00137
00138 #endif