Hello Code Lovers,
Here
I will give you a program,
“Text-to-Speech”
with a little line of python codes.
In
this program, you will get a function that can speak an open-source file
format. Like: - (.txt, .pdf, .py) and many more
Just Enter the file location and then take the rest to your eyes.
You
can use this in travel or if not want to read files.
(Works Like mp3 🎧).
Requirements for using this program:
1. The latest version of Python (>=3.2)
2. Install pyttsx3 module “pip install pyttsx3”
3. File format: (.txt, .pdf and more readable file)
Codes
are:
import pyttsx3
# Just Import pyttsx3, for installation pyttsx3
"pip install pyttsx3".
process = pyttsx3.init('sapi5') # Microsoft Speech API ('SAPI').
volume = pyttsx3.init('sapi5').getProperty('voices')
#'voices' = List of L{voice.Voice} objects
supported by the driver.
process.setProperty('voice', volume[1].id) # 'voice' =
String ID of the volume, [volume[1].id {voice.Voice}] where ([0],[1],[2],.. )
are speech language.
def speaking(word): # an argument
which speaks by the function.
process.say(word) # Speak output form given file.
process.runAndWait() # Speak
with rest.
While True:
# While Loop for reading a new file after completing one.
file = input('Enter your file location with file name : \n')
# File name you want listen.
with open(f'{file}','rt') as read: # 'r' = read ,
't' = text format.
for i in read: # Extract word form file.
speaking(i) # speak output.
print("\n The End") # Alert! After Complete file.
Visit my Page:
In Tech, For Tech, By Tech, With Tech, Just Tech, Only Tech
1 Comments
Hmm 🤔! Very useful project
ReplyDelete