Header Ads

Header ADS

Text to speech in python

Using pyttsx3

it will be work offline

Required:
pip install pyttsx3
pip install pypiwin32
pip install pypiwin32



import pyttsx3

engine = pyttsx3.init()

engine.say('Sally sells seashells by the seashore.')

engine.say('The quick brown fox jumped over the lazy dog.')

engine.runAndWait()




Changing voices



engine = pyttsx3.init()

voices = engine.getProperty('voices')
engine.setProperty('voice', voice.id)
 #here give the id like 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0'

engine.say('The quick brown fox jumped over the lazy dog.')


engine.runAndWait()




Changing speech rate



engine = pyttsx3.init()

rate = engine.getProperty('rate')

engine.setProperty('rate', 50)

engine.say('The quick brown fox jumped over the lazy dog.')

engine.runAndWait()



Changing volume



engine = pyttsx3.init()

volume = engine.getProperty('volume')

engine.setProperty('volume', 0.25)

engine.say('The quick brown fox jumped over the lazy dog.')

engine.runAndWait()



No comments

Theme images by Matt Vince. Powered by Blogger.