588
588
},
589
589
]
590
590
591
+
591
592
def vocabulary_quiz ():
592
593
print ("AI Language Learning Assistant: Vocabulary Quiz" )
593
594
score = 0
594
595
quiz_items = list (vocabulary .keys ())
595
596
random .shuffle (quiz_items )
596
-
597
+
597
598
for word in quiz_items :
598
599
user_answer = input (f"What does '{ word } ' mean? " )
599
600
if user_answer .strip ().lower () == vocabulary [word ].lower ():
600
601
print ("Correct!" )
601
602
score += 1
602
603
else :
603
604
print (f"Wrong. The correct answer is: { vocabulary [word ]} " )
604
-
605
+
605
606
print (f"Quiz completed! Your score: { score } /{ len (vocabulary )} " )
606
607
608
+
607
609
def grammar_exercise_quiz ():
608
610
print ("AI Language Learning Assistant: Grammar Exercise" )
609
611
score = 0
610
-
612
+
611
613
for item in grammar_exercise :
612
614
user_answer = input (item ['question' ] + " " )
613
615
if user_answer .strip ().lower () == item ['answer' ].lower ():
614
616
print ("Correct!" )
615
617
score += 1
616
618
else :
617
619
print (f"Wrong. The correct answer is: { item ['answer' ]} " )
618
-
619
- print (f"Grammar exercise completed! Your score: { score } /{ len (grammar_exercise )} " )
620
+
621
+ print (
622
+ f"Grammar exercise completed! Your score: { score } /{ len (grammar_exercise )} " )
623
+
620
624
621
625
def interactive_conversation_practice ():
622
626
print ("AI Language Learning Assistant: Interactive Conversation Practice" )
623
627
print ("Type 'exit' to end the conversation." )
624
-
628
+
625
629
while True :
626
630
conversation = random .choice (conversations )
627
631
user_input = input ("ChatBot: " + conversation ['question' ] + " " )
628
632
if user_input .lower () == 'exit' :
629
633
break
630
634
print ("ChatBot:" , conversation ['answer' ])
631
635
636
+
632
637
def detect_pronunciation_errors ():
633
638
print ("AI Language Learning Assistant: Pronunciation Errors Detection" )
634
-
639
+
635
640
recognizer = sr .Recognizer ()
636
641
with sr .Microphone () as source :
637
642
print ("Speak a sentence for pronunciation evaluation:" )
638
643
recognizer .adjust_for_ambient_noise (source )
639
644
audio = recognizer .listen (source )
640
-
645
+
641
646
try :
642
647
user_sentence = recognizer .recognize_google (audio )
643
-
648
+
644
649
# Compare user_sentence with a pre-defined correct sentence to detect errors.
645
650
# For simplicity, let's assume a fixed correct sentence.
646
-
651
+
647
652
correct_sentence = "I love learning languages."
648
653
if user_sentence .strip ().lower () == correct_sentence .lower ():
649
654
print ("Your pronunciation is great!" )
@@ -654,6 +659,7 @@ def detect_pronunciation_errors():
654
659
except sr .RequestError :
655
660
print ("Sorry, there was an error processing the audio. Please try again." )
656
661
662
+
657
663
vocabulary_quiz ()
658
664
grammar_exercise_quiz ()
659
665
interactive_conversation_practice ()
0 commit comments