Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GUIScripts/Voice Calculator/Media/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GUIScripts/Voice Calculator/Media/microphone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GUIScripts/Voice Calculator/Media/mictone.mp3
Binary file not shown.
26 changes: 26 additions & 0 deletions GUIScripts/Voice Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Voice Calculator

## Aim:
Calculator working from voice commands

## Purpose ➕➖➗:
It's main purpose is to perform some simple calculations by just giving some voice commands 🎙 so just rest and give commands by speech and get the results ready.

## Description:
Here with the help of speech recognition and pyaudio packages of python we recognise the words and perform some simple mathematical calculations by some speech commands 🔊. It can perform addition, subtraction, multiplication, division, calculate the remainder, lcm and hcf just by voice commands 🗣. This is a smart calculator you can also perform some scientific calculations in it by simply clicking on the buttons. It recognises various keywords which can be spoken while giving the calculation commands such as addition, add, plus these all keywords heard will do the same operation to add ➕ two numbers. It is a gui program with the help of tkinter package we have created a calculator display and buttons.

## Workflow:
The user will simply run the program click on 🎙 button and 🗣 the commands and then you have to do nothing just wait for your result to get displayed on screen 🤓💡. It is a dual system calculator which can work by simply clicking the buttons and also through voice commands.


## Media

![Voice Calculator](Media/Screenshot 1)


![Voice Calculator](Media/Screenshot 2)


## Author

Khushi Sharma
200 changes: 200 additions & 0 deletions GUIScripts/Voice Calculator/Voice calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
from tkinter import *
import math

from pygame import mixer
import speech_recognition as s_r

mixer.init()

def click(value):
ex = entryField.get()
answer = ''

# given the commands to show what the various buttons will do

try:
if value == 'C':
ex = ex[0:len(ex) - 1]
entryField.delete(0, END)
entryField.insert(0, ex)
return

elif value == 'DEL':
entryField.delete(0, END)

elif value == '√':
answer = math.sqrt(eval(ex))

elif value == 'π':
answer = math.pi

elif value == 'sinθ':
answer = math.sin(math.radians(eval(ex)))

elif value == 'cosθ':
answer = math.cos(math.radians(eval(ex)))

elif value == 'tanθ':
answer = math.tan(math.radians(eval(ex)))

elif value == '2π':
answer = 2 * math.pi

elif value == 'cosh':
answer = math.cosh(eval(ex))

elif value == 'tanh':
answer = math.tanh(eval(ex))

elif value == 'sinh':
answer = math.sinh(eval(ex))

elif value == chr(8731):
answer = eval(ex) ** (1 / 3)

elif value == 'x\u02b8':
entryField.insert(END, '**')
return

elif value == 'x\u00B3':
answer = eval(ex) ** 3

elif value == 'x\u00B2':
answer = eval(ex) ** 2

elif value == 'ln':
answer = math.log2(eval(ex))

elif value == 'deg':
answer = math.degrees(eval(ex))

elif value == "rad":
answer = math.radians(eval(ex))

elif value == 'e':
answer = math.e

elif value == 'log₁₀':
answer = math.log10(eval(ex))

elif value == 'n!':
answer = math.factorial(ex)

elif value == chr(247):
entryField.insert(END, "/")
return

elif value == '=':
answer = eval(ex)

else:
entryField.insert(END, value)
return

entryField.delete(0, END)
entryField.insert(0, answer)

except SyntaxError:
pass

def add(a,b):
return a+b
def sub(a,b):
return a-b
def mul(a, b):
return a * b
def div(a, b):
return a / b
def mod(a, b):
return a % b
def lcm(a,b):
l=math.lcm(a,b)
return l
def hcf(a,b):
h=math.gcd(a,b)
return h

# Voice command operations

operations={'ADD':add,'ADDITION':add,'SUM':add,'PLUS':add,
'SUBTRACTION':sub , 'DIFFERENCE':sub , 'MINUS':sub , 'SUBTRACT':sub,
'PRODUCT': mul, 'MULTIPLICATION': mul,'MULTIPLY': mul,
'DIVISION': div, 'DIV': div, 'DIVIDE': div, 'DIVIDED BY':div,
'LCM':lcm , 'HCF':hcf,
'MOD':mod ,'REMAINDER':mod , 'MODULUS':mod
}

def findNumbers(t):
l=[]
for num in t:
try:
l.append(int(num))
except ValueError:
pass
return l

# the function will give the audio sound when you click the mic button

def audio():
mixer.music.load('Media/mictone.mp3')
mixer.music.play()
sr = s_r.Recognizer()
with s_r.Microphone()as m:
try:
sr.adjust_for_ambient_noise(m,duration=0.2)
voice=sr.listen(m)
text=sr.recognize_google(voice)

mixer.music.load('Media/mictone.mp3')
mixer.music.play()
text_list=text.split(' ')
for word in text_list:
if word.upper() in operations.keys():
l=findNumbers(text_list)
print(l)
result=operations[word.upper()](l[0],l[1]) #mul(5.0,6.0)
entryField.delete(0,END)
entryField.insert(END,result)
else:
pass
except:
pass

# The gui display of calculator

root = Tk()
root.title('Voice Calculator')
# Screen display colour and dimensions
root.config(bg='grey')
root.geometry('680x486+100+100')

logoImage = PhotoImage(file='Media/logo.png')
logoLabel = Label(root, image=logoImage, bg='grey')
logoLabel.grid(row=0, column=0)

entryField = Entry(root, font=('arial', 20, 'bold'), bg='grey', fg='white', bd=10, relief=SUNKEN, width=30)
entryField.grid(row=0, column=0, columnspan=8)

micImage = PhotoImage(file='Media/microphone.png')
micButton = Button(root, image=micImage, bd=0, bg='grey', activebackground='orange',command=audio)
micButton.grid(row=0, column=7)

#button list
button_text_list = ["C", "DEL", "√", "+", "π", "sinθ", "cosθ", "tanθ",
"1", "2", "3", "-", "2π", "cosh", "tanh", "sinh",
"4", "5", "6", "*", chr(8731), "x\u02b8", "x\u00B3", "x\u00B2",
"7", "8", "9", chr(247), "ln", "deg", "rad", "e",
"0", ".", "%", "=", "log₁₀", "( ", " )", "n!"]
rowvalue = 1
columnvalue = 0
for i in button_text_list:

button = Button(root, width=5, height=2, bd=2, relief=SUNKEN, text=i, bg='grey', fg='white',
font=('arial', 18, 'bold'), activebackground='orange', command=lambda button=i: click(button))
button.grid(row=rowvalue, column=columnvalue, pady=1)
columnvalue += 1
if(columnvalue>7):
rowvalue += 1
columnvalue = 0

root.mainloop()
6 changes: 6 additions & 0 deletions GUIScripts/Voice Calculator/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pip install pyaudio
pip install SpeechRecognition
pip install pygame
pip install tkinter
import math
import mixer