-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmandarin_phrases_supplementary.py
More file actions
508 lines (481 loc) · 13.9 KB
/
mandarin_phrases_supplementary.py
File metadata and controls
508 lines (481 loc) · 13.9 KB
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
import argparse
import os
import time
import asyncio
import edge_tts
# Define supplementary phrases by category
# Education & Academic Life
education_phrases = {
"School Subjects": [
{
"zh": "数学",
"pinyin": "shùxué",
"en": "mathematics"
},
{
"zh": "物理",
"pinyin": "wùlǐ",
"en": "physics"
},
{
"zh": "化学",
"pinyin": "huàxué",
"en": "chemistry"
},
{
"zh": "生物",
"pinyin": "shēngwù",
"en": "biology"
},
{
"zh": "历史",
"pinyin": "lìshǐ",
"en": "history"
},
{
"zh": "地理",
"pinyin": "dìlǐ",
"en": "geography"
},
{
"zh": "文学",
"pinyin": "wénxué",
"en": "literature"
}
],
"Classroom Phrases": [
{
"zh": "请举手",
"pinyin": "qǐng jǔshǒu",
"en": "please raise your hand"
},
{
"zh": "我不明白",
"pinyin": "wǒ bù míngbai",
"en": "I don't understand"
},
{
"zh": "能再解释一遍吗?",
"pinyin": "néng zài jiěshì yībiàn ma?",
"en": "Can you explain again?"
},
{
"zh": "下课了",
"pinyin": "xià kè le",
"en": "class is over"
},
{
"zh": "考试",
"pinyin": "kǎoshì",
"en": "exam"
}
]
}
# Hobbies & Interests
hobbies_phrases = {
"Sports": [
{
"zh": "足球",
"pinyin": "zúqiú",
"en": "football/soccer"
},
{
"zh": "篮球",
"pinyin": "lánqiú",
"en": "basketball"
},
{
"zh": "游泳",
"pinyin": "yóuyǒng",
"en": "swimming"
},
{
"zh": "网球",
"pinyin": "wǎngqiú",
"en": "tennis"
},
{
"zh": "跑步",
"pinyin": "pǎobù",
"en": "running"
}
],
"Arts & Entertainment": [
{
"zh": "看电影",
"pinyin": "kàn diànyǐng",
"en": "watch movies"
},
{
"zh": "听音乐",
"pinyin": "tīng yīnyuè",
"en": "listen to music"
},
{
"zh": "画画",
"pinyin": "huàhuà",
"en": "painting"
},
{
"zh": "摄影",
"pinyin": "shèyǐng",
"en": "photography"
},
{
"zh": "弹钢琴",
"pinyin": "tán gāngqín",
"en": "play piano"
}
],
"Reading & Literature": [
{
"zh": "小说",
"pinyin": "xiǎoshuō",
"en": "novel"
},
{
"zh": "诗歌",
"pinyin": "shīgē",
"en": "poetry"
},
{
"zh": "杂志",
"pinyin": "zázhì",
"en": "magazine"
},
{
"zh": "漫画",
"pinyin": "mànhuà",
"en": "comics"
},
{
"zh": "科幻小说",
"pinyin": "kēhuàn xiǎoshuō",
"en": "science fiction"
}
]
}
# Emotions & Feelings
emotions_phrases = {
"Basic Emotions": [
{
"zh": "高兴",
"pinyin": "gāoxìng",
"en": "happy"
},
{
"zh": "伤心",
"pinyin": "shāngxīn",
"en": "sad"
},
{
"zh": "生气",
"pinyin": "shēngqì",
"en": "angry"
},
{
"zh": "害怕",
"pinyin": "hàipà",
"en": "afraid"
},
{
"zh": "紧张",
"pinyin": "jǐnzhāng",
"en": "nervous"
},
{
"zh": "兴奋",
"pinyin": "xīngfèn",
"en": "excited"
}
],
"Complex Feelings": [
{
"zh": "失望",
"pinyin": "shīwàng",
"en": "disappointed"
},
{
"zh": "骄傲",
"pinyin": "jiāo'ào",
"en": "proud"
},
{
"zh": "感动",
"pinyin": "gǎndòng",
"en": "moved/touched"
},
{
"zh": "困惑",
"pinyin": "kùnhuò",
"en": "confused"
},
{
"zh": "担心",
"pinyin": "dānxīn",
"en": "worried"
}
],
"Expressing Feelings": [
{
"zh": "我觉得很...",
"pinyin": "wǒ juéde hěn...",
"en": "I feel very..."
},
{
"zh": "让我很开心",
"pinyin": "ràng wǒ hěn kāixīn",
"en": "makes me happy"
},
{
"zh": "我有点儿...",
"pinyin": "wǒ yǒu diǎnr...",
"en": "I'm a bit..."
},
{
"zh": "心情不好",
"pinyin": "xīnqíng bù hǎo",
"en": "in a bad mood"
}
]
}
# Weather & Daily Life
daily_life_phrases = {
"Weather Conditions": [
{
"zh": "晴天",
"pinyin": "qíngtiān",
"en": "sunny day"
},
{
"zh": "下雨",
"pinyin": "xiàyǔ",
"en": "raining"
},
{
"zh": "多云",
"pinyin": "duōyún",
"en": "cloudy"
},
{
"zh": "刮风",
"pinyin": "guāfēng",
"en": "windy"
},
{
"zh": "下雪",
"pinyin": "xiàxuě",
"en": "snowing"
},
{
"zh": "潮湿",
"pinyin": "cháoshī",
"en": "humid"
}
],
"Daily Routines": [
{
"zh": "起床",
"pinyin": "qǐchuáng",
"en": "get up"
},
{
"zh": "刷牙",
"pinyin": "shuāyá",
"en": "brush teeth"
},
{
"zh": "洗澡",
"pinyin": "xǐzǎo",
"en": "take a shower"
},
{
"zh": "吃早饭",
"pinyin": "chī zǎofàn",
"en": "eat breakfast"
},
{
"zh": "上班",
"pinyin": "shàngbān",
"en": "go to work"
},
{
"zh": "下班",
"pinyin": "xiàbān",
"en": "get off work"
}
],
"Shopping Types": [
{
"zh": "服装店",
"pinyin": "fúzhuāng diàn",
"en": "clothing store"
},
{
"zh": "书店",
"pinyin": "shūdiàn",
"en": "bookstore"
},
{
"zh": "药店",
"pinyin": "yàodiàn",
"en": "pharmacy"
},
{
"zh": "面包店",
"pinyin": "miànbāo diàn",
"en": "bakery"
},
{
"zh": "水果店",
"pinyin": "shuǐguǒ diàn",
"en": "fruit store"
}
]
}
# Comparison Structures
comparison_phrases = {
"Basic Comparisons": [
{
"zh": "比...更",
"pinyin": "bǐ... gèng",
"en": "more... than"
},
{
"zh": "没有...那么",
"pinyin": "méiyǒu... nàme",
"en": "not as... as"
},
{
"zh": "跟...一样",
"pinyin": "gēn... yīyàng",
"en": "same as..."
},
{
"zh": "最...",
"pinyin": "zuì...",
"en": "the most..."
}
],
"Example Sentences": [
{
"zh": "这个比那个贵",
"pinyin": "zhège bǐ nàge guì",
"en": "this is more expensive than that"
},
{
"zh": "今天没有昨天热",
"pinyin": "jīntiān méiyǒu zuótiān rè",
"en": "today is not as hot as yesterday"
},
{
"zh": "这两个一样好",
"pinyin": "zhè liǎng ge yīyàng hǎo",
"en": "these two are equally good"
},
{
"zh": "这是最好的选择",
"pinyin": "zhè shì zuì hǎo de xuǎnzé",
"en": "this is the best choice"
}
]
}
# Dictionary mapping categories to phrase dictionaries
supplementary_phrases = {
"education": education_phrases,
"hobbies": hobbies_phrases,
"emotions": emotions_phrases,
"daily_life": daily_life_phrases,
"comparisons": comparison_phrases
}
def generate_text_file(category, format_type):
"""Generate a text file with all phrases for a specific category"""
print(f"Generating {category} {format_type} text file...")
phrases_dict = supplementary_phrases[category]
# Ensure the text_files directory exists
os.makedirs("text_files/supplementary", exist_ok=True)
with open(f"text_files/supplementary/{category}_{format_type}.txt", "w", encoding="utf-8") as f:
for subcategory, phrase_list in phrases_dict.items():
f.write(f"\n{subcategory}\n")
f.write("-" * len(subcategory) + "\n")
for phrase in phrase_list:
if format_type == "zh":
f.write(f"{phrase['zh']}\n")
elif format_type == "pinyin":
f.write(f"{phrase['pinyin']}\n")
else: # English
f.write(f"{phrase['en']}\n")
print(f"✓ Saved to text_files/supplementary/{category}_{format_type}.txt")
async def generate_audio(category, format_type="zh", voice=None):
"""Generate audio file for a specific category using edge-tts"""
# Set default voice based on language
if voice is None:
voice = "zh-CN-XiaoxiaoNeural" if format_type == "zh" else "en-US-JennyNeural"
print(f"\nGenerating {category} {format_type} audio file...")
start_time = time.time()
phrases_dict = supplementary_phrases[category]
# Generate text for phrases
text = ""
for subcategory, phrase_list in phrases_dict.items():
for phrase in phrase_list:
# Add appropriate punctuation based on language
if format_type == "zh":
text += phrase['zh'] + "。"
else:
text += phrase['en'] + ". "
# Ensure the audio_files directory exists
os.makedirs("audio_files/supplementary", exist_ok=True)
# Configure edge-tts
communicate = edge_tts.Communicate(text, voice)
# Generate audio
await communicate.save(f"audio_files/supplementary/{category}_{format_type}.mp3")
elapsed = time.time() - start_time
print(f"✓ Saved to audio_files/supplementary/{category}_{format_type}.mp3 ({elapsed:.2f}s)")
async def main():
parser = argparse.ArgumentParser(description="Generate supplementary Mandarin and English learning files")
parser.add_argument("--category", "-c", type=str,
choices=["education", "hobbies", "emotions", "daily_life", "comparisons"],
default=None,
help="Category to generate. If not specified, generates all categories.")
parser.add_argument("--text-only", "-t", action="store_true",
help="Generate only text files (no audio)")
parser.add_argument("--voice", "-v", type=str,
help="Voice to use for audio generation")
parser.add_argument("--language", "-l", type=str, choices=["zh", "en", "both"], default="both",
help="Language to generate audio for (zh=Chinese, en=English, both=Both languages)")
args = parser.parse_args()
# Determine which categories to process
categories_to_process = [args.category] if args.category else supplementary_phrases.keys()
# Process each category
for category in categories_to_process:
print(f"\n=== Processing {category} ===")
# Generate text files for Chinese characters, Pinyin, and English
generate_text_file(category, "zh")
generate_text_file(category, "pinyin")
generate_text_file(category, "en")
# Generate audio files if not text-only mode
if not args.text_only:
if args.language in ["zh", "both"]:
await generate_audio(category, "zh", args.voice)
if args.language in ["en", "both"]:
await generate_audio(category, "en", args.voice)
print("\nAll supplementary files generated successfully!")
print("\nUsage examples:")
print(" - Generate text files only: python mandarin_phrases_supplementary.py --text-only")
print(" - Generate files for just education: python mandarin_phrases_supplementary.py --category education")
print(" - Generate Chinese audio only: python mandarin_phrases_supplementary.py --language zh")
print(" - Generate English audio only: python mandarin_phrases_supplementary.py --language en")
print(" - Generate with different voice: python mandarin_phrases_supplementary.py --voice en-US-JennyNeural")
print("\nAvailable voices:")
print("Chinese voices:")
print(" - zh-CN-XiaoxiaoNeural (Default female)")
print(" - zh-CN-YunxiNeural (Male)")
print(" - zh-CN-XiaoyiNeural (Female)")
print(" - zh-CN-YunyangNeural (Male)")
print("\nEnglish voices:")
print(" - en-US-JennyNeural (Default female)")
print(" - en-US-GuyNeural (Male)")
print(" - en-US-AriaNeural (Female)")
print(" - en-US-DavisNeural (Male)")
if __name__ == "__main__":
asyncio.run(main())