Python 3 PyAudio Script to Build a Voice Recognition Arithmetic Calculator Using Google Speech API Full Project For Beginners


Welcome folks today in this blog post we will be building a voice recognition arithmetic calculator using google speech api. All the full source code of the application is shown below.




Get Started



In order to get started you need to make an file and copy paste the following code



import operator
import speech_recognition as s_r
print("Your speech_recognition version is: "+s_r.__version__)
r = s_r.Recognizer()
my_mic_device = s_r.Microphone(device_index=1)
with my_mic_device as source:
    print("Say what you want to calculate, example: 3 plus 3")
    audio = r.listen(source)
def get_operator_fn(op):
    return {
        '+' : operator.add,
        '-' : operator.sub,
        'x' : operator.mul,
        'divided' :operator.__truediv__,
        'Mod' : operator.mod,
        'mod' : operator.mod,
        '^' : operator.xor,

def eval_binary_expr(op1, oper, op2):
    op1,op2 = int(op1), int(op2)
    return get_operator_fn(oper)(op1, op2)


Leave a Reply