Member-only story
Making Your Computer Talk: Python Text-to-Speech for Fun Skits
So you’ve decided you want your computer to be more than just a lifeless screen of spreadsheets and cat pictures. You want it to talk. And not just talk, but deliver comedy skits with the charm of a late-night show host. Well, you’re in the right place! Today, we’ll be breathing life into your computer with Python’s text-to-speech, whether to get your computer to tell your friends jokes, roast you, or even give that Oscar-worthy monologue. Time to start coding!
Step 1: Installing the Text-to-Speech Library (And Warming Up Your Vocal Cords)
First of all, we need to install the library that will give vocal powers to Python. There are a few out there but we are going to use gTTS — Google Textto-Speech — because it is easy and effective and also because it will not ask for a cup of tea after talking five hours in a row.
Open your terminal and install gTTS with the following command:
pip install gTTS
Boom! Now Python can begin babbling. If only this were the way to teach your uncle to cease repeating those three jokes at family gatherings.
Step 2: Import Libraries and Set the Stage for Laughter
We will start our Python script by importing the necessary libraries. Alongside gTTS, we are going to use playsound to ensure the comedy show of our computer is heard. Go ahead…