-
Notifications
You must be signed in to change notification settings - Fork 0
/
questions.py
82 lines (66 loc) · 2.28 KB
/
questions.py
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
from re import I
import pyttsx3
import requests
from snapshots import *
import speech_recognition as sr
import playsound
from listen import *
from test import *
# initialisation
engine = pyttsx3.init()
def mcq_for_test():
response = requests.get("https://my-json-server.typicode.com/aswinikalyan30/jsonserver/db")
data = response.json()["questions"]
import time
c_answers = []
answers = []
for i in data:
c_answers.append(str(i["correct_answer"]))
i=0
while(i<len(data)):
#c_answers.append(str(data[i]["correct_answer"]))
engine.say(str(data[i]["question"]))
engine.say("A " + str(data[i]["answers"]["a"]))
engine.say("B " + str(data[i]["answers"]["b"]))
engine.say("C " + str(data[i]["answers"]["c"]))
engine.say("D " + str(data[i]["answers"]["d"]))
engine.say("..." + str(data[i]["answers"]["e"]))
engine.say("Answer Now:")
engine.runAndWait()
try:
print("before",i)
ans = listener()
snapshot()
if(ans=='repeat'):
print("after",i)
engine.say("Question will be repeated. Please answer carefully")
engine.runAndWait()
continue
engine.say("Is your answer option " + ans)
engine.runAndWait()
confirm = listener()
engine.say("You said " + confirm)
engine.runAndWait()
if confirm.lower() == "no":
engine.say("Question will be repeated. Please answer carefully")
engine.runAndWait()
continue
answers.append(ans)
print(ans)
except:
answers.append('a')
print("a")
if(i < 3):
i+=1
engine.say("Say YES to proceed ")
engine.runAndWait()
record_audio_test()
test_model()
score=0
print(c_answers,answers,score)
for j in range(len(c_answers)):
if(c_answers[j]==answers[j]):
score+=1
print(c_answers,answers,score)
engine.say("You have scored a total of " + str(score) +" out of "+str(len(data)) + " questions")
engine.runAndWait()