-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChatBot.py
More file actions
96 lines (56 loc) · 2 KB
/
ChatBot.py
File metadata and controls
96 lines (56 loc) · 2 KB
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
83
84
85
86
87
88
89
90
91
92
93
# coding: utf-8
# In[1]:
import speech_recognition as sr
r=sr.Recognizer()
def talk():
with sr.Microphone() as source:
audio=r.listen(source)
user=r.recognize_google(audio)
try:
print('Google recognised your speech as: \n' + user)
except:
pass
return user
# In[2]:
from translate import Translator
import pyttsx3
#chatbot = ChatBot('Harper', trainer = 'chatterbot.trainers.ListTrainer')
def main():
try:
engine = pyttsx3.init()
print("Welcome")
engine.say("Welcome to my Translator")
engine.setProperty('rate',120)
engine.setProperty('volume', 0.9)
engine.runAndWait()
print("What language would you like your text translated to?")
engine.say("What language would you like your text translated to?")
engine.setProperty('rate',120)
engine.setProperty('volume', 0.9)
engine.runAndWait()
lang_2 = talk()
print("From what language you want your text translated to?")
engine.say("From what language you want your text translated to?")
engine.setProperty('rate',120)
engine.setProperty('volume', 0.9)
engine.runAndWait()
lang_1=talk()
print('So What statement you want to convert?')
engine.say('So What statement you want to convert')
engine.setProperty('rate',120)
engine.setProperty('volume', 0.9)
engine.runAndWait()
request=talk()
translator= Translator(from_lang=lang_1,to_lang= lang_2)
translation = translator.translate(request)
print (translation)
engine.say(translation)
engine.setProperty('rate',120)
engine.setProperty('volume', 0.9)
engine.runAndWait()
except KeyboardInterrupt:
print("Program Interrupted")
main()
# In[ ]:
# In[ ]:
# In[ ]: