10
10
#include " ../../../../../SDK/components/utilities/include/sample_log.h"
11
11
#include " processor/wetext_processor.h"
12
12
13
- // Debug logging switch - set to true to enable debug logs
14
- static bool DEBUG_LOGGING = false ;
15
- // Macro for debug logging
16
- #define DEBUG_LOG (fmt, ...) \
17
- do { \
18
- if (DEBUG_LOGGING) { \
19
- SLOGI (fmt, ##__VA_ARGS__); \
20
- } \
21
- } while (0 )
22
13
std::vector<std::string> split (const std::string& s, char delim)
23
14
{
24
15
std::vector<std::string> result;
@@ -31,6 +22,7 @@ std::vector<std::string> split(const std::string& s, char delim)
31
22
}
32
23
return result;
33
24
}
25
+
34
26
class Lexicon {
35
27
private:
36
28
std::unordered_map<std::string, std::pair<std::vector<int >, std::vector<int >>> lexicon;
@@ -41,18 +33,12 @@ class Lexicon {
41
33
wetext::Processor* m_processor;
42
34
43
35
public:
44
- // Setter for debug logging
45
- static void setDebugLogging (bool enable)
46
- {
47
- DEBUG_LOGGING = enable;
48
- }
49
36
Lexicon (const std::string& lexicon_filename, const std::string& tokens_filename, const std::string& tagger_filename,
50
37
const std::string& verbalizer_filename)
51
38
: max_phrase_length(0 )
52
39
{
53
- DEBUG_LOG (" Dictionary loading: %s Pronunciation table loading: %s tagger_filename: %s verbalizer_filename: %s" ,
54
- tokens_filename.c_str (), lexicon_filename.c_str (), tagger_filename.c_str (),
55
- verbalizer_filename.c_str ());
40
+ SLOGD (" Dictionary loading: %s Pronunciation table loading: %s tagger_filename: %s verbalizer_filename: %s" ,
41
+ tokens_filename.c_str (), lexicon_filename.c_str (), tagger_filename.c_str (), verbalizer_filename.c_str ());
56
42
57
43
m_processor = new wetext::Processor (tagger_filename, verbalizer_filename);
58
44
@@ -106,8 +92,8 @@ class Lexicon {
106
92
lexicon[" 。" ] = lexicon[" ." ];
107
93
lexicon[" !" ] = lexicon[" !" ];
108
94
lexicon[" ?" ] = lexicon[" ?" ];
109
- DEBUG_LOG (" Dictionary loading complete, containing %zu entries, longest phrase length: %zu" , lexicon.size (),
110
- max_phrase_length);
95
+ SLOGD (" Dictionary loading complete, containing %zu entries, longest phrase length: %zu" , lexicon.size (),
96
+ max_phrase_length);
111
97
}
112
98
113
99
std::vector<std::string> splitEachChar (const std::string& text)
@@ -136,15 +122,17 @@ class Lexicon {
136
122
{
137
123
return s.size () == 1 && ((s[0 ] >= ' A' && s[0 ] <= ' Z' ) || (s[0 ] >= ' a' && s[0 ] <= ' z' ));
138
124
}
125
+
139
126
bool is_english_token_char (const std::string& s)
140
127
{
141
128
if (s.size () != 1 ) return false ;
142
129
char c = s[0 ];
143
130
return (c >= ' A' && c <= ' Z' ) || (c >= ' a' && c <= ' z' ) || (c >= ' 0' && c <= ' 9' ) || c == ' -' || c == ' _' ;
144
131
}
132
+
145
133
void process_unknown_english (const std::string& word, std::vector<int >& phones, std::vector<int >& tones)
146
134
{
147
- DEBUG_LOG (" Processing unknown term: %s" , word.c_str ());
135
+ SLOGD (" Processing unknown term: %s" , word.c_str ());
148
136
std::string orig_word = word;
149
137
std::vector<std::string> parts;
150
138
std::vector<std::string> phonetic_parts;
@@ -163,7 +151,7 @@ class Lexicon {
163
151
tones.insert (tones.end (), sub_tones.begin (), sub_tones.end ());
164
152
parts.push_back (sub_word);
165
153
phonetic_parts.push_back (phonesToString (sub_phones));
166
- DEBUG_LOG (" Matched: '%s' -> %s" , sub_word.c_str (), phonesToString (sub_phones).c_str ());
154
+ SLOGD (" Matched: '%s' -> %s" , sub_word.c_str (), phonesToString (sub_phones).c_str ());
167
155
start += len;
168
156
matched = true ;
169
157
break ;
@@ -180,13 +168,13 @@ class Lexicon {
180
168
tones.insert (tones.end (), char_tones.begin (), char_tones.end ());
181
169
parts.push_back (single_char);
182
170
phonetic_parts.push_back (phonesToString (char_phones));
183
- DEBUG_LOG (" Single char: '%s' -> %s" , single_char.c_str (), phonesToString (char_phones).c_str ());
171
+ SLOGD (" Single char: '%s' -> %s" , single_char.c_str (), phonesToString (char_phones).c_str ());
184
172
} else {
185
173
phones.insert (phones.end (), unknown_token.first .begin (), unknown_token.first .end ());
186
174
tones.insert (tones.end (), unknown_token.second .begin (), unknown_token.second .end ());
187
175
parts.push_back (single_char);
188
176
phonetic_parts.push_back (" _unknown_" );
189
- DEBUG_LOG (" Unknown: '%s'" , single_char.c_str ());
177
+ SLOGD (" Unknown: '%s'" , single_char.c_str ());
190
178
}
191
179
start++;
192
180
}
@@ -200,26 +188,25 @@ class Lexicon {
200
188
parts_str += parts[i];
201
189
phonetic_str += phonetic_parts[i];
202
190
}
203
- DEBUG_LOG (" %s\t |\t Decomposed: %s\t |\t Phonetics: %s" , orig_word.c_str (), parts_str.c_str (),
204
- phonetic_str.c_str ());
191
+ SLOGD (" %s\t |\t Decomposed: %s\t |\t Phonetics: %s" , orig_word.c_str (), parts_str.c_str (), phonetic_str.c_str ());
205
192
}
206
193
207
194
void convert (const std::string& text, std::vector<int >& phones, std::vector<int >& tones)
208
195
{
209
- DEBUG_LOG (" \n Starting text processing: \" %s\" " , text.c_str ());
196
+ SLOGD (" \n Starting text processing: \" %s\" " , text.c_str ());
210
197
211
198
std::string taggedText = m_processor->Tag (text);
212
- DEBUG_LOG (" \t aggedText processing: \" %s\" " , taggedText.c_str ());
199
+ SLOGD (" \t aggedText processing: \" %s\" " , taggedText.c_str ());
213
200
std::string normalizedText = m_processor->Verbalize (taggedText);
214
- DEBUG_LOG (" \n ormalizedText processing: \" %s\" " , normalizedText.c_str ());
201
+ SLOGD (" \n ormalizedText processing: \" %s\" " , normalizedText.c_str ());
215
202
216
- DEBUG_LOG (" =======Matching Results=======" );
217
- DEBUG_LOG (" Unit\t |\t Phonemes\t |\t Tones" );
218
- DEBUG_LOG (" -----------------------------" );
203
+ SLOGD (" =======Matching Results=======" );
204
+ SLOGD (" Unit\t |\t Phonemes\t |\t Tones" );
205
+ SLOGD (" -----------------------------" );
219
206
phones.insert (phones.end (), unknown_token.first .begin (), unknown_token.first .end ());
220
207
tones.insert (tones.end (), unknown_token.second .begin (), unknown_token.second .end ());
221
- DEBUG_LOG (" <BOS>\t |\t %s\t |\t %s" , phonesToString (unknown_token.first ).c_str (),
222
- tonesToString (unknown_token.second ).c_str ());
208
+ SLOGD (" <BOS>\t |\t %s\t |\t %s" , phonesToString (unknown_token.first ).c_str (),
209
+ tonesToString (unknown_token.second ).c_str ());
223
210
auto chars = splitEachChar (normalizedText);
224
211
int i = 0 ;
225
212
while (i < chars.size ()) {
@@ -236,8 +223,8 @@ class Lexicon {
236
223
auto & [eng_phones, eng_tones] = lexicon[eng_word];
237
224
phones.insert (phones.end (), eng_phones.begin (), eng_phones.end ());
238
225
tones.insert (tones.end (), eng_tones.begin (), eng_tones.end ());
239
- DEBUG_LOG (" %s\t |\t %s\t |\t %s" , orig_word.c_str (), phonesToString (eng_phones).c_str (),
240
- tonesToString (eng_tones).c_str ());
226
+ SLOGD (" %s\t |\t %s\t |\t %s" , orig_word.c_str (), phonesToString (eng_phones).c_str (),
227
+ tonesToString (eng_tones).c_str ());
241
228
} else {
242
229
process_unknown_english (orig_word, phones, tones);
243
230
}
@@ -256,8 +243,8 @@ class Lexicon {
256
243
auto & [phrase_phones, phrase_tones] = lexicon[phrase];
257
244
phones.insert (phones.end (), phrase_phones.begin (), phrase_phones.end ());
258
245
tones.insert (tones.end (), phrase_tones.begin (), phrase_tones.end ());
259
- DEBUG_LOG (" %s\t |\t %s\t |\t %s" , phrase.c_str (), phonesToString (phrase_phones).c_str (),
260
- tonesToString (phrase_tones).c_str ());
246
+ SLOGD (" %s\t |\t %s\t |\t %s" , phrase.c_str (), phonesToString (phrase_phones).c_str (),
247
+ tonesToString (phrase_tones).c_str ());
261
248
i += len;
262
249
matched = true ;
263
250
break ;
@@ -279,25 +266,25 @@ class Lexicon {
279
266
auto & [char_phones, char_tones] = lexicon[s];
280
267
phones.insert (phones.end (), char_phones.begin (), char_phones.end ());
281
268
tones.insert (tones.end (), char_tones.begin (), char_tones.end ());
282
- DEBUG_LOG (" %s\t |\t %s\t |\t %s" , orig_char.c_str (), phonesToString (char_phones).c_str (),
283
- tonesToString (char_tones).c_str ());
269
+ SLOGD (" %s\t |\t %s\t |\t %s" , orig_char.c_str (), phonesToString (char_phones).c_str (),
270
+ tonesToString (char_tones).c_str ());
284
271
} else {
285
272
phones.insert (phones.end (), unknown_token.first .begin (), unknown_token.first .end ());
286
273
tones.insert (tones.end (), unknown_token.second .begin (), unknown_token.second .end ());
287
- DEBUG_LOG (" %s\t |\t %s (Not matched)\t |\t %s" , orig_char.c_str (),
288
- phonesToString (unknown_token.first ).c_str (), tonesToString (unknown_token.second ).c_str ());
274
+ SLOGD (" %s\t |\t %s (Not matched)\t |\t %s" , orig_char.c_str (),
275
+ phonesToString (unknown_token.first ).c_str (), tonesToString (unknown_token.second ).c_str ());
289
276
}
290
277
}
291
278
}
292
279
phones.insert (phones.end (), unknown_token.first .begin (), unknown_token.first .end ());
293
280
tones.insert (tones.end (), unknown_token.second .begin (), unknown_token.second .end ());
294
- DEBUG_LOG (" <EOS>\t |\t %s\t |\t %s" , phonesToString (unknown_token.first ).c_str (),
295
- tonesToString (unknown_token.second ).c_str ());
296
- DEBUG_LOG (" \n Processing Summary:" );
297
- DEBUG_LOG (" Original text: %s" , text.c_str ());
298
- DEBUG_LOG (" Phonemes: %s" , phonesToString (phones).c_str ());
299
- DEBUG_LOG (" Tones: %s" , tonesToString (tones).c_str ());
300
- DEBUG_LOG (" ====================" );
281
+ SLOGD (" <EOS>\t |\t %s\t |\t %s" , phonesToString (unknown_token.first ).c_str (),
282
+ tonesToString (unknown_token.second ).c_str ());
283
+ SLOGD (" \n Processing Summary:" );
284
+ SLOGD (" Original text: %s" , text.c_str ());
285
+ SLOGD (" Phonemes: %s" , phonesToString (phones).c_str ());
286
+ SLOGD (" Tones: %s" , tonesToString (tones).c_str ());
287
+ SLOGD (" ====================" );
301
288
}
302
289
303
290
private:
@@ -316,6 +303,7 @@ class Lexicon {
316
303
phones.insert (phones.end (), phones_and_tones.first .begin (), phones_and_tones.first .end ());
317
304
tones.insert (tones.end (), phones_and_tones.second .begin (), phones_and_tones.second .end ());
318
305
}
306
+
319
307
std::string phonesToString (const std::vector<int >& phones)
320
308
{
321
309
std::string result;
@@ -329,6 +317,7 @@ class Lexicon {
329
317
}
330
318
return result;
331
319
}
320
+
332
321
std::string tonesToString (const std::vector<int >& tones)
333
322
{
334
323
std::string result;
0 commit comments