Convert Text to mp3 using Python
Python provides various modules and APIs for converting text messages to speech.
Here we will use gTTS (Google Text-to-Speech) and win32com.
Using win32com
Installation
pip install pypiwin32
Usage
import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak('Welcome to Hackzism')
Using gTTs
Installation
pip install gTTS
Usage
from gtts import gTTS
import os
text = 'Welcome to Hackzism'
language = 'en'
speech = gTTS(text=text, lang=language, slow=False)
speech.save("hackzism.mp3")
os.system("hackzism.mp3")
This will create an mp3 file and play the speech
If you would like to contribute to Hackzism you can also write an article and mail to hackzism.hack@gmail.com.
Your article will be published on our home page.
Comments
Post a Comment