1010#include " ../../../../../SDK/components/utilities/include/sample_log.h"
1111#include " processor/wetext_processor.h"
1212
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 )
2213std::vector<std::string> split (const std::string& s, char delim)
2314{
2415 std::vector<std::string> result;
@@ -31,6 +22,7 @@ std::vector<std::string> split(const std::string& s, char delim)
3122 }
3223 return result;
3324}
25+
3426class Lexicon {
3527private:
3628 std::unordered_map<std::string, std::pair<std::vector<int >, std::vector<int >>> lexicon;
@@ -41,18 +33,12 @@ class Lexicon {
4133 wetext::Processor* m_processor;
4234
4335public:
44- // Setter for debug logging
45- static void setDebugLogging (bool enable)
46- {
47- DEBUG_LOGGING = enable;
48- }
4936 Lexicon (const std::string& lexicon_filename, const std::string& tokens_filename, const std::string& tagger_filename,
5037 const std::string& verbalizer_filename)
5138 : max_phrase_length(0 )
5239 {
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 ());
5642
5743 m_processor = new wetext::Processor (tagger_filename, verbalizer_filename);
5844
@@ -106,8 +92,8 @@ class Lexicon {
10692 lexicon[" 。" ] = lexicon[" ." ];
10793 lexicon[" !" ] = lexicon[" !" ];
10894 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);
11197 }
11298
11399 std::vector<std::string> splitEachChar (const std::string& text)
@@ -136,15 +122,17 @@ class Lexicon {
136122 {
137123 return s.size () == 1 && ((s[0 ] >= ' A' && s[0 ] <= ' Z' ) || (s[0 ] >= ' a' && s[0 ] <= ' z' ));
138124 }
125+
139126 bool is_english_token_char (const std::string& s)
140127 {
141128 if (s.size () != 1 ) return false ;
142129 char c = s[0 ];
143130 return (c >= ' A' && c <= ' Z' ) || (c >= ' a' && c <= ' z' ) || (c >= ' 0' && c <= ' 9' ) || c == ' -' || c == ' _' ;
144131 }
132+
145133 void process_unknown_english (const std::string& word, std::vector<int >& phones, std::vector<int >& tones)
146134 {
147- DEBUG_LOG (" Processing unknown term: %s" , word.c_str ());
135+ SLOGD (" Processing unknown term: %s" , word.c_str ());
148136 std::string orig_word = word;
149137 std::vector<std::string> parts;
150138 std::vector<std::string> phonetic_parts;
@@ -163,7 +151,7 @@ class Lexicon {
163151 tones.insert (tones.end (), sub_tones.begin (), sub_tones.end ());
164152 parts.push_back (sub_word);
165153 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 ());
167155 start += len;
168156 matched = true ;
169157 break ;
@@ -180,13 +168,13 @@ class Lexicon {
180168 tones.insert (tones.end (), char_tones.begin (), char_tones.end ());
181169 parts.push_back (single_char);
182170 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 ());
184172 } else {
185173 phones.insert (phones.end (), unknown_token.first .begin (), unknown_token.first .end ());
186174 tones.insert (tones.end (), unknown_token.second .begin (), unknown_token.second .end ());
187175 parts.push_back (single_char);
188176 phonetic_parts.push_back (" _unknown_" );
189- DEBUG_LOG (" Unknown: '%s'" , single_char.c_str ());
177+ SLOGD (" Unknown: '%s'" , single_char.c_str ());
190178 }
191179 start++;
192180 }
@@ -200,26 +188,25 @@ class Lexicon {
200188 parts_str += parts[i];
201189 phonetic_str += phonetic_parts[i];
202190 }
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 ());
205192 }
206193
207194 void convert (const std::string& text, std::vector<int >& phones, std::vector<int >& tones)
208195 {
209- DEBUG_LOG (" \n Starting text processing: \" %s\" " , text.c_str ());
196+ SLOGD (" \n Starting text processing: \" %s\" " , text.c_str ());
210197
211198 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 ());
213200 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 ());
215202
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 (" -----------------------------" );
219206 phones.insert (phones.end (), unknown_token.first .begin (), unknown_token.first .end ());
220207 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 ());
223210 auto chars = splitEachChar (normalizedText);
224211 int i = 0 ;
225212 while (i < chars.size ()) {
@@ -236,8 +223,8 @@ class Lexicon {
236223 auto & [eng_phones, eng_tones] = lexicon[eng_word];
237224 phones.insert (phones.end (), eng_phones.begin (), eng_phones.end ());
238225 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 ());
241228 } else {
242229 process_unknown_english (orig_word, phones, tones);
243230 }
@@ -256,8 +243,8 @@ class Lexicon {
256243 auto & [phrase_phones, phrase_tones] = lexicon[phrase];
257244 phones.insert (phones.end (), phrase_phones.begin (), phrase_phones.end ());
258245 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 ());
261248 i += len;
262249 matched = true ;
263250 break ;
@@ -279,25 +266,25 @@ class Lexicon {
279266 auto & [char_phones, char_tones] = lexicon[s];
280267 phones.insert (phones.end (), char_phones.begin (), char_phones.end ());
281268 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 ());
284271 } else {
285272 phones.insert (phones.end (), unknown_token.first .begin (), unknown_token.first .end ());
286273 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 ());
289276 }
290277 }
291278 }
292279 phones.insert (phones.end (), unknown_token.first .begin (), unknown_token.first .end ());
293280 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 (" ====================" );
301288 }
302289
303290private:
@@ -316,6 +303,7 @@ class Lexicon {
316303 phones.insert (phones.end (), phones_and_tones.first .begin (), phones_and_tones.first .end ());
317304 tones.insert (tones.end (), phones_and_tones.second .begin (), phones_and_tones.second .end ());
318305 }
306+
319307 std::string phonesToString (const std::vector<int >& phones)
320308 {
321309 std::string result;
@@ -329,6 +317,7 @@ class Lexicon {
329317 }
330318 return result;
331319 }
320+
332321 std::string tonesToString (const std::vector<int >& tones)
333322 {
334323 std::string result;
0 commit comments