Python Voice Assistant Tutorial #7 - Speaking Events (With Pyttsx3)
Skills:
LLM Foundations90%Prompt Craft80%Prompting Basics70%Prompt Systems Engineering60%Agent Foundations50%
Key Takeaways
This video tutorial demonstrates how to create a Python voice assistant that speaks out events from Google Calendar using the Pyttsx3 library for text-to-speech functionality and the Google Calendar API for event retrieval.
Full Transcript
hello everyone and welcome back so in the last video what we did is essentially make it so we can speak to the computer asking about any day that we have in our Google Calendar and see what events we have on that day so I'll give a quick demo here by running the program if I can actually run it what do I have on November 5th and you can see it actually prints out my entire schedule here saying I have a lecture lab lab and another lecture so this is how this works now it's gonna be really nice to actually get this assistant to speak back to us rather than us having to read through this like we would do if we just had you know our Google Calendar so what we're gonna do is modify this function get events so that it does exactly that and it speaks this back to us now the first thing I'm gonna start by doing is making an L state in here so it's actually saying if not event so there's nothing there we're gonna print no upcoming events otherwise what we're gonna do is we are going to actually instead of printing this we're going to speak this because we're gonna have the assistant speak that and otherwise we will have an F string in here for what the assistants gonna speak and it is gonna speak you have in here the Len of events event on this day so essentially it's gonna tell us how like we have you know six events on this day or we have three events on this day we're gonna start by speaking that out now what we're gonna do next is we're actually going to loop through all these events here and we're gonna print out the events like what it is as well as the time that it starts at so we're gonna say you have you know CSI to ten lecture on at 7:00 p.m. or whatever it is that's what I'm gonna be printing out so to do this we actually need to do a little bit of kind of weird manipulation with this date/time object that we get from this start variable here and we need to figure out the hour at which we have the event so to do this is a little convoluted I'll try to explain this but we're gonna say start underscore time equals string I guess it starts dot split at T like this one dot split at I think it's : and then zero now or sorry not : actually this is a - I'm gonna walk you through exactly what this just did this is actually going to give us the hour at which our event starts so if you look here at the string it's on the bottom of my screen I wish let's see if I can make it a bit bigger there we go you can see down here we have like 2019 11:05 T and that's how this date string comes it comes with it T so when I start by doing is splitting this whole string by T so what that means is we're gonna take this half and this half and split them so once I split this by this T I take the first index which is gonna give me all of this so 10 to 5 now what I do after this now is I split by this - so now I just get this 10 and that's exactly what I want because you know it starts at 10 now this - 5 is actually just like the UTC time zone so yours might be different here depending on what you have you can see you know mine starts at 10 then it starts at 1 then I guess 5 and then 7 so that's kind of how that works so that's how we split it so now that we split that with the start time we're gonna do next is add either an AM or a PM to our what is it is like string so what we're gonna say is if start underscore time we're gonna say actually if int start underscore time dot splits by : 0 is less than 12 then what we're gonna do is we're gonna say start mmm yes for as they start underscore time people start underscore time plus in this case a.m. because this means that the events happening in the a.m. so we want to say you know you have this at 10:00 a.m. now otherwise what will do is will say start on your square time people start on your square time + yeah now this is pretty straightforward what we're gonna say is you know we're gonna find this time so we're gonna find whatever it is we're gonna check if it's less than 12 because if it's less than 12 that means it's in the morning and we add an a.m. otherwise it's in the afternoon with the p.m. and then we add that to the end of this string because you know start time is a string and then read it out so now what we're gonna do is gonna say speak and then here we're gonna say event summary which is this part here so the CSI 2110 lecture that's gonna be the summary and we're gonna say plus at in this case and then our start underscore time so we're gonna say we have whatever the actual event summary so CSI lecture at and then maybe in this case 10:00 a.m. that's what we're gonna do and that should hopefully work let me just do a quick look through here to make sure I didn't mess anything up too badly it looks to be ah one second I need to fix this bracket here so we're gonna split at t then we put the square bracket so just make sure you didn't mess up those brackets like I did but that looks to be right now so let's run this and test it out what do I have on Monday you have to this day 21:36 ledger at 10:00 a.m. so see 2109 919 p.m. and there we go that is how that works now what we can also do is if we want it to say like 7:00 p.m. instead of you know like 19 p.m. because that doesn't really make sense what we'll say here is we'll just take like this here and subtract 12 from it so it'll actually tell us the correct time so I'm gonna just copy this actually I'm gonna put this here and I'm gonna say start underscore time equals string of this minus 12 so let's run this now and we'll say the same thing and see we get 7 p.m. because what this is doing is just getting rid of that 24 hour time and giving us because we have the AM and PM s right what do I have on Monday 21:36 ledger at 10 a.m. 21 at 7:00 p.m. and there we go that is how that works now this is correct this is actually what my schedule is that is pretty much how we get this to speak it out now the next thing that I'm going to add here because this video is kind of short he's just making it so we only actually call this you know get events function in this get date function if we say something that you know makes sense for that so like I'm only gonna call get events or get date if we say something to that requires getting that because right now we're always gonna do that so whether I say like hello will still call get events will still call get date so I'm just gonna create a list here which is actually just gonna stand for all the things that we could say to trigger us to want to tell the person their calendar or the events they have on that day so I'm gonna call this like I guess calendar underscore strings I don't know you call it whatever you want and then here I'm just gonna put a bunch of kind of phrases that someone might say before they're gonna ask about what they have or like they're gonna ask about their plans so you guys will understand I'm gonna say what do I have like if that's in the string someone's probably asking like what do I have on Tuesday or what do I have on November 3rd so then we're gonna give that information to them you can say do I have plans if someone says that then they're probably gonna be talking about a day and they probably gonna want to know what they have on that day you might say am i busy so if you say am i busy then that might you know you might add like am i busy on Wednesday so we can add all kinds of stuff here I might just say do I have plans as another one and oh I already have do I have plans okay we'll just leave it at 3 for now but I mean you guys can add a ton of these that you think someone might say when they want to ask about their calendar so what we're gonna do now is we're gonna actually loop through all of these see if this is a part of whatever text we got here and if it is then you know we'll call get events we'll get the date from that text and we'll tell them what they have on that day so we're gonna say for I guess I don't know let's just go hmm what should it be let's say for parades in calendar strings if phrase like this in text so essentially if we see one of these in the tech then what we will do is exactly this will get the events and to say that to the person now what we're actually going to do here that was split this up into two variables so we're gonna say date equals get date text now we're gonna do a quick thing here and we're going to say if date which essentially means if it's not none then we'll pass that into here and actually get the plans that we have on that day now this is just to prevent us from possibly you know running into an era where we return none from yet date because I actually didn't talk about a specific day and then we call to get events function you know with that none and we run into an error so that's what this is gonna do but if let's say you know they say what do I have and then they don't continue and they don't say anything we should probably tell them you know like I don't understand what you're saying or this doesn't make sense so I'm just gonna speak please try again now the very last thing I'm gonna add here before I test this out is I just want to print a thing here that says start after we authenticate Google because sometimes if you just start speaking immediately when you run the bot it's still authenticating your like information for Google Calendar and all of that so we're gonna wait for it to say start and then that's actually one will start speaking and let's try this now what do I have on Friday uh and unfortunately what do I have ah that's this is what I need to do I forgot I used to say if phrase in textile or need to turn the text into dog lower okay so if phrase in textile lower because you see this eye here it was it wasn't being caught in that phrase so let's try this now wait for it to start to see that message let's run this one more time what do I have on Friday you have my events on this day six twenty one to live richer eleven Here I am and there we go so you can see that is how that works and now we can essentially speak to the computer asking about any day and it will tell us what we have on that day now I think this is really cool it's actually pretty useful we're gonna obviously make this more advanced and add some more features but as always if you guys have any ideas or you think that I did anything wrong in this video please don't hesitate to leave a comment down below I do read them all what would that being said I will see you guys in the next video
Original Description
In this tutorial we will add to our previously created functions to get our assistant to speak out events that we have on a specific day. We will be using pyttsx3 to do this.
Playlist: https://www.youtube.com/watch?v=-AzGZ_CHzJk&list=PLzMcBGfZo4-mBungzp4GO4fswxO8wTEFx
Text-Based Tutorial: https://techwithtim.net/tutorials/voice-assistant/speaking-events/
◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python
https://tech-with-tim.teachable.com/p...
📸 Instagram: https://www.instagram.com/tech_with_tim
🌎 Website https://techwithtim.net
📱 Twitter: https://twitter.com/TechWithTimm
⭐ Discord: https://discord.gg/pr2k55t
📝 LinkedIn: https://www.linkedin.com/in/tim-rusci...
📂 GitHub: https://github.com/techwithtim
🔊 Podcast: https://anchor.fm/tech-with-tim
💵 One-Time Donations: https://www.paypal.com/donate/?token=...
💰 Patreon: https://www.patreon.com/techwithtim
◾◾◾◾◾◾
⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡
Tags:
- Tech With Tim
- Python Tutorials
- Pyttsx3
- Python playing sound
- Python Voice Assistant Tutorial
- Voice Assistant Python
#Python #Pytttsx3 #SpeechRecognition
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tech With Tim · Tech With Tim · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
Building Smarter AI: How LLM Chatbots Become More Accurate with RAG (Retrieval-Augmented…
Medium · LLM
Como IA, Pesquisa Operacional e LLMs estão transformando a tomada de decisão nas empresas
Medium · AI
Why ChatGPT Doesn’t “Know” Anything (And Why It’s Still So Smart)
Medium · AI
Teaching a 0.6B LLM to Rank: Score-Weighted BPR Fine-Tuning from Blended Relevance Signals
Medium · Machine Learning
🎓
Tutor Explanation
DeepCamp AI