Don't Buy Alexa! Build Your Own. Create a Virtual Assistant with Python | Python Project | Jarvis AI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
don't buy alexa rather build your own with just simple 20 lengths of python this is super simple super crazy virtual assistant just for you so let's get started before getting into the detail please please like this video and subscribe to this channel otherwise grandma will break up with alexa and create a romantic relation with siri to start this fun project you need to start with a python code editor and i will be using pie chart and once this pycharm is ready just click on this new project and give it any fancy name in this case if you are feeling very romantic you can name it like romantic alexa or something like this and once this pycharm is getting ready think about what does alexa do let's say do just two simple thing the first thing she does is to listen what you are saying for example alexa what's the time or what's the weather or play some music that means you are giving a voice command to alexa and alex has to listen to it and the second part alexa does is to speak that means like okay i found this here i found this i'm doing that part that means she listen and then also she speaks and if you understand these two core part this project will be super easy super fun for you and the first thing we will do just press ctrl a and then back space to make it a clean slate and we will definitely use three simple python packages so the first python package would be something called speech recognition you can search python speech recognition and go to the first link you get and then click on this tiny icon come back to your pycharm click on terminal and then you have to do control b and press enter so speech recognition package would be installed and after that you need the second package is called python text to a speech version three and you need to click on this guy again click this to copy whatever this command come back to your pycharm terminal press enter and this would be installed as well and to make it working you will need one last package called python pi or do and if you go this link you will get same command come back to python and then ctrl b and then press enter and in some computer this pi order you might give some error in that case you need to lower down the python version to 3.6 or earlier and if you face any trouble to install pi audio in your computer please comment below and grandma will definitely help you out so once you have these three basic package installed our first task is to talk to alexa in a very romantic way and to talk she has to understand you and that's the purpose we will import the speech recognition package and we'll give it a tiny name and we'll call it like sr and once the sr is available all you need to do is to create a listener and this listener would be sr dot recognizer that means you are creating a recognizer who would be able to recognize your voice who will understand the romantic desire inside your heart and after that you need to put something inside a try block because sometime microphone might not work or give you some other trouble and once you create a try block you need to create another accept block and if you don't want to do anything for the accept just you need to write pass that means python will ignore or don't do anything when the exception happens but inside the try block we will do use the microphone so that's why we will type with sr dot microphone and we'll give another small name is called a source this is the source of our audio or source of our command and here we will declare a variable and that would be the voice and we will write listener to listen to this source so i will explain this line little more all you are trying to do using your microphone as a source and then calling this speech recognizer to listen to this search and once you have this source you can use a lot of functions that this speech recognization have to convert voice to text and we will use one of them and we'll declare a variable name command and the value of this command would be listener dot recognize by using the google api and you will pass the voice the audio to google and google will give you the text and to make sure this is working all you need to do is to print that command and then see whether this is right now working for you or not so once you have up to this part uh we will just test it by clicking on this dude so i click on the run button and i am not sure that which is the time i can speak to alexa so for that purpose all i can do here is write another command is called like a listening and this is just printing out giving me some indication that alexa is ready to listen whatever i have to say so click on this run button and you see listening so you can just speak alexa i miss you and you'll see and listening and justice speak alexa i miss you and you can do like a similar way multiple times so once i click on this run alexa button you single you see that alexa are you single is on the screen that means alexa can listen to you because you can convert to this part and you can do much more fun thing using this so you can uh detect whether alexa is mentioned there or not and you can just do a simple thing for example here you can type ah command and we will make this command to lower case so you can just type this lower and then you can check if alexa in command if alexa is mentioned in the command in that case you will print otherwise you will not print so let's do that that whether we can detect that alexa is mentioned uh on the command or not so i will run this uh run button again so click on this alexa are you there you see alexa was there that's why you see alexa are you there as an output and if i don't say alexa says something else let's see whether this is printed or not siri are you sleeping or are you crying you see i don't see as an output that means our alexa only listen to whenever i called her how romantic is that so let's get into the next step let's alexa talk to me so for that purpose we will use the uh second package that we installed and that is import python text to speech version 3 and to do so we can just create an engine that will speak to you you can say python text to its pitch and initialize this engine and then maybe you can do something here or you can create a function later too but we will do here say engine and then you can say like ask it to say something this uh command that you have mentioned and then you can say like an engine run and wait something like this or even at the beginning you don't have to do it here you can do here as well like here uh say something like i am your alexa maybe i can say like an enzyme say something else uh what can i do for you something like this and and that will speak to you and then you start talking when alexa says something and here we will as usual have the print commands this way so now i am running this i am your alexa what can i do for you hey alexa why you have a male voice you should have a female voice so now what we can do we can convert the tone of alexa to a female voice very very simple way as well to give alexa a female voice you just need two lines of code this is super simple you need to declare a variable called voices to get all the different voices this python text to speech can provide so you just on the right side write engine dot get property and the name of the property you want to get all the voices and you are setting it to this variable voices and after that you will tell the engine hey engine now set a property and you'd be setting the voice and it would be all the voices you get out of there the second one which is the index position of one and then we'll set the id of it that's it and now we will run this code and then see how does it speaks to us i am your alexa what can i do for you hey alexa i am very happy to listen to your romantic voice and you see this is this alexa i am very happy to listen to your very romantic voice so we got to alexa speak in the female voice which is super fun and we can write it this way or we can make a simple function here just declare a function in python is like diff this is kind of like short version of define and we can tell it as like a talk and inside this stock we can take one or two parameter to execute here so we say like whatever you want to say maybe some text and then inside we will make it dynamic like text so this way we would be calling this stock function and every time we are calling this stock function it will say whatever the parameter we are passing to this function this is super simple and here from inside other than like a command printing it out you can just say like talk whatever the comment it is so whatever you are saying alexa will be repeating that so let's click on this run button alexa i love you alexa i love you and that means like alexa is repeating whatever i am speaking to her but that's not the fun part of building an alexa rather we want to do much more using this alexa right for example play some youtube song or maybe what's the time alexa or alexa uh do can you tell me about this person and all this cool stuff so let's get building something like this and in that purpose you can also convert this as a function as well so all we need to do tab it that means it gets indented and we defined a function called uh take command or something like this and once you have that ah this should be inside this function and from this function you can return anything so from here for example if we want we can return the command that you are saying and here we will just maybe print the command as well so that we can see it in the uh output below so this is would be our uh take command from us and then we want to do some work using alexa so for that purpose we will declare another function maybe this would be like a run alexa something like this and inside this function we the first thing we will do take a command from the user that means it be taking the command from me and that would be the command it should be take command function that means we are getting the command by using this function so we are calling this function and getting this command this is super simple and after that we'll do some processing by using it for example if the command has like play that means play a song we will be playing a song here so we'll check if play that means if play in command then we will do that like a printing or maybe playing some song something like this or you can say like or alexa can talk as well we can say like okay playing some song you can say like a playing some song she could be telling to you and you need to clean little bit because whenever uh you are giving the command alex alexa is there but you don't want to search music with the name of alexa it could be ariana grande song or something like this and you can remove that from the command as well this is super simple you can write command equals to a command and then from there dot replace that means you want to replace the word alexa and instead of alexa you want to just put an m testing that means alexa will be removed from the string and once you get there for example here in the play so let's just print it here print the command right now and here all we need to do is to call this function just for right now for one time and then see how does it goes so we will have this opening and then we will click this stud alexa how are you doing today you see that alexa is removed from this text and you can do the same thing for example uh you are giving a comment like alexa play some music so i click on this button alexa play ariana grande playing so that means when you are searching on youtube or playing a music on the youtube you don't need this word play as well so you can remove uh this play keyword from the command very simple way so you can give this name like as a command or you can give it like a song equals to command dot replace you would be replacing the play with this empty string that means this would be the song and you can hear just playing and then you can add the song here say playing aryana gandhi or something like this alexa could open up the youtube and then play that song for you and that would be super fun for you my friend uh so we run it again and let's see whether we are getting the song here and we will print the song here so i will click on this run alexa play ariana grande playing ariana grande and you see the last print is only the ariana grande so what happened in between just pay a little bit attention here you are calling this run alexa it goes here it comes this this line it cause this take command come to this place using your microphone start listening and once you say the word alexa you are removing alexa from your command and once you have this command without alexa it comes as a return here and once you have this it detects the play and you remove the play from your command and only remaining the final ariana grande and if you have that the last very piece is to install a simple python package and that package my friend is called pi what kit so you can search here uh python pi what kit and this will give you a simple line to install it so click on this button come back here ctrl b press enter and this will take few seconds to install pi what kit and this will give you a powerful package to search youtube or do some fun using it now all we will need to do is to import pi what kit and then all you need to do is to come back instead of printing the song you will write by what kit dot play on youtube that means play on yt means youtube and let's see the magic and now if you click on this run button and give this comment to play any song you can have fun with alexa alexa play ariana grande playing ariana grande you might think i'm crazy so ariana grande is crazy that's what she thinks and you are crazy too because you can give a simple command with your voice and play youtube song and it doesn't have to be ariana grande song it could be any other song as well for example let's do have some fun alexa play taylor swift playing taylor swift so you see with just a voice command you are playing youtube video or any song that you want to listen and this is super easy by using alexa so you see you have the fun and the power just creating your own alexa and we will have much more fun so please get going another fun thing with alexa is to ask her the time as if you cannot check your phone or your watch that what's the time rather you have to talk with alexa and that is super easy you don't have to do much all you have to do is to here detect or check whether somebody mentioned what's the time or tell me the time can you share the time or something like this so you can write another like elsie for something like this if time is mentioned in the command in that case you want to get the time and tell the time to the person who is asking for it and to get the time is super simple you need to use a python building package so here would be date time and by using the date time you can get the time here and that would be the variable time or any any variable you want to give and from the date time you will call the date time and now that means the current moment and after that you can get the sting format of the time that means you can format the time how we want to set the get the time and it would be percentage h for the hour and then percentage m minute and if you care about the second you can get like a percentage s as well but here we just want to listen the minute and second and after that you can say uh talk uh and then the time or uh it could be much more uh that current time is and then you add the time that's it so i will play this and then see or you can actually uh print the time to see in the print as the output as well so i will click on this run button alexa tell me the time current time is 21.35 and if you want to get just uh like am or pm you can do other stuff for example i this is uh the the 12 hour format of the time and you can do like a percentage p to get the am or pm something like this as well uh so here i am clicking on the run button alexa tell me the time current time is 9 35 pm so you see this is super simple just with two lines of code you can get the time by using alexa and we'll do some other cool stuff for example you need to search a lot of fun things and the internet maybe you want to learn about people and search on wikipedia and you can do this with just few lines of python as well and for that purpose we will use a python package as well so search for uh something called python we key pdr and this is a simple python wikipedia projects that you can call uh and then uh get results from wikipedia so i copy this as usual come back to my termine null and then in the terminal control b press enter the wikipedia would be installed and once you install something the most important part is to import that thing so we'll do the wikipedia and if you mention the word wikipedia or wiki or info get info or anything something like that you could be able to call the wikipedia and get the result and make alexa to say that thing to you so we will do for example uh else if the lc would be like for example wikipedia or something like that and then in the command so for example wikipedia by maybe search for or tell me about uh taylor swift or ariana grande or miley cyrus or something like that or you can make this comment uh who the heck is uh aryana gandhi or who the heck is something like this you can make this if you want for example who the heck is someone or something like this and you get the command maybe you saw like a person and equals to from the query you will have who the heck is taylor swift but if you go to wikipedia then you will only search for the name of the person not you will search for like who the heck is taylor swift you search for taylor swift so we need to just uh replace it so from the command we will replace as usual and we will replace a who the heck is by using an empty string so this would be clean and then you can go to get the information maybe in for something like this call the wikipedia and it has a method called summary you can pass what the thing you want to search here we want to search the person and how many sentences you want to get as a result it could be like a five lines four lines three lines one line or two line in our case we'll just get one line and we want alexa to talk back the information she found in the wikipedia so this is super easy all we need to alexa who the heck is that person and alexa will go to the wikipedia find that result and tell us about that person and also we would be able to see that here as well so let's do that fun part alexa who the heck is donald trump donald john trump born june 14 1946 is the 45th and current president of the united states let's do a few more other things alexa who the heck is ariana grande ariana grande butera born june 26 1990. oh i didn't know her last name is butera okay that's interesting so let's do one more thing alexa who the heck is justin bieber justin drew beaver born march 1st 19th you see you can search a lot of things and it doesn't have to be the person it could be some other thing as well say alexa find something maybe global warming or something like this or maybe some kind of iphone 12 or iphone 15 or any other person you can search by using the word uh who the heck is it would go to the wikipedia and find information about this person and so this is super simple but super cool and you can do a lot of endless thing by using alexa and this voice command system your options with alexa is endless you can do a lot of fun things and it could be some romantic thing as well so let's do few more thing so for example we are doing this uh extra stuff say for example if you want to ask alexa to go for a date say let's go for a date or do you want to have a date or something like this in your comment uh alexa could say something interesting or funny or it could be something deceiving as well say for example if you said alexa let's go for a date and she might talk back to you i have a headache or sorry and that's the common excuse i have an a headache something like this and it could be some other thing as well else if if you ask for like are you single or do you love me and say for example are you single something like this uh in common and she could talk back like i am in a relationship with wi-fi something like this and so many other cool things like are you a single or are you something something something alexa can do all this part as well and another cool thing is if you are bored you can ask alexa to tell you a jokes and to do this you need a simple python package and just search for it and this name is a python pie jokes and if you install this pie jokes by using this command you can get endless supply of jokes as well so i'm going to the terminal control b press enter and i would be installing the pi jokes and when the pyjax is installed the first thing you will do import the pie jokes so import by jokes and here if you ask like hey alexa tell me a jokes or do you have a jokes or share me a joke so anything is mentioned in the joke you can say like if joke is in common in that case you can make alexa go to the pie jokes and get a joke and it will get a joke and talk back to you so let's hear a joke from alexa alexa tell me a joke dotnet was named.net so that it wouldn't show up in a unix directory listing and that's a romantic joke or it could be like a programming jokes as well and if you want you can see the jokes in the output as well just get the return from this and print it there and you can ask like a date on romantic thing now look at the code you have so many different options here but instead of these options sometimes there could be a command that you are giving to alexa but alexa didn't understood it in that case alexa could just say hey say it again or repeat it something like this so in your if else you could have an else and what this else alexa will tell you ah please say the command again something like this and in that way you will understand that alexa want to listen if she didn't understood whatever you're trying to say and another problem we have that this code is executing only once but we don't want alexa to die after single command we need to power on her every single time instead of you can just do here say like a while and then true this means you are running a loop and this loop would be executed every single time and doing the command again and again again and again and if alexa doesn't hear anything from you in that case it will go back and ask you to say it again so let's run it for the alexa one final time and have fun with it alexa are you single i am in a relationship with wi-fi alexa let's go for a romantic date with you sorry i have a headache alexa what is the time right now current time is 9 53 pm alexa please see you again playing see you again so this is where my friend you have a your own alexa with few lines of code and all you have to do is to learn how to use python and use all these python packages and you have endless opportunity to extend your alexa the way you want to build it and you never know someday if you make alexa in the right way you might become a chillier like mr jeff bezos so that's all from this video if you watch till this point definitely definitely like this button and punch the subscribe button and grandma will say a romantic heart to you and definitely definitely don't forget our awesome mobile app called programming hero so go to the app store or the play store download programming hero give us a good rating and we'll be making fun fun content for you and you would become a python genius very soon that's all from now your grandma and i will see you in the next video you
Info
Channel: Programming Hero
Views: 1,179,878
Rating: 4.8988304 out of 5
Keywords: Programming, python, web development, learn programming, programming tutorial, coding, software, python tutorial, python projects, python for beginners, learn python, python tips, python tricks
Id: AWvsXxDtEkU
Channel Id: undefined
Length: 31min 27sec (1887 seconds)
Published: Mon Dec 07 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.