forked from haguvenir/Turkish_TTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextStruct.h
341 lines (312 loc) · 6.9 KB
/
TextStruct.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#ifndef TEXT_STRUCT
#define TEXT_STRUCT
#include "TextConstants.h"
#include "TTSTrie.h"
#include <atlstr.h>
class Word;
class Parser;
class Splitter;
class Rules;
class RuleStack;
class TTSHashTrie;
class TTSQueue;
struct token;
struct ruleUpdate;
struct TrieNode;
struct token
{
struct token * next;
string cont;
void SetContent(string str){ cont = str; }
string GetCont() { return cont; }
void Append(token *tk)
{
Last()->next = tk;
tk->Last()->next = NULL;
}
void Append(string str)
{
token *ptr = new token;
ptr->cont = str;
ptr->next = NULL;
Append(ptr);
}
token * Last()
{
token *ptr = this;
while(ptr->next != NULL)
ptr = ptr->next;
return ptr;
}
int Len()
{
int len = 0;
token *ptr = this;
while(ptr->next != NULL)
{
len++;
ptr = ptr->next;
}
return len;
}
void display()
{
token *ptr = this;
while(ptr != NULL)
{
cout<<ptr->cont<<" ";
ptr = ptr->next;
}
}
};
struct ruleUpdate
{
int ruleNo;
int data;
int valid;
void displayMe()
{
if(DEBUG_0) cout<<endl;
if(DEBUG_0) cout<<"Rule no :"<<ruleNo<<endl;
if(DEBUG_0) cout<<"Data :"<<data<<endl;
if(DEBUG_0) cout<<endl;
}
};
struct TTSHashTrieNode
{
TRIE_NODE_TYPE type;
string compare;
string * info;
string * data;
TTSHashTrieNode * left;
TTSHashTrieNode * right;
int elements;
int index;
};
class RuleStack
{
public:
RuleStack(int size,int);
~RuleStack();
void Push(int);
int Pop();
const int TopE();
void Resize(int nsize);
void Display();
int GetNoElem(){ return top+1; }
int GetRuleno(){ return ruleno; }
void MakeEmpty();
private:
int size;
int top;
int ruleno;
int * stackPtr;
bool isEmpty() const {return top == -1; }
bool isFull() const {return top == size-1; }
};
class TTSQueue
{
public:
TTSQueue();
~TTSQueue();
void EmptyQueue();
void Enqueue(Word *);
Word * Dequeue();
void Display();
void DisplayP();
void DisplayS();
int QueueSize(){ return size; }
bool isBusy;
private:
bool finished;
int size;
Word * header;
Word * last;
HANDLE mutex;
HANDLE full;
HANDLE empty;
};
class Word
{
public:
Word(string);
~Word();
WORD_TYPE GetType() { return type; }
ruleUpdate * GetRule() { return rule; }
void SetType(WORD_TYPE newtype){ type = newtype; }
// call for updates {NUMBER, ABBREVIATION, ...}
void Update(Parser*);
void Display();
void DisplayP(); // display phonemes
void DisplayS(); // display syllables
// formatting part
void FormatNumber();
void FormatAbbrExc(Parser*);
void FormatPhone();
void FormatSymbol();
void FindTokens(Splitter *, TTSTrie *);
token * HandleUnknownPhonem(Splitter *,string str, TTSTrie * trie);
void Split(string);
void SetContent(string cont){ content = cont; }
string GetContent() { return content; }
void SetNext(Word *nxt) { next = nxt; }
Word * GetNext() { return next; }
int GetPCount() { return tokencount_p; }
token * GetPHeader() { return tokens_phonemes; }
int GetSCount() { return tokencount_s; }
token * GetSHeader() { return tokens_syllables; }
private:
WORD_TYPE type;
string content;
string original;
token *tokens_phonemes;
token *tokens_syllables;
ruleUpdate *rule;
int tokencount_p;
int tokencount_s;
Word *next;
Word *back;
Word *internalqueue;
friend class Parser;
friend class TTSQueue;
};
class Rules
{
public:
Rules();
~Rules();
void RuleEmph(ruleUpdate*,string);
void RuleBreak(ruleUpdate*,string);
void RulePitch(ruleUpdate*,string);
void RuleRate(ruleUpdate*,string);
void RuleVolume(ruleUpdate*,string);
void RuleEngine(ruleUpdate*,string);
void RuleSable();
void RulePron(ruleUpdate*,string);
void RuleSayas(ruleUpdate*,string);
void RuleLang(ruleUpdate*,string);
void RuleSpeaker(ruleUpdate*,string);
void RuleAudio(ruleUpdate*,string);
void RuleMarker(ruleUpdate*,string);
void RuleDiv(ruleUpdate*,string);
Word* RulePronClosable(string);
// -------------------------------------------------------
// we will not have close tags of
// break and pron tags, since break will be similar to set command,
// closing break do not mean anything
// similarly, pron will cover the first string after the tag !, no need to
// look for a close tag.
// -------------------------------------------------------
void RuleEmphC(ruleUpdate*);
void RulePitchC(ruleUpdate*);
void RuleRateC(ruleUpdate*);
void RuleVolumeC(ruleUpdate*);
void RuleEngineC(ruleUpdate*);
void RuleSableC();
void RuleSayasC(ruleUpdate*);
void RuleLangC(ruleUpdate*);
void RuleSpeakerC(ruleUpdate*);
void RuleAudioC(ruleUpdate*);
void RuleMarkerC(ruleUpdate*);
void RuleDivC(ruleUpdate*);
void RulePronClosableC();
void defaults();
string pronounce;
string pronouncec;
private:
int sableOn;
RuleStack
* emphs,
* pitchs,
* rates,
* volumes,
* engines,
* sayass,
* langs,
* speakers,
* audios,
* markers,
* divs;
friend class Parser;
friend class Word;
};
class Parser
{
public:
Parser(TTSQueue *, TTSTrie *);
~Parser();
void Parse();
void LoadString(string);
void LoadFile(ifstream*);
void InsertWord(Word *);
Word * GetWord();
void SetPuncRead(bool flag){ puncEnabled = flag; }
bool GetPuncRead(){ return puncEnabled; }
void EnableRules() {ruleEnabled = true; }
void DisableRules() {ruleEnabled = false; }
void Display();
void DisplaySyllables();
void DisplayPhonemes();
int IsBusy(){ return isBusy; }
int TagControl(string , int );
int GetQueueSize() { return queue->QueueSize(); }
Splitter * GetSplitter(){ return splitter; }
string PrintTagFree();
private:
void LoadExceptions(TTSHashTrie *);
void LoadAbbreviations(TTSHashTrie *);
int isBusy;
TTSQueue *queue;
TTSTrie *trie;
string content;
Splitter *splitter;
Rules * rules;
TTSHashTrie * abbr_exc;
bool ruleEnabled;
bool puncEnabled;
friend class Word;
};
class Splitter
{
public:
Splitter();
~Splitter();
string SplitToPhonemes(string);
string Syllabify(string s, TTSTrie * trie);
bool IsVowel(TCHAR);
bool IsConsonant(TCHAR);
private:
vector<string> PhonemeVector(string str);
bool HasVowel(string str);
int CountVowels(string);
string SplitSyllable(string);
};
class TTSHashTrie
{
public:
TTSHashTrie();
~TTSHashTrie();
void Insert(string str,string data);
string Exists(string str);
void Display();
void DeleteAll();
private:
TTSHashTrieNode *Create(TRIE_NODE_TYPE);
void Check(TTSHashTrieNode *);
string Exists(string str,TTSHashTrieNode *);
void Insert(TTSHashTrieNode *,string str,string data);
void Display(TTSHashTrieNode *);
void Delete(TTSHashTrieNode *);
TTSHashTrieNode * root;
};
CHAR_TYPE GetTypeOf(TCHAR thechar);
string Tens(TCHAR number);
string Ones(TCHAR number);
string Sayiderece(TCHAR number);
string Tolower(string str);
Word * GetChar(TCHAR);
token * GetCharTokens(TCHAR);
token * GetCharTokensToRead(TCHAR);
void GetParameter(string,string,string *);
int Compare(string,string);
#endif TEXT_STRUCT