Coders Packet

Voice Based Calculator using SpeechRecognition, pyttsx3,gtts and googletrans in Python

By Pusuluri Sidhartha Aravind

A Python Project to perform basic mathematical calculations using audio using libraries such as SpeechRecognition, pyttsx3 and gTTs.

INTRODUCTION & FUNCTION:

To perform the normal mathematical calculation python works really well. But with the help of different libraries in python it is possible to make this process completely voice-based without having to input any details by hand.

In this project we use the different libraries mentioned below in the requirements section for the following uses:

pyttsx3 is a library used for performing text to speech conversions and so we use it for the conversion of the python calculated result to voice.

SpeechRecognition is a library used to perform the speech to text conversion with the help of attributes like pause_threshold and adjust_for_ambient_noise.

gtts is both a python library and a CLI tool with Google Translate API.

Within the code the say(audio,language) function performs the function of allowing the system to speak by converting the provided text into audio and presenting it.

Within the code the myCmd(param) function allows the voice input to be taken by the system with a set pause threshold of 0.5. 

REQUIREMENTS:

1. System should have installed Python 2.6 or above.

2. System should have PyAudio installed as per the system specification.

3.System should have the following installed with code for installation:

3.a. pyttsx3: pip install pyttsx3

3.b. SpeechRecognition: pip install SpeechRecognition

3.c. gtts: pip install gtts

3.d. googletrans: pip install googletrans

 

INPUT FORMAT:

operation operand1 connector operand2

Legend:

operation: multiply/add/subtract/divide

operand1,operand2: any number

connector: by/from/to/and(with certain conditions for each operation)

 

OUTPUT FORMAT:

Sample Output

The above-presented image shows how the interface works. The last line is "...." is a message displayed to the user in the case when no audio is detected from the user and the question is prompted again.

In the case when terminate the program the above-presented prompt is produced.

CONCLUSION:

The output says the answer of the calculation as per the input provided and further asks if one wants to continue with different calculations. This is an application of voice recognition and voice response with the help of python libraries

Download Complete Code

Comments

No comments yet