-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.py
53 lines (41 loc) · 1.46 KB
/
compile.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
import speech_recognition as sr
import pyttsx3
from predict import init, predict
import time
from show import show_init, paint, pred_show
#pygame initialization
screen = show_init()
posx = 0
posy = 0
#model initialization
model, char_to_int, int_to_char, n_vocab = init()
#speech recognizer initialization
r = sr.Recognizer()
m = sr.Microphone()
audio3=[]
text = ''
start = True
time.sleep(15)
# Main program loop
while(start):
try:
with m as source:
r.adjust_for_ambient_noise(source)
print("start speaking")
audio = r.listen(source) # listening for speech
Mytext = r.recognize_google(audio) # Speech to text
Mytext = Mytext.lower()
Mytext += '. '
screen, posx, posy = paint(screen, Mytext, posx, posy) # show text in pygame
text += Mytext
if(len(text) > 100):
text = text[(len(text)-100):len(text)]
Predicted_text = predict(text, char_to_int, int_to_char, model, n_vocab) # future prediction of speech
screen = pred_show(screen, Predicted_text, posx, posy)
if(text[len(text)-4:] == 'quit'):
#speaking = False
start = False
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
except sr.UnknownValueError:
print("unknown error occured")