The coronavirus has caused havoc across the globe. Millions of people are infected and thousands are dead. The pandemic is still on the rise as all the countries in the world have imposed a lock down. Everybody has the rights to know how this virus has affected our lives as we continue to wage a war against it. So, I write this article about my project with a voice that addresses the current situation of the world.
In this project, you’ll learn how to build a COVID19 voice assistant using Python. The project mainly covers the fundamentals of web scraping, voice assistance and multi threading in python.
The project makes use of a tool called ParseHub. ParseHub is free web scraper that is very powerful and is easy to use. This tool allows you to scrape the web merely just by clicking on the elements you would like to get out from that website. So, the first step is to download ParseHub.
We will be scraping from the very famous website for statistics which is Worldometers that is regularly kept updated about the coronavirus information. Open up ParseHub -> Start New Project -> Paste the link to
Click on the elements you would like to scrape from the page and assign
unique tags to them. Use the relative tool to link let’s say, ‘Coronavirus Cases’ on the page with its number. The ParseHub is clearly very efficient and uses an AI to understand which elements you would want. To try this, link ‘USA’ with the ‘total cases’ and it does rest of the countries in the list for you. Amazing! What this is doing behind the scenes is constructing a JSON format of what you are linking above.
After you are done with the linking, hit ‘Get Data’, which may take a while.
Then make sure, on the next screen you note down the API key, Project
token and Run token.
Copy paste the code given in Part1.py and I shall walk you through what is really going on.
These points explain the Part1.py file:
As of now, your assistant speaks only the data you fetched initially. It
is important to keep the data updated, as this global pandemic is still
on, it would be soothing to hear it when your assistant says that the
number is declining.
Delete Part1.py and copy the Part2.py into your application.
The Part2.py has just an extra function and a handler for it in addition to Part1.py. This function is the update() function. The function, doesn’t fetch from the last run on parsehub, but instead initializes a new run on the parsehub servers for your project. This will take a while, so please give it some time when you are updating.
The most interesting part is to reduce this time. So, we make use of multi threading using the multithreading library in python. By doing this, we ensure that the voice assistant is running on one thread and the updating of data takes place parallely on another.
The most interesting part of this project is its result.
Run the Part2.py file and when the console says “Listening…”, say “number
of total cases” and the assistant would reply with the number of COVID19 cases across the world. Now say, “total deaths in India” and the
assistant would reply with this number.
You can say, “update” and the assistant will update the values for you which may take some time. Please wait patiently.
You will have to say “stop” to exit from the running application.
You did it! You just built a voice assistant that updates you about the
coronavirus by only using your voice. You can further develop this
project into amazing things. To get complete insight checkout my GitHub.
If you got any errors, feel free to reach out to me on my LinkedIn.
Hopefully, you enjoyed as well as understood this project.
Previously published at https://medium.com/@KGPrajwal/covid19-voice-assistant-63c37b1f02f9
Create your free account to unlock your custom reading experience.