In this article, you will see how we can use python to convert text into speech in python. you will see how we can do the conversion of text into audio.
This method is very helpful in the conversion of textbooks into audiobooks with the help of python programming language.
How do I convert text into speech in Python
we will be using the gtts library to do the conversion of text into speech. The gtts library in python is very helpful in the conversion of text into audio.
Install gtts library in Python
pip install gtts
Python code to covert text into audio
from gtts import gTTS
import os
file = open("abc.txt", "r").read()
speech = gTTS(text=file, lang='en', slow=False)
speech.save("voice.mp3")
os.system("voice.mp3")
Summary and Conclusion:
You have seen how we can use the gtts module in python to do the conversion of text into speech in python. if you have any questions, please leave them in the comment section.
I am a software Engineer having 4+ Years of Experience in Building full-stack applications.