As we know Python is a suitable language for script writers and developers. Let’s write a script for Voice Assistant using Python. The query for the assistant can be manipulated as per the user’s need.
Speech recognition is the process of converting audio into text. This is commonly used in voice assistants like Alexa, Siri, etc. Python provides an
SpeechRecognition to allow us to convert audio into text for further processing. In this article, we will look at converting large or long audio files into text using the
SpeechRecognition API in python.
- Subprocess:- This module is used for getting system subprocess details which are used in various commands i.e Shutdown, Sleep, etc. This module comes buit-in with Python.
- Wolframalpha:- It is used to compute expert-level answers using Wolfram’s algorithms, knowledgebase and AI technology. To install this module type the below command in the terminal.
pip install wolframaplha
- Pyttsx3:- This module is used for conversion of text to speech in a program it works offline. To install this module type the below command in the terminal.
pip install pyttsx3
- Tkinter:- This module is used for building GUI and comes inbuit with Python. This module comes buit-in with Python.
- Wikipedia:- As we all know Wikipedia is a great source of knowledge just like GeeksforGeeks we have used Wikipedia module to get information from Wikipedia or to perform Wikipedia search. To install this module type the below command in the terminal.
pip install wikipedia
- Speech Recognition:- Since we’re building an Application of voice assistant, one of the most important things in this is that your assistant recognizes your voice (means what you want to say/ ask). To install this module type the below command in the terminal.
pip install SpeechRecognition
- Web browser:- To perform Web Search. This module comes buit-in with Python.
- ES capture:- To capture images from your Camera. To install this module type the below command in the terminal.
pip install escapture
- Pyjokes:- Pyjokes is used for collection Python Jokes over the Internet. To install this module type the below command in the terminal.
pip install pyjokes
- Datetime:- Date and Time is used to showing Date and Time. This module comes built-int with Python.
- Twilio:- Twilio is used for making call and messages. To install this module type the below command in the terminal.
pip install twilio
- Requests: Requests is used for making GET and POST requests. To install this module type the below command in the terminal.
pip install requests
- BeautifulSoup: Beautiful Soup is a library that makes it easy to scrape information from web pages. To install this module type the below command in the terminal.
pip install beautifulsoup4
Note: You can remove some of the import file if you don’t want to get that feature as here
twilio for making call and messages if you don’t want to use that you can simply remove that function.
Import the below libraries.
Now we will set our engine to Pyttsx3 which is used for text to speech in Python and sapi5 is Microsoft speech application platform interface we will be using this for text to speech function.
You can change voice Id to “0” for Male voice while using assistant here we are using Female voice for all text to speech
Main Function starts here, we will now call all these function in main function.
User said: Gaurav
Welcome Mr. Gaurav
User said: yes
(‘As the history majors among you here today know all too well, when people in power invent their own facts and attack those who question them, it can mark the beginning of the end of a free society. That is not hyperbole. It is what authoritarian regimes throughout history have done. They attempt to control reality. Not just our laws and our rights and our budgets, but our thoughts and beliefs.’, ‘Hillary Clinton’)
User said: Gaurav in Wikipedia
Gaurav is an Indian and Nepalese male name. The name literally means pride.
== Notable people named Gaurav ==
Gaurav S Bajaj, Indian television actor
Gaurav Bhatt, Indian Music Director, singer, songwriter.
User said: open YouTube
Unable to Recognizing your voice.
User said: exit
- Personal Voice Assistant in Python
- Python | Create a simple assistant using Wolfram Alpha API.
- Voice search Wikipedia using Python
- Text-To-Speech changing voice in Python
- Building App For Google Assistant Without Any Coding
- Python - Read blob object in python using wand library
- twitter-text-python (ttp) module - Python
- Reading Python File-Like Objects from C | Python
- MySQL-Connector-Python module in Python
- Python | Convert list to Python array
- Python | PRAW - Python Reddit API Wrapper
- Python | Index of Non-Zero elements in Python list
- Important differences between Python 2.x and Python 3.x with examples
- Python | Merge Python key values to list
- Python | Add Logging to Python Libraries
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to a Python Script
- Python | Sort Python Dictionaries by Key or Value
- Python | Visualizing O(n) using Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.