Tetany part one

I lived a normal life of a university student until the day when I suddenly stopped sleeping. It was weird. I couldn’t get myself to sleep at all. Not at night, not even during the day no matter how…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Mini Voice Assistant in Python.

You see many movies where computers communicate with their owner. So, here I came up with my Voice Assistant.

Voice Assistant in Python

Let’s start with our coding section, let’s go !!!

I am writing this code in python 3.6 and you can run this in Python 3.x + versions:

Firstly, You need to install some module to run efficiently :

1. pip install web browser

The web browser module provides a high-level interface to allow displaying Web-based documents to users. Under most circumstances, simply invoke the open() function from this module will do the right thing. You have to import the module and use an open() function. This will open your online things (google, youtube, etc.) in the browser.

2. pip install play sound

The playsound module is a cross-platform module that can play audio files. This doesn’t have any dependencies, simply install with pip in your virtualenv and run!

3. pip install gtts

There are several APIs available to convert text to speech in Python. One such APIs is the Google Text to Speech API commonly known as the gTTS API.
gTTS is a very easy-to-use tool that converts the text entered, into audio which can be saved as an mp3 file. However, as of the latest update, it is not possible to change the voice of the generated audio.

Speech Recognition is an important feature in several applications used such as home automation, artificial intelligence, etc. This article aims to provide an introduction on how to make use of the SpeechRecognition library of Python.
This is useful as it can be used on microcontrollers such as Raspberry Pis with the help of an external microphone.

5. pip install PyAudio

PyAudio provides Python bindings for PortAudio, the cross-platform audio I/O library. With PyAudio, you can easily use Python to play and record audio on a variety of platforms.
You need to download Pyaudio from —

search for pyaudio and download pyaudio according to your laptop/pc bits(32 or 64). If you get confused while installing refer to this video —

6. pip install Wikipedia

To extract data from Wikipedia, we must first install the Python Wikipedia library, which wraps the official Wikipedia API.

And last is python module time, os, Datetime, and Tkinter (This all is pre-defined library/module in python).

So, After importing all libraries our journey of code will start…Let’s Go !!!

Now the game start’s :

here we have defined the root for python Tkinter.

This is used for .mp3 file saving according to some speak done by the assistant.

Here we created a function named Speak which will convert text into speech in .mp3 format and it will save .mp3 file in the directory where you will save this project file.

Now it’s timed for creating a class that contains our GUI and Commands to execute named as Widget.

So, Our GUI will look like this :

In this, we have to give title, config, geometry(height and width for tkinter window), and resizeable (not compulsory here I have put it because I don’t want anyone to adjust it ). Next, I have written myself. context and self.userText variable and assign them as a string variable. After all this I have created a basic two frames named as userFrame and compFrame and
under that, I have created a Message (what we have to show in the frame of user and comp ) .

Now we need a button Two-button for start and close, so I have created a button as btn and btn2. Button1 calls the function named as an assistant (which I will create after this GUI function) and Button2 calls the destroy function of GUI as root.destroy that we normally used for destroying the Tkinter window.

There is the function of Commands name as an assistant which I even have told you within the previous paragraph in GUI function under Button1.

In, if condition I have given 0 in order that if it didn’t recognize your voice it’ll continue again and in elif condition, we’ve given all kinds of command and thereunder elif part we’ve given self.compText.set to print in GUI under compFrame and speak will speak the given answer which we’ve set.

In, else part we’ve given the Wikipedia part:

In this block, I even have created variable results where Wikipedia. a summary will take the text (user command) then what percentage sentences it should read and after it, I even have made it to talk the content which is coming in result variable by writing it in speak.

Here , A Full Source Code of Voice Assistant :

So, here we’ve finished making 💖 now enjoy running it 😉.

Add a comment

Related posts:

The Best Custom Web Development Services In UAE

At Global Advertising, we specialize in Custom Web Development and digital marketing services that are designed to help businesses achieve their goals and grow their brand. Whether you need help with…

Ghosn or Ghost?

After 14 months of arrest, the real-life dramatic escape of Ghosn inside an instrument luggage from the oppressive, inhumane, Japanese legal system (Ghosn’s words) to one of his three home countries…

Emotions in Marketing

While making a buying decision, we tend to be extremely calculative in our mind as we think about factors such as cost, quality of product etc. But is it possible that along with these calculative…