-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspeech.py
70 lines (53 loc) · 1.53 KB
/
speech.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
import speech_recognition as sr
import pyaudio
import pyttsx3
from database import retrieve_question, insert_val, set_good, set_okay, set_bad, set_additional
listener= sr.Recognizer()
value=0
engine = pyttsx3.init()
engine.setProperty('rate',120)
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def listen():
try:
with sr.Microphone() as source:
print("listening")
voice = listener.listen(source)
command = listener.recognize_google(voice)
print(command)
return command
#value=int(command)
#print(value)
except Exception as e:
print(str(e))
def talk(text):
engine.say("Okay")
engine.say(text)
engine.runAndWait()
def good(response, q):
if('good' in response):
print('setting good')
set_good(q)
return
def ok(response, q):
if('okay' in response or 'ok' in response):
set_okay(q)
talk("Please provide additional details.")
details=listen()
set_additional(details, q)
def bad(response, q):
if('bad' in response):
print('setting bad')
set_bad(q)
talk("Please provide additional details")
details=listen()
set_additional(details, q)
questions= retrieve_question()
for q in questions:
talk(q[0])
ans=listen()
good(ans,q[0])
ok(ans,q[0])
bad(ans,q[0])
if(q[-1]==1):
insert_val(ans,q[0])