-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculatenumbers.py
48 lines (42 loc) · 1.23 KB
/
Calculatenumbers.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
import wolframalpha
import pyttsx3
import speech_recognition
# Initialize the text-to-speech engine
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
for voice in voices:
if "zira" in voice.name.lower():
engine.setProperty("voice", voice.id)
break
engine.setProperty("rate", 170)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def WolfRamAlpha(query):
apikey = "HEVXUJ-T9P3G7YK76"
requester = wolframalpha.Client(apikey)
response = requester.query(query)
try:
answer = next(response.results).text
# print(answer)
speak(answer)
return answer
except StopIteration:
speak("I'm sorry, I don't have an answer to that question")
return None
def Calc(query):
Term = str(query)
Term = Term.replace("plus", "+")
Term = Term.replace("minus", "-")
Term = Term.replace("multiply", "*")
Term = Term.replace("divide", "/")
Term = Term.replace("Daisy", "")
Final = str(Term)
try:
result = WolfRamAlpha(Final)
if result:
print(result)
# speak(result)
except Exception as e:
print(f"Error: {e}")
speak("I'm sorry, I don't have an answer to that question")