Install our App:- https://play.google.com/store/apps/details?id=com.solostudio.python_pysnakeblog
Convert text to speech,
Read text to speech from text file to mp3
Source code:
Works offline:
#Text to speech (offline)
#python -m pip install pywin32
#Program description:-
#Directly read from text without saving any mp3 file
import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
file = open("text_speech.txt","r")
#print(file.read())
string = file.read()
speaker.Speak(string)
If error check and install using pip (python -m pip install pywin32)
Works online:
#Text to speech (Online)
# pip install gTTS
#Program description:-
# It uses google translate in order to create
# mp3 file from text
from gtts import gTTS as gt
import os
file = open("text_speech.txt","r")
#print(file.read())
def read(text):
sound_file="file.mp3"
a = gt(text,"en")
a.save(sound_file)
os.system('mpg123 ' + sound_file)
try:
print("Generating...")
read(file.read())
except:
print("Enter Proper Text")
print("No connection to Google Translate")
finally:
print("Done")
If error check and install using pip (pip install gTTS)
#python #programming #developer