In this tutorial, we're going to show you how to create a program that can understand your voice and give you information about your schedule. We'll start by saying "UTC equals pi t z dot e UTC" which will give us our current time zone. Then, we'll say "date equals date dot as time zone UTC" to get the minimum date with a specific time zone.
Next, we'll use the same logic to get the end date with a specific time zone. We'll then use this information to turn it into some UTC formatted date string which is what we need to pass into our service. We'll change the time parameter in our function to be "date" because that's the one with the minimum time, and we'll add another parameter called "time" which will be equal to "&date". This should actually work if we pass it a day.
Let's test this out by getting a date from strings and selecting text equals get audio. Then, what we're going to do is just pass this to get event since we're going to say get underscore events and we're going to do get underscore date text and then pass it "text" or not. We also need to get service so we'll say service equals get our authenticate to Google.
Now that we have that, let's run this and see if this works properly. I'll say like what do I have on Wednesday or something and see if I have any events. What do I have on Wednesday? And we get an error. Let me have a quick look and I'll be right back okay. So, I just remembered actually forgot one thing that I need to add here. For when I'm actually passing these dates, I need to add something to them that is this weird thing it's is a format which is formats them properly.
I don't really know exactly how all this formatting is supposed to work. It's kind of weird because you know what times you have different time zones and all that. But now if we run this, we should hopefully get something that actually works.
So, I'm just signing in to my other Google account now and I'm gonna test this out and show you how this works. What I'm gonna do is run the program. Do I have anything on Thursday? And what you can see is it actually pops up my entire schedule for Thursday here which is correct. It means I have a lecture, a lab, a tutorial, and a DGD.
Now for those of you unaware, what this means I'm in school right now so these are like my course codes and times that they Pinet um what we're gonna do in the next video is actually make this speak it out to us rather than just showing us what we have. But I mean I think this is pretty cool so far that we can actually just speak into the computer you know ask it like what do I have on a specific day and it can actually tell us that information for us.
I know a quick thing here that I want to do is just inside of this function I noticed that sometimes we get an error if you know there's no date that it finds so what we want to do is just do a quick if statement here before this last return that says if month equals equals negative 1 which means essentially we haven't figured out a month then what we need to do is or if month equals equals negative 1 or day equals equals negative 1 we're just gonna return none.
So, we'll return none. I don't know why this is lagging all right so sub-line text was lagging there so I'd restart but anyways we're just gonna return none here which essentially is saying you know if we've gone through this and we didn't find a date so we didn't figure out a month we didn't find a day return non.
"WEBVTTKind: captionsLanguage: enhey guys and welcome back so what we're gonna be doing in this video is just changing a few things to kind of optimize this code to make a little bit better because I've recently found out because of you guys continually commenting this and I apologize I didn't fix this sooner is that I should really be using a different module for doing the speaking for the computer so rather than using Google Texas Beach which is kind of slow and requires the Internet there's actually a module called pi TTS x3 that works really well in that I've actually tested down we're gonna switch to right now it's not gonna take us very long before I continue though I just want to fix a few errors that you guys pointed out to me in the last video so the first one is I need to add an ND to this day extensions list because you know if we have like second we need to add that which I forgot about I also need to add the month October because apparently I forgot to that so let's add that in here get those errors fixed up and now what I want to do is actually change to PI T TS X 3 and for doing the speaking from the computer so to do that we're gonna start by installing it so pip install PI T TS X 3 which I believe this means like version 3 of Pi text-to-speech we'll hit enter install that I already have it installed now what I'm gonna do is actually on import our gets get rid of these imports for play sound in Google Texas speech and instead import PI TTS X 3 so that means inside of speak now this function we need to change this and you're gonna see how much easier this is to actually speak something out it's not necessarily less code it's just like way simpler the process we're in create a variable called engine and that's gonna be equal to PI TTS x 3.9 it this is just starting pi TTS getting it ready to go and you need to do this every time you're about to speak something new is which is what I found out next we're gonna do is engine dot say and here we're just gonna say the text and let me make sure that that's the correct one but I think it is and then the last thing we need to do here is do engine dot and I believe this one is run and wait like that so this will run and wait for this text to finish being spoke until we move on to the next part of our program so this is just way easier and that's we're gonna use we don't need to save anything too file now so I can actually get rid of this voice mp3 file okay wonderful so now that we've done that let's actually just show you how this works by just speaking you know like hello Tim how are you and let's see what this sounds like how are you there you go so pretty fast but that's fine we can deal with that and I think there's probably a way to slow it down but I mean you guys can look up the documentation if you want to do that okay so now that we've done that that what we're actually gonna do is modify this get of Ben's function so that we can actually pass it a date one that we're gonna get from this get date function that we've been working on so hard for the past two videos and it will give us the list of events that occur on that date now that's gonna be great because what we can do then is we can you know speak to the computer we can figure out what day we're talking about and if we're asking about you know do we have an event on this day or are we busy do we have plans we can call this get events function give it the date we're talking about and then it'll figure out what we have on that day now it's a little bit tricky but what I'm gonna do is just start by replacing n with date up there we're gonna get rid of a few things like these first three lines and we're also going to get rid of this Max result parameter inside of events results service whatever this all is now we're gonna change this quite a bit the first thing that we need to do is you need to determine how this date is coming in and put it in the correct format so that we can actually pass it to this Google Calendar API like I guess query call whatever it is to get I mean like the correct format so essentially need to send in a date that's in like some UTC time format what we've done here is just gotten a date in terms of like you know the day the year in the month so we need to turn this into like a UTC timestamp which is kind of weird but I'm gonna show you how to do that now I'm gonna be quite honest I don't know like exactly what a lot of these lines do I was just messing around and I mean I know what the end result is but I don't work with the day time module very much so I can't really explain all of this but what we're gonna do is start by actually combining this date time we're gonna do date equals date time dot date time dot combined and then we're gonna do the day and date time is this just this isn't day sorry this is date yes or a new date date time dot min or was it sorry dot date time dot min dot time now this reminds me actually to change this parameter today and change this today that's what I have my other codes will stay consistent now I'm actually gonna copy this for date and I'm gonna make a new variable called end underscore date and what I'm gonna do here is this ever doing min time I'm gonna do max time so essentially what I need to do is I need to get two times I need to get our two date time objects one that has the beginning of the day so let's say we're talking about Tuesday I need Tuesday at like I guess what is it midnight like Tuesday at as soon as it hits Tuesday I need that time so the minimum time on Tuesday and then I need the maximum time on Tuesday so like 11:59 p.m. so what I can do is search through my the events in my Google Calendar so I only find the ones that occur in between those two times so that's why I'm doing this end date and this date alright so now that I have that this reminds me I need to actually go up here and import one more module this is built into Python but it's called PI T Zed I believe is the name of it and this is gonna allow us to actually get our current UTC time zone so what i'm gonna do is i'm going to say UTC equals pi t z dot e UTC which i believe just gives our current UTC time zone and that's gonna be different depending on wherever you live and then what I'm gonna do is say date equals date dot as time zone UTC and I'm gonna do the same thing for end underscore dates equals and underscore date dot as time zone like that and then UTC now what this is gonna do is just turn this into some UTC formatted date string which we actually need to pass into here and now what we're gonna do is we're gonna change this time in parameter to be date because that's the one with the minimum time we're gonna add one more parameter which is time which is going to be equal to and underscore a date like that okay so now that we have that this should actually work if we pass it a day and we pass it the service to give us all of the events that we have on that specific day so we're gonna test this out to start and yeah let's let's test it out so we're gonna get a date from strings we're going to select text equals get underscore audio and then what we're gonna do is just pass this to get event since we're going to say get underscore events and we're gonna do get underscore date text and then pass it text or not texter what am I saying we need to pass it service so we also need to get service so we'll say service equals get our authenticate to Google like that and it will pass it this service okay wonderful so now that we have that let's run this and see if this works properly so I'll say like what do I have on Wednesday or something and see if I have any events then what do I have on Wednesday and we get an error what is this let's see here we get an issue with this let me have a quick look and I'll be right back okay so I just remembered actually forgot one thing that I need to add here so for when I'm actually passing these dates I need to actually add something to them that is this weird thing it's is a format we did in the last video but I just forgot about it so is a format which is formats them properly I don't really know exactly how all this formatting is supposed to work it's kind of weird because you know what times you have different time zones and all that but now if we run this we should hopefully get something that actually works all right so I'm just signing in to my other Google account now and I'm gonna test this out and show you how this works so what I'm gonna do is run the program do I have anything on Thursday and what you can see is it actually pops up my entire schedule for Thursday here which is correct it means I have a lecture a lab a tutorial and a DGD now for those of you unaware what this means I'm in school right now so these are like my course codes and times that they Pinet um what we're gonna do in the next video is actually make this speak it out to us rather than just showing us what we have but I mean I think this is pretty cool so far that we can actually just speak into the computer you know ask it like what do I have on a specific day and it can actually attach that information for us I know a quick thing here that I want to do is just inside of this function I noticed that sometimes we get an error if you know there's no date that it finds so what we want to do is just do a quick if statement here before this last return that says if month equals equals negative 1 which means essentially we haven't figured out a month then what we need to do is or if month equals equals negative 1 or day equals equals negative 1 we're just gonna return none so we'll return none I don't know why this is lagging all right so sub-line text was lagging there so I'd restart but anyways we're just gonna return none here which essentially is saying you know if we've gone through this and we didn't find a date so we didn't find a month we didn't find a day return non grouted than running this because this code will actually return an error to us as it tries to create a date with a negative month right because month starts at negative 1 so noise that has been it for this video in terms of actually getting you know the events that we have on a specific day simply by speaking to the computer the next one we're gonna modify this function so it actually speaks back to us and tells us you know you have an event at 3 p.m. or whatever it is and yeah so if you guys have any ideas as always leave them in the comments down below and I will see you guys in the next videohey guys and welcome back so what we're gonna be doing in this video is just changing a few things to kind of optimize this code to make a little bit better because I've recently found out because of you guys continually commenting this and I apologize I didn't fix this sooner is that I should really be using a different module for doing the speaking for the computer so rather than using Google Texas Beach which is kind of slow and requires the Internet there's actually a module called pi TTS x3 that works really well in that I've actually tested down we're gonna switch to right now it's not gonna take us very long before I continue though I just want to fix a few errors that you guys pointed out to me in the last video so the first one is I need to add an ND to this day extensions list because you know if we have like second we need to add that which I forgot about I also need to add the month October because apparently I forgot to that so let's add that in here get those errors fixed up and now what I want to do is actually change to PI T TS X 3 and for doing the speaking from the computer so to do that we're gonna start by installing it so pip install PI T TS X 3 which I believe this means like version 3 of Pi text-to-speech we'll hit enter install that I already have it installed now what I'm gonna do is actually on import our gets get rid of these imports for play sound in Google Texas speech and instead import PI TTS X 3 so that means inside of speak now this function we need to change this and you're gonna see how much easier this is to actually speak something out it's not necessarily less code it's just like way simpler the process we're in create a variable called engine and that's gonna be equal to PI TTS x 3.9 it this is just starting pi TTS getting it ready to go and you need to do this every time you're about to speak something new is which is what I found out next we're gonna do is engine dot say and here we're just gonna say the text and let me make sure that that's the correct one but I think it is and then the last thing we need to do here is do engine dot and I believe this one is run and wait like that so this will run and wait for this text to finish being spoke until we move on to the next part of our program so this is just way easier and that's we're gonna use we don't need to save anything too file now so I can actually get rid of this voice mp3 file okay wonderful so now that we've done that let's actually just show you how this works by just speaking you know like hello Tim how are you and let's see what this sounds like how are you there you go so pretty fast but that's fine we can deal with that and I think there's probably a way to slow it down but I mean you guys can look up the documentation if you want to do that okay so now that we've done that that what we're actually gonna do is modify this get of Ben's function so that we can actually pass it a date one that we're gonna get from this get date function that we've been working on so hard for the past two videos and it will give us the list of events that occur on that date now that's gonna be great because what we can do then is we can you know speak to the computer we can figure out what day we're talking about and if we're asking about you know do we have an event on this day or are we busy do we have plans we can call this get events function give it the date we're talking about and then it'll figure out what we have on that day now it's a little bit tricky but what I'm gonna do is just start by replacing n with date up there we're gonna get rid of a few things like these first three lines and we're also going to get rid of this Max result parameter inside of events results service whatever this all is now we're gonna change this quite a bit the first thing that we need to do is you need to determine how this date is coming in and put it in the correct format so that we can actually pass it to this Google Calendar API like I guess query call whatever it is to get I mean like the correct format so essentially need to send in a date that's in like some UTC time format what we've done here is just gotten a date in terms of like you know the day the year in the month so we need to turn this into like a UTC timestamp which is kind of weird but I'm gonna show you how to do that now I'm gonna be quite honest I don't know like exactly what a lot of these lines do I was just messing around and I mean I know what the end result is but I don't work with the day time module very much so I can't really explain all of this but what we're gonna do is start by actually combining this date time we're gonna do date equals date time dot date time dot combined and then we're gonna do the day and date time is this just this isn't day sorry this is date yes or a new date date time dot min or was it sorry dot date time dot min dot time now this reminds me actually to change this parameter today and change this today that's what I have my other codes will stay consistent now I'm actually gonna copy this for date and I'm gonna make a new variable called end underscore date and what I'm gonna do here is this ever doing min time I'm gonna do max time so essentially what I need to do is I need to get two times I need to get our two date time objects one that has the beginning of the day so let's say we're talking about Tuesday I need Tuesday at like I guess what is it midnight like Tuesday at as soon as it hits Tuesday I need that time so the minimum time on Tuesday and then I need the maximum time on Tuesday so like 11:59 p.m. so what I can do is search through my the events in my Google Calendar so I only find the ones that occur in between those two times so that's why I'm doing this end date and this date alright so now that I have that this reminds me I need to actually go up here and import one more module this is built into Python but it's called PI T Zed I believe is the name of it and this is gonna allow us to actually get our current UTC time zone so what i'm gonna do is i'm going to say UTC equals pi t z dot e UTC which i believe just gives our current UTC time zone and that's gonna be different depending on wherever you live and then what I'm gonna do is say date equals date dot as time zone UTC and I'm gonna do the same thing for end underscore dates equals and underscore date dot as time zone like that and then UTC now what this is gonna do is just turn this into some UTC formatted date string which we actually need to pass into here and now what we're gonna do is we're gonna change this time in parameter to be date because that's the one with the minimum time we're gonna add one more parameter which is time which is going to be equal to and underscore a date like that okay so now that we have that this should actually work if we pass it a day and we pass it the service to give us all of the events that we have on that specific day so we're gonna test this out to start and yeah let's let's test it out so we're gonna get a date from strings we're going to select text equals get underscore audio and then what we're gonna do is just pass this to get event since we're going to say get underscore events and we're gonna do get underscore date text and then pass it text or not texter what am I saying we need to pass it service so we also need to get service so we'll say service equals get our authenticate to Google like that and it will pass it this service okay wonderful so now that we have that let's run this and see if this works properly so I'll say like what do I have on Wednesday or something and see if I have any events then what do I have on Wednesday and we get an error what is this let's see here we get an issue with this let me have a quick look and I'll be right back okay so I just remembered actually forgot one thing that I need to add here so for when I'm actually passing these dates I need to actually add something to them that is this weird thing it's is a format we did in the last video but I just forgot about it so is a format which is formats them properly I don't really know exactly how all this formatting is supposed to work it's kind of weird because you know what times you have different time zones and all that but now if we run this we should hopefully get something that actually works all right so I'm just signing in to my other Google account now and I'm gonna test this out and show you how this works so what I'm gonna do is run the program do I have anything on Thursday and what you can see is it actually pops up my entire schedule for Thursday here which is correct it means I have a lecture a lab a tutorial and a DGD now for those of you unaware what this means I'm in school right now so these are like my course codes and times that they Pinet um what we're gonna do in the next video is actually make this speak it out to us rather than just showing us what we have but I mean I think this is pretty cool so far that we can actually just speak into the computer you know ask it like what do I have on a specific day and it can actually attach that information for us I know a quick thing here that I want to do is just inside of this function I noticed that sometimes we get an error if you know there's no date that it finds so what we want to do is just do a quick if statement here before this last return that says if month equals equals negative 1 which means essentially we haven't figured out a month then what we need to do is or if month equals equals negative 1 or day equals equals negative 1 we're just gonna return none so we'll return none I don't know why this is lagging all right so sub-line text was lagging there so I'd restart but anyways we're just gonna return none here which essentially is saying you know if we've gone through this and we didn't find a date so we didn't find a month we didn't find a day return non grouted than running this because this code will actually return an error to us as it tries to create a date with a negative month right because month starts at negative 1 so noise that has been it for this video in terms of actually getting you know the events that we have on a specific day simply by speaking to the computer the next one we're gonna modify this function so it actually speaks back to us and tells us you know you have an event at 3 p.m. or whatever it is and yeah so if you guys have any ideas as always leave them in the comments down below and I will see you guys in the next video\n"