See the video first for demo:-
First create a text file named :- text_speech.txt
And type what ever you want it to read and save it.
Works offline:-
If error check and install using pip (python -m pip install pywin32)
Works online:-
If error check and install using pip (pip install gTTS)
First create a text file named :- text_speech.txt
And type what ever you want it to read and save it.
Works offline:-
1 2 3 4 5 6 7 8 9 10 11 | #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:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #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") |