How to convert text into speech using python
Let’s move on to an awesome project on how to convert text into audio using python. Before getting into this we will have a python and gTTS and Playsound library. In this case, I will use pycharm IDE
How to install pycharm in windows: https://iterathon.tech//how-to-install-the-pycharm-in-windows/
Open New Projects
After opening a pycharm click on a new project and you can give it any name as a Text into Audio to the project.
Once you give it a name and click on the create. It takes few seconds to create the project, On the current project there are some existing files are found in ide so, delete all those files using Ctrl+A and Backspace. Now Python is ready to code before that we need one awesome python packages called gTTS.
gTTS Library
gTTS (Google Text-to-Speech), a Python library and CLI tool to interface with Google Translate text-to-speech API.
Link to gTTS package: https://pypi.org/project/gTTS/ .
After getting into the link. You need to copy the magical word to install gTTS. That is pip install gTTS. If you have mac then type python3 -m pip install gTTS.
Playsound Library
Pure Python, cross platform, single function module with no dependencies for playing sounds. Playsound is used to play sound without use of any external software.
Link to playsound package: https://pypi.org/project/playsound/
After getting into the link. You need to copy the magical word to install playsound. That is pip install playsound. If you have mac then type python3 -m pip install playsound.
Install in Terminal
Again go to the pycharm and click terminal then paste the magical word pip install & pip install playsound . It takes few seconds to install packages. Once the package gets installed and then go to your project Text into Audio.
I have been done with the these two library installation. so, It told that Requirement already satisfied.
Code
This is an easy and crazy python project convert text into speech. Let’s further move on to the python program.
#pip install gtts from gtts import gTTS # pip install playsound from playsound import playsound audio = 'Iterathon.mp3' language = 'en' text = gTTS(text = "Hello, I'm your lovely Iterathon", lang = language, slow= False) text.save(audio) playsound(audio)
Related Post
How to design Instagram Logo using python: https://iterathon.tech//how-to-design-instagram-logo-using-python/
Detect Motion and intimate to the user | python: https://iterathon.tech//detect-motion-and-intimate-to-the-user-python/
How to Impress a girl’s heart using python heart: https://iterathon.tech//how-to-impress-a-girlfriend-heart-using-python/
Learn Something New ❣