-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
37 lines (29 loc) · 1014 Bytes
/
main.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
import speech_recognition as sr
import chatbot as chat
import pyttsx3
engine = pyttsx3.init()
engine.setProperty('rate', 160)
def getInputData(speaktext = ""):
if len(speaktext) > 0:
speakText(speaktext)
audio = r.listen(source)
return r.recognize_google(audio, language="de-DE").lower()
def speakText(text):
engine.setProperty('voice', 'german')
engine.say(text)
engine.runAndWait()
r = sr.Recognizer()
with sr.Microphone() as source:
while True:
try:
text = getInputData()
print(text)
if "werner" in text:
print("Werner hört zu!")
response = chat.chat(text[text.index("werner") + 6:])
print(f"> {response}")
speakText(response)
except sr.UnknownValueError:
print("Could not understand audio!")
except sr.RequestError as e:
print("Could not access Google speech recognition service; {0}".format(e))