Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd55178

Browse files
Merge pull request avinashkranjan#1024 from Arnab11917676/master
Voice Calculator
2 parents 5942824 + db555dc commit bd55178

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

‎Voice Calculator/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Voice Calculator
2+
3+
This is voice calculator capable enough to do difficult trigonometric probelms and simple arithmatic calculation and also Linear Expression.
4+
This will run in the terminal and all the instruction will be given while running it.
5+
6+
## Setup instructions
7+
8+
There way to run it on your Linux,MAC or Windows
9+
10+
- Run the program in your IDE or terminal/command line.
11+
12+
Click on the **Click Here** to see the Voice Calculator Demo on YouTube.
13+
14+
| Name of Script | YouTube Link | Author | Tools Used |
15+
| ---------------- | ------------------------------------------ | --------------------------------------------- | --------------------------------- |
16+
| Voice Calculator | [Click Here](https://youtu.be/cOgujLzl9zg) | [Arnab Ray](https://github.com/Arnab11917676) | Speech Recognition , Wolframalpha |
17+
18+
## Output
19+
20+
![image](https://user-images.githubusercontent.com/59610398/117536098-ccff8900-b016-11eb-809d-a63a3c23b39b.png)
21+
22+
## Author(s)
23+
24+
- [Arnab Ray](https://github.com/Arnab11917676)

‎Voice Calculator/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
speech_recognition
2+
pyttsx3
3+
wolframalpha

‎Voice Calculator/voiceCalc.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import os
2+
import pyttsx3
3+
import speech_recognition as sr
4+
import tkinter.messagebox as tmessage
5+
import wolframalpha
6+
7+
from os.path import exists
8+
9+
listener = sr.Recognizer()
10+
engine = pyttsx3.init()
11+
voices = engine.getProperty('voices')
12+
engine.setProperty('voice', voices[0].id)
13+
wolfprimeaplahe_app = input('Enter the API Token')
14+
15+
16+
def audio(audio):
17+
engine.say(audio)
18+
engine.runAndWait()
19+
20+
21+
def welcomeInst():
22+
print('Welcome to Calculator :)')
23+
audio('Welcome to Calculator :)')
24+
print('If you want calculate something please tell calcualte and then your expression')
25+
audio('If you want calculate something please tell calcualte and then your expression')
26+
print('For example CALCULATE 7 PLUS 8 or CALCULATE sin30 plus cot20')
27+
audio('For example CALCULATE 7 PLUS 8 or CALCULATE sin30 plus cot20')
28+
29+
30+
def _takeCommand():
31+
r = sr.Recognizer()
32+
with sr.Microphone() as source:
33+
print("Listening....")
34+
audio("Listning...")
35+
r.pause_threshold = 2
36+
r.energy_threshold = 3000
37+
audio = r.listen(source)
38+
39+
try:
40+
print("Recognizing...")
41+
audio("Recognizing...")
42+
query = r.recognize_google(audio, language='en-In')
43+
print(query)
44+
45+
except Exception as e:
46+
tmessage.showinfo('Error', f'{e}')
47+
print("Didn't understand you...\nCan you repeat?...")
48+
return "NONE"
49+
50+
return query
51+
52+
53+
def _calculate():
54+
client = wolframalpha.Client(wolfprimeaplahe_app)
55+
indx = spech.lower().split().index('calculate')
56+
query = spech.split()[indx + 1:]
57+
res = client.query(''.join(query))
58+
answerr = next(res.results).text
59+
space = '\n'
60+
ourQuery = ''.join(query)
61+
Question = 'Your Query was :- '
62+
Answer = 'Your answer was :- '
63+
finalAnswer = Question + str(ourQuery) + \
64+
space + Answer + str(answerr) + space
65+
66+
if exists('./Voice Calculator/maths.txt'):
67+
with open('./Voice Calculator/maths.txt', 'a', encoding='utf-8') as mth:
68+
mth.write(finalAnswer)
69+
mth.close()
70+
else:
71+
history = open('./Voice Calculator/maths.txt', 'w', encoding='utf-8')
72+
history.write(finalAnswer)
73+
history.close()
74+
print("The answer is " + answerr)
75+
audio("the answer is %s" % answerr)
76+
77+
78+
welcomeInst()
79+
80+
while True:
81+
82+
spech = _takeCommand().lower()
83+
84+
if 'calculate' in spech:
85+
_calculate()
86+
87+
elif 'clear' in spech:
88+
89+
if exists('./Voice Calculator/maths.txt'):
90+
with open('./Voice Calculator/maths.txt', 'r+') as file:
91+
file.truncate(0)
92+
file.close()
93+
print('done')
94+
95+
else:
96+
tmessage.showinfo('Error', 'No file exists with this name')
97+
98+
elif 'history' in spech:
99+
os.system('./Voice Calculator/maths.txt')
100+
101+
elif 'quit' in spech or 'exit' in spech:
102+
quit()
103+
104+
else:
105+
tmessage.showinfo('Opps', "Didn't understand")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /