Voice Assistant with Python | Create A Voice Assistant like Google and SIRI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys my name is rishikesh sahu and today we are going to work on a project that is a voice assistant yes a voice assistant that will accept what you say it will hear what you say and also perform the task you ask it to play for example if you ask it to play a video on youtube it will do it so let us first look at what our final product looks like then then we'll shift to the coding part hello sir good evening i'm your voice assistant today is 31 of october and it's currently 12 59 a.m temperature in new delhi is 21.1 degrees celsius and with smoke let me start by asking how are you i'm absolutely fine what about you i am also having a good day sir what can i do for you can you please play a video for me you want me to play which video believer playing believer on youtube [Applause] what can i do for you can you please give me some information sure sir you need information related to which topic neutron stars searching neutron stars in wikipedia what can i do for you can you please read the latest news to me sure sir now i will read news for you number one generator messenger stock republican head of super super clearance number two swing state butter space materials returning ballots on time usps data shows the washington post number three lauren against sentence in college admissions scandal nbc news what can i do for you tell me an interesting fact sure sir did you know that due to the paraguay's central location in south america it is sometimes referred to as the heart of south america what can i do for you tell me a joke sure sir get ready for some chuckles why did sweden start painting barcodes on the sides of their battleships so they could scandinavian hey guys welcome back now we'll shift to the coding part of our program and we'll first see how to convert text to speech in python to convert text to speech we have a module known as pytts x3 it does not come with python all along so we have to install it first right so to install it open your terminal open it whether you are using pycharm or any other id like vs code right and right here pip install pytts x3 it's python text to speech version 3. module is already installed in my computer so it says requirement already satisfied but in your computer it may take some time right so we'll move further we'll close the terminal and we'll import this module i'm importing it as p because just for my convenience and then we'll initiate an instance of the p dot init class here this engine is an instance of the p dot init class which is inside this pyth module what it does it just gets the information of the current driver you are using right see it in the first go it may sound a bit complicated but just remember for your convenience that it is used to initiate the pytts x3 which we are using to convert text to speech right so what next we will do to our computer to speak for us we will write engine dot say and then we'll add the text we want our computer to say right hello world my name is nova right hello world i'll add a full stop after that and after this we'll ask a computer to wait for us until the sentence gets finished engine dot run and wait let me recall it for you the same method of the engine instance helps the computer to save for us and the run and wait ask the computer to wait until the sentence gets finished hello so we'll run and check how it goes hello world my name is nova see it was phenomenal it was working as expected see now there are several properties in this pytts x3 module which can be changed like the voice of the computer and the speed of the computer and various others so let us first check what all properties can we change for example we want to adjust the rate the speed of the voice right so we will write this rate is equal to engine dot get property and then we write the characteristic we want to know about like in our case it is rate for now and then we will print this print great and now we'll again run our program and see what the default rate is hello world my name is nova as you see the default rate is 200 right we can change this property by using the method set property for example we write engine dot set property and then we'll mention the characteristic we want to change like for in our example we want to change the rate and then the value we want to set for it for example uh it is by default it is 120 so if we set it at 130 it will be a little slow in compared to the default rate let us check whether it is fine or not hello world my name is nova as you see it was comparatively slow but it was too slow for us so we will set it at 180 maybe i think it will work hello world my name is nova yes it is perfect so now let us look at what all voices our windows operating system you know offer us so let us check it so now we'll have a look at the voices voices is equal to engine dot get property voices and then we'll print this voices this yeah voices right we declared a variable here that captures the output of the engine.getproperty method and then we'll print it let us see what happens what it returns us right hello world my name is nova as you can see it returned us a list of two items nothing as such is clear from that but we can tell that these are the voices as we pass the voices characteristic so these are these are the two voices which the windows offers us right we can check them by writing this code let me show you how we can actually listen to them rather than just seeing the text we'll write here engine dot set property voices and then we'll pass the voice we want right so we'll write voices let us check what was there in the first element of the list id so what we just are going to run we will be able to hear this piece of voice right so let us run our program hello world my name is nova so it is still a male voice so we can judge from this that the first element in this list was a male voice now we'll check for the second element in this list just a second i have to make it voice right hello world my name is nova see as you can hear the second voice was of a female right this voice was of a female so these are the properties you can adjust using the pytts x3 module and you can check their official documentation for more information let us try our hands on on some other examples like hi what are you doing let us run it hi what are you doing now we'll work on some other examples hi there i'm your voice assistant and we'll set it to 130 maybe so you can set the properties once hello there i am your voice assistant see it is working perfectly fine and you have to just set this property once and they'll work for all time right so now we'll see how to convert speech to text right so let's go so now we'll work on converting speech to text and for converting speech to text in python we have a module known as speech recognition and similarly like pytts x3 we have to install it using the terminal it does not come with python p installed so we'll go to the terminal and right here pip install speech recognition as you can see i've written it is already there in my computer and it may take some time in yours to install and here i'd like to tell you that i am using an anaconda environment you can install anaconda in your computer it is a very good software it comes with python with it and it is better than python as it allows you to install some packages which you cannot install with pip right you can install an anaconda from their official website anaconda.com just go to the products individual edition and here you you can install it install anaconda on your computer it comes with many applications like jupiter notebook anaconda prompt jupiter lab and spider it it is very useful and i'm using uh anaconda in my project because i have to use pi audio and it shows some problem if you use pip to install it right so i'll use it i'll use anaconda to install it so i'll write conda install pi audio it is already there in my computer and it may take some time in yours right so now we'll work on converting speech to text first of all i'll import the speech recognition module i'll write import speech recognition as sr then i'll create an instance of the recognizer class i'll tell you in a moment what it is r is equal to sr dot recognizer see this recognizer class basically creates an instance that helps us to retrieve information from a source that will be microphone in our case so in simpler word it helps us to retrieve the audio from our microphone now we'll convert the speech to text the main code comes here we'll write with sr dot microphone as source and uh if we want the computer to listen to us we we have a method known as r dot listen the source right and after that we store the listen in an audio so basically what this listen function does is that it listens to what we say and captures it in our microphone and saves the audio in the variable we have just mentioned here that is the audio now we'll send this audio to the google api engine which will convert it to a text right we'll write text is equal to r dot recognize google and then we'll add the audio what this line of code does is that it converts the audio it sends the audio to the google api engine and the google api engine converts the audio we have entered to a text we can check it by printing the text print text just like that so now what will this piece of codes do is that it will capture the voice it will capture what we say through the microphone as a source and then it will send it to the google apis which will convert it to the text and uh we'll print the text right before running this program i would like to adjust some of the background uh properties like the energy threshold and the ambient noise right i i'll tell you in a moment what they are first of all let me write the code now what is energy what this energy threshold does is that it increases the spectrum of our voice like if we increase the value of energy threshold then it will capture even the low voices right so by experimenting i found that 10 000 works just fine for me right so and this adjust for ambient noise what it does is it cancels all the noises around you right so it it will not capture all the noises around you and it will just capture your voice so let us just run and check what it does let me just right here print listening hello there i am your voice assistant hello there how are you as you can see it just captured what i said and you can see it displayed it here using the print text hello there how are you let us try it once more but first of all let me remove what i uh printed here it is of no use now the voices hello there i am your voice assistant hi my name is rishikesh as you can see it displayed what i said right so it is working absolutely fine so now we'll make our code a little bit more functional and make it a real voice assistant right so let's go further so every time i want my computer to say something from me then i have to write these two lines of code so instead of writing these two end of code i will write a function that will do it for me def speak it will take the text i wanted to speak and the speak will take the text and it will say for us right it's just perfect so now let us make a script how what will the workflow of our uh voice assistant so first of all it will ask us hello sir i am your voice assistant and how are you right so let us do it speak hello sir i am your voice assistant how are you it will ask us how are you and we'll give an answer to it which will get stored in the text so if the text consists of what about you then i'll make it to speak i am having a good day sir and then there'll be a mandatory line speak what can i do for you let us check whether it works or not hello sir i'm your voice assistant how are you i'm absolutely fine what about you i am having a good day sir what can i do for you see it worked as expected we if we add a comma here then it will be a pause i'm having i'm also let me write i'm also having a good day right so it works just fine for us now suppose i want to add some more functionality to my voice assistant right so i want to add automation to it for example if i want some information from the voice assistant then what i wanted to do is i wanted to go to the wikipedia.org page search for the information for me and display the page related to that information for example if i search for neutron stars then it it should go to the wikipedia home page it will search for neutron stars and show me the result it will be a pure automation based task and for that we'll use a selenium webdriver so i'll make a new python page named selenium web and here i'll write all the code related to my selenium webdriver so guys now we will see how to add automation in our program for that i'll use selenium webdriver we have to install it using the terminal so i'll go to the terminal i'll write pip install selenium it is already there in my computer and it may take some time in yours after that i'll uh import webdriver from selenium so from selenium import webdriver after that i'll make a class known as info constructor function and in that i'll initiate my driver see in my case the executable path of my chrome driver is this it is mostly the same in all the computers but if it is different in your computer then you have to search that where is your chrome driver or firefox whichever driver you are using and then you have to put the full path of it here right so after that so after that i'll write one more function which will be our task performing main function i'll name it get info and it will take a query query will be the text we want to search in the wikipedia right so here we will write we'll initiate the self dot query as query and then we'll initiate the driver as well using the driver.getget method what this line of code does is that self.driver initiates the driver which are using that is the chrome driver in our case and this dot get method takes the url which we want to search right so when i activate this line of code when the interpreter runs this line of code it will run this url right so let us test it let me make an instance of this class let's name it ss assist is equal info and then assist dot right i think it will work just fine let us just run it now now let us run this program and see what it returns us it is intended to open the wikipedia page but before running this i have to enter a query here so let me enter just any string because it takes a query if i don't enter it will throw me an error right let me run it now see it open the chrome browser as expected ca it has entered the wikipedia page isn't that amazing right so now what we have to do is that just me let me run it once again oh no now what we have to do that we have we want our computer to click on this search bar enter the text enter the query we want to search for and then press this enter button for this we'll use several more selenium methods and one such method is find element by xpath so let me do it for you see now uh what this xpath is let me show you let me first comment this out and run this program once again see now every text box and every link on a web page has their own id which is unique so we have to go to that id and copy that and paste uh it in our program so that it gets triggered right so once it gets triggered we'll able to control it using selenium right so we will go to inspect we'll have a right click and go to inspect we'll select on a click right then we'll copy its x path see here we can copy its xpath i'll copy it i'll uncomment this and i'll paste it here i'll paste it here now what this function does is that it triggers the search box on the wikipedia page and stores it in the search variable right now we'll use another method known as dot click search dot click now using the search we triggered the search box and this click method will make our program to click on that box right so after clicking we have to enter the text we want to search that is the query for that we'll use a function search dot send keys and here we'll add the query so it will take the query and enter it in the search box after that i'll trigger the enter the search button on the wikipedia page so once again i'll make a new trigger variable enter and i'll copy the code from here find element by xpath and here i'll enter the x path of the search button right i'll go here i'll trigger the search button see the id of the css element here is a button so i have to click here i have to copy the x path of the element that i have selected right go to the copy section copy the x path and i'll enter it here and then i'll press the click button just like as we did before so now if we run this program once again and search our query search for example if you search for neutron stars and now if we run the program it should it should search for it it should give me a page of neutron stars right see it worked as expected we have the neutron star related page in front of us and it's amazing now at this point of time where we have learned so much i have a small challenge for you what you have to do is let me just show you the passage first you have to copy the x path of the first passage here only the first passage and you have to try make your assistant to speak only the first two lines written in this passage so the workflow goes like this whenever you run this program the wikipedia page will open in front of you and it will read the first two lines of the passage of the first passage so i leave this challenge for you and you have to try making that possible right so now we will shift to uh indulging this selenium web automation to our main program so after this what can i do for you i want my uh assistant to listen to me right so i'll again write this code with microphone as source r dot threshold and r dot adjust the ambient noise and then again it will listen to us right so it will again store what what all we said in a text variable if i say that uh can you give me some information then it will check that whether the word information is there in the text or not and if it is there it will perform the task for me right so i'll check if information in text let me just make it text 2 so that it does not get mixed up we'll see if you find the word information in text 2 then it will ask me you need information related to which topic then again it will listen to me let me change the text name to infer right then i'll pass the infer variable to the assist.getinfo function and i'll remove it from here so now the workflow is like this that it'll ask me what can i do for you i'll say can you can you give me some information then it will check that whether the word information is there in the string or not which i'm saying if it is there then it will ask me you need information related to which topic then again it will listen to me and i will say that i need information related to related to neutron stars then it will take it and pass it to the get info function from the selenium web automation script that we just wrote and we'll pass it to that and it will open the wikipedia and search it for site so let us test it hello sir i'm your voice assistant how are you i am absolutely fine what about you i am also having a good day sir what can i do for you can you please give me some information you need information related to which topic neutron stars see it opened the wikipedia page for us as we expected it to do now we can make it a little more interactive by adding a line here right so it'll speak searching in wikipedia i'll add a variable here the variable will be um infer right let me try it once again this time i'll not say what about you so it will just say hello sir i'm your voice assistant how are you i'm good what can i do for you can you pass me some information you need information related to which topic neutron stars searching neutron stars in wikipedia see it worked as expected it searched the neutron star for us right so now we'll learn how to open youtube and search for youtube videos and audios right so let me show you the code for that so guys this is our code for the youtube automation script and i have pre-written it because it is quite similar to the wikipedia automation let us see what's happening here line by line first line is from selenium import web driver it will import the web driver class from the selenium then we make a class called music we have written an init that is a constructor function which initiates our driver that is a chrome driver in our case and this is the executable path for it then we have a play function which is the main uh main function main working function of our youtube automation script what it will do first of all it sets the self.query as the query we have entered here then it initiates the driver this code self.driver initiates the driver and the dot get method takes us to the url we have entered here right now one thing i want you to notice here that in the url i have written this piece of code and then i have written the query now what is this let me show you it on youtube whenever i search something on youtube for example i search for dynamite then on the search bar we have this thing in common all the time only the last word changes right for example i uh search for see in this case also the initial string is same but only the last word changed pasted it here and then i passed the last word that is our query then what i did i selected the first result that came after the search right for example if i inspect this then i took the x path of this i copied the x path from here and pasted it here right and then and then i used the click method to click on that link and the video will play right so let us test it first we'll add a query here let us play dynamite right if i run this program let us see what it returns us it went to the google it opened the [Music] youtube see the program worked as we expected it to work right it played the video and everything worked fine i hope you understood it now let us indulge this youtube script in our program so just after um what can i do for you line it will hear what we wanted to say we'll add another lf block else if if the word play and video in text 2 then it will ask me it will ask me which i want to play which video then again it'll here so i'll copy this code as it is i hope you understood right so it will be fair for me to copy the code it listen to me and in this case i'll case i'll make it a vid then it'll initialize the class there we'll initialize an instance of the music class and then it will run the function dot what it is it is is it play yeah it is and then it will take the query as they forgot to import the yt auto file right so now if we ask our uh voice assistant to play a video for us on youtube it will play right let us make it a little bit more interactive right so right let us now run the program and see what it does right but before running this program let me just comment out this part of code otherwise it will run first yeah everything looks fine let me just run the program now hello sir i'm your voice assistant how are you i'm absolutely fine what about you i am also having a good day sir what can i do for you can you please play a video for me you want me to play which video believer playing believer on youtube see it is working absolutely fine see everything is going absolutely fine let me just make a bit modification so that it look more clean right so everything which our assistant speaks will be will be printed also right so yeah it looks fine and i'll run it once again i'll search for something else in wikipedia hello sir i'm your voice assistant how are you i am very good what can i do for you can you please give me some information sure sir you need information related to which topic black holes searching black holes in wikipedia as you can see a program searched for a black hole in the vastness of this universe right till now we have added two very interesting features to our voice assistant one is searching for information on wikipedia and the other is playing videos on youtube isn't that amazing now we'll add another amazing feature to our voice assistant that is telling us the latest news for that i'll use an api that is an application programming interface i'll show you how to use it let me give you a brief introduction about what are apis apis are application programming interfaces they help us to communicate between two different programs in our case we will we will extract the news from a source known as news api.org it provides us a json file which has the latest news and we have to just extract the news from it now that was enough of talking let me show you the code for it first of all we will install the requests module pip install requests it has been successfully installed in my pc so now i will import it now i'll make a variable that will store the url from which i am going to retrieve my data let me call the variable as api api address equals see this is my url from which i am going to retrieve my data it is unique for every user to get your own url you have to just go to their official website that is news api.org click on get api key you have to sign up here add your information all of your information and then you will get an api key just like this right this is my api key i can't show you the full key otherwise it will get copied right after that you can read the official documentation it is quite informative and clear and it it will help you to get this url right this key here is my key which i i have stored it in a secret file so now what we have to do is here i'll make a variable json data guys it will use the request module request.getmethod and it will search for the url which we have just stored in the variable api address right and it will convert it to a json file now what is a json file it looks something like this we will get into this once we dive deep right here we have an article list right it is a list which has all the latest news we will access it to get the news we want it has plenty of news but we'll take only the first three headlines right otherwise it will be too long so now i'll make a function uh let it be def news here i'll run a loop for three times and i'll extract the data from the json file here as you can see in the json file we have a list with the name article and here we have all the news here we have a title a description for each news for different news we have different titles and descriptions i hope you all know how to access dictionaries and lists so i'm not getting deep into it i'll just access it and show you how it works right first of all let us make an empty list named ar it is an empty list and it will take the news the top three titles i'm taking only the titles not the descriptions in this case otherwise it will be too long right so first of all here i'll make a string then i'll append it in the list we have just created ar so the string goes as follows our voice assistant will say number one for the first news it will say number one then it will say the title of the news all our news is stored in the json data so we will access it for the first news we will pass the value of i it will it is zero in the first year then it will be one then it will be two so in that way we will access three news and we'll access only the title and then we'll append a full stop right you can also add the description according to your convenience but i am adding only the titles right and then i'll append it in a r last this function will return the list first of all we'll check uh whether the script even runs or not then we will include it in our main dot py so we will call the function news and as it throws a list we'll store it in a list and then we'll print the contents of the list just to look whether the news function returns something or not let me run it and check see as you can see it returned something in the list it's not clear because it's too long but it returns something and it is the news right so now we can include this in our main dot py so let us get back to it alif if there is news in our text then call the news function but first we have to include it right so we'll include it from news it's capital news import everything so if our voice assistant finds the word news in the string then it will print all the news for us and it will recite also right so we'll run a group loop here first of all we'll call the news function and store the contents returned by it in a list and then we will run a loop and then we'll make our assistant to speak whatever there is in the list and also to print it right so speak whatever there is in the list and also print it so let us check whether it runs or not i hope it runs finger crossed okay so unfortunately it throwed an error to us okay i got it what's wrong um see we didn't remove the print statement from here right now i think it will work again fingers crossed hello sir i'm your voice assistant how are you i'm absolutely fine what about you i am also having a good day sir what can i do for you can you please tell the latest news number one powerful earthquake jolts turkey and greece killing at least four cnn number two big tech paces stock drop along with exxon mobil fox business number 35 new albums you should listen to now ariana grande onattrick's point never and more pitchfork see it is working absolutely fine but there is some problem in you know the documentation which i've done here so i have to add a space also should be number one and then there should be a full a comma right and also here it should print first and then speak something is wrong right and also if we ask our program to read news for us then it should reply it should give us a pre-reply first so we should speak saucer now i will read news for you right let us run it once again hello sir i'm your voice assistant how are you i'm absolutely fine what can i do for you can you please tell me the latest news number one powerful earthquake jolts turkey and grease okay just printed it didn't speak short sir that line so let me make it peak also now let us run it once again hello sir i'm your voice assistant how are you i'm absolutely fine what can i do for you can you please read the latest news for me sure sir now i will read news for you number one powerful earthquake jolts turkey and greece killing at least four cnn number two big tech paces stock drop along with exxon mobil fox business number three five new albums you should listen to now ariana grande ohnatrix point never and more pitchfork see it is working phenomenally i am absolutely satisfied by the way it works now we have added three features to it isn't that amazing now we'll add one more we'll make a program to say a random and interesting fact for us so fortunately we have a module for that we don't need to use an api we'll use a module rand facts brand fact module is a very interesting and useful module in our case it does not come pre-installed so we have to install it first so i'll do it i'll open the terminal and write pip install trend facts it got installed in my computer right it was quite fast and i'll import it in my main dot py import rand facts right so i'll write another lf block if anyone says fact or facts in our main text then what our program will do it will get a random fact it will get a random fact from the module and store it in a variable named x and then our voice assistant will make it to print and also speak it for us right so print x it will speak i'll make it to speak in a very interactive manner right so i'll write did you know that then i'll add a comma and then i'll concatenate the fact i got from the module right so let us see whether it works or not hello sir i'm your voice assistant how are you i'm absolutely fine what can i do for you can you please tell me a random fact did you know that beer was illegal in iceland until march 1st 1989. now the date is celebrated every year in reykjavik as jordan or beer day did you see that it was another amazing feature right let me make it a little bit more interactive sure sir i think it will work just fine for me now we have added four features now i'll use another api to tell a joke right to make our assistant tell a joke so i will directly show you the code just a second see now this is the code using which we will extract jokes from an api this is a url of an api it is common for everyone and you can just copy it from my screen right let me explain the user code line by line even though it is absolutely same but still i'll explain first of all we imported the requests module then we stored the api address the address from which we are going to extract the jokes into a variable called url then we converted the url to a json file we first used the requests module to get the url and then converted the contents returned to us by the url into a json file let me show you first that what are the contents returned by the url right it will be more clear then just a second this is the exactly same um url which i mentioned here right this this one i entered this url on my google chrome and see it returned me a dictionary as it can be seen from the curly braces it returned me a dictionary and then we have characteristics like id type but we are interested in the setup and punch line setup is the first line of the joke and punchline is the main you know the funny part so we'll extract it in our program see here we created an empty list it's not empty we created a list with two empty strings the first string is for the setup as you can see we have two characteristics here in which we are interested the setup and the punch line right so the first element of the list stores the setup from the json file and the second element stores the punch line if you observe this piece then json data returns us a dictionary and this is just a common python syntax of accessing a dictionary right then we create a function joke and it returns the list we have created right the one interesting thing i would like to show you here is that the moment i refresh this page the joke changes right if you observe so this is why we are using this api because it gives a different joke every time it will be more interactive and interesting in that case right so now we'll indulge we'll include this in our main dot py right so from jokes import everything right then we'll add another alif block alif joke or jokes in text 2 and what you have to do is it will call the jokes function right let me just have a look joke it will call the joke function and since the joke function returned a list so we will store it in a list arr and since we know that the list has only two uh elements in it first is the setup and then is a punchline so we'll not run a loop for that we'll just try directly access it so we'll write first print the first element then print the second element see first we'll play first we'll print the setup line then we'll speak the setup line then it will print the punch line and then it will speak the punch line right so let us first run and see what happens hello sir i'm your voice assistant how are you i'm absolutely fine what can i do for you can you please tell me a joke what is a centipedes favorite beetle song i want to hold your hand hand hand hand as you can see it told me a joke right and it is working perfectly fine i have no issues with that just to make it a little bit more interactive let me add one more line so it will speak sir get ready for some chuckles right now let me run it once again hello sir i'm your voice assistant how are you i'm good what can i do for you tell me a joke sure sir get ready for some chuckles what's the difference between an african elephant and an indian elephant about 5 000 miles see it was amazing it is working absolutely as expected so i have no issues right now let us add one more feature to our voice assistant that is telling the weather forecast real-time weather forecast of a state and also the time right and according to the time it will wish us good morning good afternoon or good evening right so let us do it for that i'll again use an api that is open within map.org it is similar to the news api.org here you also you have to sign up and then you will get an api key so i'll not repeat the process i'll show you the website their official website and then i'll show you the code right this is the official website of open weather map api it says openweathermap.org so once you come here you can sign up or sign in here and they'll provide you the key and they also have a very interactive end nicely managed documentation so you can access it and can write your code right so let us make a new python file we'll name it weather and here we'll write all the code related to our weather forecast right so let us just dig into that this is the code that gives me the information about the current weather and we can check this by just printing what is written what these functions return to me this is the code that gives me the information about the current weather we can check it by just printing what these functions return to me the temp function returns me the temperature and the test function returns me the description of the weather see the temperature here was in kelvin so i subtracted 273 from it and i rounded the temperature to one decimal point so that's why i use the round function here right so i'll run it and see what it returns what it prints okay i think i made a spelling mistake it was supposed to be temp it's 21.1 and it's a lot of smoke right as you can see it's a lot of pollution in delhi so you must be thinking from where did i get this main and temp and weather and description so i would like to tell that i got it from the api which uh which i have used here right so i'll enter the api address on my google chrome browser and show you how the actual json file looks like so as you can see in my chrome browser that there are several characteristics on which we can can access here for example we have a key named as weather which has a list as of as its value which we used we used this weather and accessed its description right if you noticed it carefully we used the key weather and then we accessed the first element in the list so you can access different things using an api one more thing which i'd like to show you is that if you notice carefully in this url i have used this keyword delhi here so you can change it according to your state you will find every small detail in their documentation so go and have a look there right so i'll use it in my main dot py and i'll use it to make my voice assistant speak for me you know the information i am your voices assistant and i'll remove this right and i'll here write that temperature in new delhi is i'll concatenate the first i'll type cast the temp function i have to import it right from weather import everything temperature in new delhi is and it will return me the temperature and here i'll write and i'll with right so it should work fine let me just run and test it hello sir i'm your voice assistant dot temperature in new delhi is 21.1 no something is not correct just a second okay i used an extra bracket here for no reason i think i should shift this sentence to another line so that it gives a pause to it right i think now it should work fine hello sir i'm your voice assistant temperature in new delhi is 21.1 and with smoke first of all uh the temperature module which we have created returns uh you know it prints the temperature so we have to remove it right here and second thing i made a spelling mistake in the word temperature so i have to correct it and now it looks perfect and now just run and test it once again hello sir i'm your voice assistant temperature in new delhi is 21.1 and with smoke we should write a degree celsius right right so it should work fine now hello sir i'm your voice assistant temperature in new delhi is 21.1 degrees celsius and with smoke yeah it's working perfectly fine and after that it should speak what can i do for you right uh so i want my assistant to speak today's day also and also the time right so let me do it i'll use a date time audio so let me import date time yeah and i'll make a variable no not here i'll make a variable date today date is equal to datetime dot date time dot now and here i'll make my voice assistant to say today is today dot shift time and here we'll add a specifier i'll explain don't worry what this method means so here i've used so here i've made my voice assistant to speak today is this date and this month and this year so i did it using uh the strip time method of date time module yes what this method does is that it converts the date into readable strings like if it is 28 6 then it will say 28th of june right you can read the documentation of datetime module from any documentation website right and this percentile d and this percentile b are the specifiers for date month and year for example if i write percentile small d then it means according to the documentation let me find it out there it means day of the month 1 to 31st right if i write here percentile b then it means percentile capital b it means month name full month name like it will say 21st of december right so this is the use of this drift time method of the datetime audio now let us see what it is the final what is the final outcome of our voice assistant hello sir i'm your voice assistant okay through an error i think i made a typo somewhere yeah see i would like to show you the full string first here um just a second see today is today is and uh this percentile d will show the date percentile b will show the month and percentile i is for the r for the minute and for am or pm right so you saw and la the so you saw the whole string and now we'll run it let's see what it ends up being hello sir i'm your voice assistant today is 31 of october and it's currently 12 43 am temperature in new delhi is 21.1 degrees celsius and with smoke what can i do for you see it's working perfectly fine right see i've made another function here known as wish me what it does is that it takes the datetime.datetime.now that is the current time and takes the r of the time that what is the r and if it is between 0 to 12 according to a 24 hour clock then it will wish me it will give me a morning if it is between 12 to 6 that is if if it is between 12 to 4 pm then it will give me an afternoon or in any other case it will give me an evening even in the night it will give me an evening which works fine for me so i will include it in my program so it will be like hello sir good morning or hello sir good evening right so let me just include it i think it should work fine it should wish me an evening sir evening i'm your voice assistant okay okay something is not correct now i think i should run and it should return me an evening hello sir good evening i'm your voice assistant today is 31 of october and it's currently 12 47 a.m temperature in new delhi is 21.1 degrees celsius and with smoke what can i do for you see it worked perfectly fine so now we have worked a lot on our project and i would like to leave the further on you you can improvise it in a way you like right you can add new features to it you can modify it you can add new versions to it you can add new features you can do whatever you want with it i've just given you a basic skeleton and here it goes right so just before leaving let us have a final look at what all it can do what all our voice assistant can do right so it tells us the real time weather forecast it wish us morning night or evening morning afternoon or evening right it uh it can play video for us right you can also improvise it by uh if someone says that play music to me then it redirects it to spotify website and there you use the selenium to play that music right it it will be a nice little challenge for you and it tells us the latest news it tells us a fact interesting fact it can tell us jokes right you can also add a movie review system to this like whenever someone asks for a review then it goes to google searches for that movie and adds a string there like like if i ask for new mutants then it should write new mutants movie review on the google platform and it should search for the movie and it should recite the ratings right so this is another challenge for you so yeah i would like to conclude here this was all from my side you can improvise this program you can take it further you can release new versions of it you can do whatever you want we have just created a skeleton it is the starting of this ai program so thank you very much it is rishikesh this side and i would like to take a leave happy coding
Info
Channel: EduYear
Views: 30,048
Rating: 4.9433961 out of 5
Keywords: create a voice Assistant, create a google Assistant, voice Assistant like siri, voice Assistant like google, own voice Assistant, how to create a voice assistant, easy way to create a voice assistant, voice assistant in python, python voice assistant, eduyear
Id: fjPuAKR_h4M
Channel Id: undefined
Length: 81min 36sec (4896 seconds)
Published: Thu Nov 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.