Amazing-Python-Scripts

Форк
0
666 строк · 22.1 Кб
1
import random
2
import speech_recognition as sr
3

4
vocabulary = {
5
    'apple': 'a fruit',
6
    'dog': 'an animal that barks',
7
    'cat': 'a small domesticated carnivorous mammal',
8
    'book': 'a written or printed work consisting of pages glued or sewn together along one side',
9
    'sun': 'the star around which the earth orbits',
10
    'moon': 'the natural satellite of the earth',
11
    'tree': 'a woody perennial plant',
12
    'ocean': 'a large body of salt water',
13
    'computer': 'an electronic device for storing and processing data',
14
    'music': 'vocal or instrumental sounds combined to produce beauty of form',
15
    'happy': 'feeling or showing pleasure or contentment',
16
    'sad': 'feeling or showing sorrow',
17
    'water': 'a colorless, transparent, odorless liquid',
18
    'sky': 'the region of the atmosphere above the earth',
19
    'mountain': 'a large natural elevation of the earth\'s surface',
20
    'friend': 'a person whom one knows and with whom one has a bond of mutual affection',
21
    'love': 'an intense feeling of deep affection',
22
    'time': 'the indefinite continued progress of existence',
23
    'work': 'activity involving mental or physical effort done to achieve a purpose',
24
    'study': 'the devotion of time and attention to acquiring knowledge',
25
    'write': 'mark (letters, words, or other symbols) on a surface',
26
    'learn': 'gain or acquire knowledge of or skill in (something) by study, experience, or being taught',
27
    'laugh': 'make the spontaneous sounds and movements of the face and body that are the instinctive expressions of lively amusement',
28
    'run': 'move at a speed faster than a walk',
29
    'eat': 'put (food) into the mouth and chew and swallow it',
30
    'drink': 'take (a liquid) into the mouth and swallow',
31
    'jump': 'push oneself off a surface and into the air by using the muscles in one\'s legs and feet',
32
    'sleep': 'be in a state of rest in which the eyes are closed',
33
    'happy': 'feeling or showing pleasure or contentment',
34
    'angry': 'having a strong feeling of or showing annoyance, displeasure, or hostility',
35
    'beautiful': 'pleasing the senses or mind aesthetically',
36
    'big': 'of considerable size or extent',
37
    'small': 'of a size that is less than normal or usual',
38
    'fast': 'moving or capable of moving at high speed',
39
    'slow': 'moving or operating at a low speed',
40
    'hot': 'having a high degree of heat or a high temperature',
41
    'cold': 'of or at a low or relatively low temperature',
42
    'old': 'having lived for a long time',
43
    'new': 'produced, introduced, or discovered recently or now for the first time',
44
    'happy': 'feeling or showing pleasure or contentment',
45
    'sad': 'feeling or showing sorrow',
46
    'flower': 'the seed-bearing part of a plant, consisting of reproductive organs',
47
    'house': 'a building for human habitation',
48
    'car': 'a road vehicle, typically with four wheels, powered by an internal combustion engine',
49
    'bicycle': 'a vehicle with two wheels, powered by pedals',
50
    'school': 'an institution for educating children',
51
    'pen': 'a tool for writing or drawing with ink',
52
    'pencil': 'a writing implement with a graphite or colored core',
53
    'phone': 'a device used to communicate through sound or speech',
54
    'television': 'a system for transmitting visual images and sound',
55
    'watch': 'a small timepiece worn on the wrist',
56
    'shoe': 'a covering for the foot',
57
    'shirt': 'a garment worn on the upper part of the body',
58
    'pants': 'an outer garment covering the body from the waist to the ankles',
59
    'hat': 'a covering for the head',
60
    'garden': 'a plot of ground where plants are cultivated',
61
    'river': 'a large natural stream of water',
62
    'lake': 'a large body of water surrounded by land',
63
    'beach': 'a sandy or pebbly shore by the ocean',
64
    'rain': 'water falling in drops from the atmosphere',
65
    'snow': 'atmospheric water vapor frozen into ice crystals',
66
    'cloud': 'a visible mass of condensed water vapor',
67
    'bird': 'a warm-blooded vertebrate with feathers and beak',
68
    'fish': 'a limbless cold-blooded vertebrate with gills',
69
    'insect': 'a small arthropod with six legs and typically wings',
70
    'computer': 'an electronic device for storing and processing data',
71
    'table': 'a piece of furniture with a flat top and legs',
72
    'chair': 'a separate seat for one person',
73
    'lamp': 'a device for giving light',
74
    'door': 'a hinged, sliding, or revolving barrier for closing an opening',
75
    'window': 'an opening in a wall to let in light and air',
76
    'wall': 'a continuous vertical brick or stone structure',
77
    'bookcase': 'a piece of furniture with shelves for books',
78
    'clock': 'a timepiece that shows the time',
79
    'guitar': 'a musical instrument with strings',
80
    'piano': 'a large musical instrument with a keyboard',
81
    'singer': 'a person who sings',
82
    'artist': 'a person who creates visual or performing arts',
83
    'chef': 'a professional cook',
84
    'doctor': 'a person trained in medicine',
85
    'firefighter': 'a person who extinguishes fires',
86
    'pilot': 'a person who operates an aircraft',
87
    'teacher': 'a person who educates others',
88
    'actor': 'a person who performs in plays or movies',
89
    'dentist': 'a person who treats teeth and oral health',
90
    'engineer': 'a person who designs and builds machines or structures',
91
    'waiter': 'a person who serves food in a restaurant',
92
    'police': 'a civil force responsible for maintaining law and order',
93
    'nurse': 'a person trained to care for the sick or infirm',
94
    'writer': 'a person who writes books, stories, or articles',
95
    'scientist': 'a person who conducts scientific research',
96
    'musician': 'a person who plays a musical instrument',
97
    'photographer': 'a person who takes photographs',
98
    'baker': 'a person who bakes bread and cakes',
99
    'painter': 'a person who creates paintings',
100
    'dancer': 'a person who performs dance',
101
    'engineer': 'a person who designs and builds machines or structures',
102
    'architect': 'a person who designs buildings and structures',
103
    'astronaut': 'a person trained for space travel',
104
    'athlete': 'a person proficient in sports and other physical exercises',
105
    'biologist': 'a person who studies living organisms',
106
    'economist': 'a person who studies economic systems',
107
    'geologist': 'a person who studies the earth and its history',
108
    'historian': 'a person who studies and writes about the past',
109
    'journalist': 'a person who reports news and events',
110
    'lawyer': 'a person who practices law and represents clients',
111
    'mathematician': 'a person who studies mathematics',
112
    'physicist': 'a person who studies the fundamental nature of the universe',
113
    'psychologist': 'a person who studies the mind and behavior',
114
    'sociologist': 'a person who studies society and social behavior',
115
}
116

117
grammar_exercise = [
118
    {
119
        'question': 'He ___ to the store every day.',
120
        'answer': 'goes'
121
    },
122
    {
123
        'question': 'They ___ in the park yesterday.',
124
        'answer': 'played'
125
    },
126
    {
127
        'question': 'She ___ a song beautifully.',
128
        'answer': 'sings'
129
    },
130
    {
131
        'question': 'I ___ my homework yesterday.',
132
        'answer': 'did'
133
    },
134
    {
135
        'question': 'We ___ lunch at noon.',
136
        'answer': 'have'
137
    },
138
    {
139
        'question': 'It ___ raining outside.',
140
        'answer': 'is'
141
    },
142
    {
143
        'question': 'They ___ going to the party.',
144
        'answer': 'are'
145
    },
146
    {
147
        'question': 'He ___ reading a book.',
148
        'answer': 'is'
149
    },
150
    {
151
        'question': 'She ___ her friend tomorrow.',
152
        'answer': 'will see'
153
    },
154
    {
155
        'question': 'We ___ to the beach last summer.',
156
        'answer': 'went'
157
    },
158
    {
159
        'question': 'The birds ___ in the sky.',
160
        'answer': 'fly'
161
    },
162
    {
163
        'question': 'The sun ___ in the east.',
164
        'answer': 'rises'
165
    },
166
    {
167
        'question': 'I ___ English for two years.',
168
        'answer': 'have been studying'
169
    },
170
    {
171
        'question': 'He ___ his bike last week.',
172
        'answer': 'fixed'
173
    },
174
    {
175
        'question': 'She ___ breakfast at 8 AM.',
176
        'answer': 'eats'
177
    },
178
    {
179
        'question': 'They ___ a movie tonight.',
180
        'answer': 'will watch'
181
    },
182
    {
183
        'question': 'The baby ___ asleep.',
184
        'answer': 'is'
185
    },
186
    {
187
        'question': 'We ___ the test yesterday.',
188
        'answer': 'passed'
189
    },
190
    {
191
        'question': 'I ___ to the radio every morning.',
192
        'answer': 'listen'
193
    },
194
    {
195
        'question': 'He ___ a letter to his friend.',
196
        'answer': 'wrote'
197
    },
198
    {
199
        'question': 'She ___ a picture of the sunset.',
200
        'answer': 'took'
201
    },
202
    {
203
        'question': 'They ___ the cookies yesterday.',
204
        'answer': 'ate'
205
    },
206
    {
207
        'question': 'I ___ in this city for five years.',
208
        'answer': 'have lived'
209
    },
210
    {
211
        'question': 'He ___ late for school yesterday.',
212
        'answer': 'was'
213
    },
214
    {
215
        'question': 'She ___ at the party tonight.',
216
        'answer': 'will dance'
217
    },
218
    {
219
        'question': 'We ___ a new car next week.',
220
        'answer': 'are buying'
221
    },
222
    {
223
        'question': 'The sun ___ in the west.',
224
        'answer': 'sets'
225
    },
226
    {
227
        'question': 'I ___ my keys yesterday.',
228
        'answer': 'lost'
229
    },
230
    {
231
        'question': 'He ___ his grandmother every Sunday.',
232
        'answer': 'visits'
233
    },
234
    {
235
        'question': 'She ___ her hair last month.',
236
        'answer': 'cut'
237
    },
238
    {
239
        'question': 'They ___ a good time at the party.',
240
        'answer': 'had'
241
    },
242
    {
243
        'question': 'I ___ the book last night.',
244
        'answer': 'read'
245
    },
246
    {
247
        'question': 'We ___ a lot of pictures on our vacation.',
248
        'answer': 'took'
249
    },
250
    {
251
        'question': 'He ___ a cup of coffee every morning.',
252
        'answer': 'drinks'
253
    },
254
    {
255
        'question': 'She ___ for her friend at the airport.',
256
        'answer': 'is waiting'
257
    },
258
    {
259
        'question': 'They ___ a pizza for dinner tonight.',
260
        'answer': 'will order'
261
    },
262
    {
263
        'question': 'I ___ with my friends last weekend.',
264
        'answer': 'played'
265
    },
266
    {
267
        'question': 'We ___ the movie last night.',
268
        'answer': 'watched'
269
    },
270
    {
271
        'question': 'He ___ in the garden every day.',
272
        'answer': 'works'
273
    },
274
    {
275
        'question': 'She ___ her sister this evening.',
276
        'answer': 'will meet'
277
    },
278
    {
279
        'question': 'They ___ to the mountains last summer.',
280
        'answer': 'went'
281
    },
282
    {
283
        'question': 'I ___ Spanish at school.',
284
        'answer': 'study'
285
    },
286
    {
287
        'question': 'He ___ his bike to work.',
288
        'answer': 'rides'
289
    },
290
    {
291
        'question': 'She ___ breakfast at 7 AM.',
292
        'answer': 'eats'
293
    },
294
    {
295
        'question': 'They ___ a movie last night.',
296
        'answer': 'watched'
297
    },
298
    {
299
        'question': 'The baby ___ up from a nap.',
300
        'answer': 'woke'
301
    },
302
    {
303
        'question': 'We ___ the test two days ago.',
304
        'answer': 'took'
305
    },
306
    {
307
        'question': 'I ___ to music every day.',
308
        'answer': 'listen'
309
    },
310
    {
311
        'question': 'He ___ a letter to his friend last week.',
312
        'answer': 'wrote'
313
    },
314
    {
315
        'question': 'She ___ a picture of the sunrise.',
316
        'answer': 'took'
317
    },
318
    {
319
        'question': 'They ___ the cookies yesterday.',
320
        'answer': 'ate'
321
    },
322
    {
323
        'question': 'I ___ in this city since 2010.',
324
        'answer': 'have lived'
325
    },
326
    {
327
        'question': 'He ___ late for school yesterday.',
328
        'answer': 'was'
329
    },
330
    {
331
        'question': 'She ___ at the party tomorrow.',
332
        'answer': 'will dance'
333
    },
334
    {
335
        'question': 'We ___ a new car next month.',
336
        'answer': 'are buying'
337
    },
338
    {
339
        'question': 'The sun ___ in the east.',
340
        'answer': 'rises'
341
    },
342
    {
343
        'question': 'I ___ my keys yesterday morning.',
344
        'answer': 'lost'
345
    },
346
    {
347
        'question': 'He ___ his grandmother every week.',
348
        'answer': 'visits'
349
    },
350
    {
351
        'question': 'She ___ her hair last week.',
352
        'answer': 'cut'
353
    },
354
    {
355
        'question': 'They ___ a good time at the party.',
356
        'answer': 'had'
357
    },
358
    {
359
        'question': 'I ___ the book yesterday evening.',
360
        'answer': 'read'
361
    },
362
    {
363
        'question': 'We ___ a lot of pictures on our vacation.',
364
        'answer': 'took'
365
    },
366
    {
367
        'question': 'He ___ a cup of coffee every morning.',
368
        'answer': 'drinks'
369
    },
370
    {
371
        'question': 'She ___ for her friend at the airport.',
372
        'answer': 'is waiting'
373
    },
374
    {
375
        'question': 'They ___ a pizza for dinner tonight.',
376
        'answer': 'will order'
377
    },
378
    {
379
        'question': 'I ___ with my friends last Saturday.',
380
        'answer': 'played'
381
    },
382
    {
383
        'question': 'We ___ the movie last night.',
384
        'answer': 'watched'
385
    },
386
    {
387
        'question': 'He ___ in the garden every day.',
388
        'answer': 'works'
389
    },
390
    {
391
        'question': 'She ___ her sister this evening.',
392
        'answer': 'will meet'
393
    },
394
    {
395
        'question': 'They ___ to the mountains last summer.',
396
        'answer': 'went'
397
    },
398
    {
399
        'question': 'I ___ Spanish at school.',
400
        'answer': 'study'
401
    },
402
    {
403
        'question': 'He ___ his bike to work every day.',
404
        'answer': 'rides'
405
    },
406
    {
407
        'question': 'She ___ breakfast at 7 AM.',
408
        'answer': 'eats'
409
    },
410
    {
411
        'question': 'They ___ a movie last night.',
412
        'answer': 'watched'
413
    },
414
    {
415
        'question': 'The baby ___ up from a nap.',
416
        'answer': 'woke'
417
    },
418
    {
419
        'question': 'We ___ the test two days ago.',
420
        'answer': 'took'
421
    },
422
    {
423
        'question': 'I ___ to music every day.',
424
        'answer': 'listen'
425
    },
426
    {
427
        'question': 'He ___ a letter to his friend last week.',
428
        'answer': 'wrote'
429
    },
430
    {
431
        'question': 'She ___ a picture of the sunrise.',
432
        'answer': 'took'
433
    },
434
    {
435
        'question': 'They ___ the cookies yesterday.',
436
        'answer': 'ate'
437
    },
438
    {
439
        'question': 'I ___ in this city since 2010.',
440
        'answer': 'have lived'
441
    },
442
    {
443
        'question': 'He ___ late for school yesterday.',
444
        'answer': 'was'
445
    },
446
    {
447
        'question': 'She ___ at the party tomorrow.',
448
        'answer': 'will dance'
449
    },
450
    {
451
        'question': 'We ___ a new car next month.',
452
        'answer': 'are buying'
453
    },
454
    {
455
        'question': 'The sun ___ in the east.',
456
        'answer': 'rises'
457
    },
458
    {
459
        'question': 'I ___ my keys yesterday morning.',
460
        'answer': 'lost'
461
    },
462
    {
463
        'question': 'He ___ his grandmother every week.',
464
        'answer': 'visits'
465
    },
466
    {
467
        'question': 'She ___ her hair last week.',
468
        'answer': 'cut'
469
    },
470
    {
471
        'question': 'They ___ a good time at the party.',
472
        'answer': 'had'
473
    },
474
    {
475
        'question': 'I ___ the book yesterday evening.',
476
        'answer': 'read'
477
    },
478
    {
479
        'question': 'We ___ a lot of pictures on our vacation.',
480
        'answer': 'took'
481
    },
482
    {
483
        'question': 'He ___ a cup of coffee every morning.',
484
        'answer': 'drinks'
485
    },
486
    {
487
        'question': 'She ___ for her friend at the airport.',
488
        'answer': 'is waiting'
489
    },
490
    {
491
        'question': 'They ___ a pizza for dinner tonight.',
492
        'answer': 'will order'
493
    },
494
    {
495
        'question': 'I ___ with my friends last Saturday.',
496
        'answer': 'played'
497
    },
498
    {
499
        'question': 'We ___ the movie last night.',
500
        'answer': 'watched'
501
    },
502
]
503

504
conversations = [
505
    {
506
        'question': 'What is your favorite color?',
507
        'answer': 'My favorite color is blue.'
508
    },
509
    {
510
        'question': 'Do you enjoy learning new things?',
511
        'answer': 'Yes, I love learning new things and expanding my knowledge.'
512
    },
513
    {
514
        'question': 'What languages can you speak?',
515
        'answer': 'I can speak English and Spanish fluently.'
516
    },
517
    {
518
        'question': 'Tell me a fun fact!',
519
        'answer': 'Sure! Did you know that honey never spoils? Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly edible!'
520
    },
521
    {
522
        'question': 'What do you like to do in your free time?',
523
        'answer': 'In my free time, I enjoy reading books and going for long walks.'
524
    },
525
    {
526
        'question': 'What\'s your favorite book or movie?',
527
        'answer': 'I really love the book "To Kill a Mockingbird" by Harper Lee.'
528
    },
529
    {
530
        'question': 'How do you stay motivated?',
531
        'answer': 'I stay motivated by setting goals and staying focused on achieving them.'
532
    },
533
    {
534
        'question': 'What are your goals for the future?',
535
        'answer': 'My goals include traveling to different countries and learning new languages.'
536
    },
537
    {
538
        'question': 'What\'s the most interesting language fact you know?',
539
        'answer': 'One fascinating fact is that the Inuit language has over 50 different words for "snow"!'
540
    },
541
    {
542
        'question': 'Tell me about an inspiring language learner!',
543
        'answer': 'Sure! There is a polyglot named Ziad Fazah who holds the Guinness World Record for speaking the most languages. He can speak 59 languages fluently!'
544
    },
545
    {
546
        'question': 'How do you deal with language learning challenges?',
547
        'answer': 'I overcome language learning challenges by practicing regularly and seeking help from language exchange partners.'
548
    },
549
    {
550
        'question': 'What advice would you give to new language learners?',
551
        'answer': 'My advice is to be patient with yourself, practice consistently, and immerse yourself in the language as much as possible.'
552
    },
553
    {
554
        'question': 'What\'s the best way to learn vocabulary?',
555
        'answer': 'Learning vocabulary through context and using flashcards or mnemonic techniques can be very effective.'
556
    },
557
    {
558
        'question': 'Can you recommend any language learning resources?',
559
        'answer': 'Certainly! There are many great language learning apps and websites like Duolingo, Memrise, and FluentU.'
560
    },
561
    {
562
        'question': 'What are the benefits of being multilingual?',
563
        'answer': 'Being multilingual opens up opportunities for better communication, cultural understanding, and career prospects.'
564
    },
565
    {
566
        'question': 'How can I improve my pronunciation?',
567
        'answer': 'Practicing with native speakers, listening to authentic materials, and using pronunciation apps can be helpful.'
568
    },
569
    {
570
        'question': 'What\'s the most challenging language to learn?',
571
        'answer': 'The difficulty of learning a language varies for each individual, but some consider languages with complex grammar and writing systems, like Mandarin Chinese or Arabic, to be challenging.'
572
    },
573
    {
574
        'question': 'How do you celebrate language learning milestones?',
575
        'answer': 'I celebrate language learning milestones by treating myself to a nice meal or doing something I enjoy.'
576
    },
577
    {
578
        'question': 'What are some common language learning myths?',
579
        'answer': 'One common myth is that you need to be naturally talented to learn a language. In reality, dedication and practice are more important.'
580
    },
581
    {
582
        'question': 'What languages are you currently learning?',
583
        'answer': 'Currently, I am focusing on improving my French and learning German.'
584
    },
585
    {
586
        'question': 'What language learning techniques do you use?',
587
        'answer': 'I use various techniques, including spaced repetition, interactive quizzes, and language immersion.'
588
    },
589
]
590

591

592
def vocabulary_quiz():
593
    print("AI Language Learning Assistant: Vocabulary Quiz")
594
    score = 0
595
    quiz_items = list(vocabulary.keys())
596
    random.shuffle(quiz_items)
597

598
    for word in quiz_items:
599
        user_answer = input(f"What does '{word}' mean? ")
600
        if user_answer.strip().lower() == vocabulary[word].lower():
601
            print("Correct!")
602
            score += 1
603
        else:
604
            print(f"Wrong. The correct answer is: {vocabulary[word]}")
605

606
    print(f"Quiz completed! Your score: {score}/{len(vocabulary)}")
607

608

609
def grammar_exercise_quiz():
610
    print("AI Language Learning Assistant: Grammar Exercise")
611
    score = 0
612

613
    for item in grammar_exercise:
614
        user_answer = input(item['question'] + " ")
615
        if user_answer.strip().lower() == item['answer'].lower():
616
            print("Correct!")
617
            score += 1
618
        else:
619
            print(f"Wrong. The correct answer is: {item['answer']}")
620

621
    print(
622
        f"Grammar exercise completed! Your score: {score}/{len(grammar_exercise)}")
623

624

625
def interactive_conversation_practice():
626
    print("AI Language Learning Assistant: Interactive Conversation Practice")
627
    print("Type 'exit' to end the conversation.")
628

629
    while True:
630
        conversation = random.choice(conversations)
631
        user_input = input("ChatBot: " + conversation['question'] + " ")
632
        if user_input.lower() == 'exit':
633
            break
634
        print("ChatBot:", conversation['answer'])
635

636

637
def detect_pronunciation_errors():
638
    print("AI Language Learning Assistant: Pronunciation Errors Detection")
639

640
    recognizer = sr.Recognizer()
641
    with sr.Microphone() as source:
642
        print("Speak a sentence for pronunciation evaluation:")
643
        recognizer.adjust_for_ambient_noise(source)
644
        audio = recognizer.listen(source)
645

646
    try:
647
        user_sentence = recognizer.recognize_google(audio)
648

649
        # Compare user_sentence with a pre-defined correct sentence to detect errors.
650
        # For simplicity, let's assume a fixed correct sentence.
651

652
        correct_sentence = "I love learning languages."
653
        if user_sentence.strip().lower() == correct_sentence.lower():
654
            print("Your pronunciation is great!")
655
        else:
656
            print("There might be some pronunciation errors. Keep practicing!")
657
    except sr.UnknownValueError:
658
        print("Sorry, I couldn't understand what you said.")
659
    except sr.RequestError:
660
        print("Sorry, there was an error processing the audio. Please try again.")
661

662

663
vocabulary_quiz()
664
grammar_exercise_quiz()
665
interactive_conversation_practice()
666
detect_pronunciation_errors()
667

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.