# Text to Speech using SAPI (Windows) and Python module Pytts by Peter parente# Download installer file pytts-3.0.win32-py 2.4.exe # from:http://sourceforge.net/projects/uncassist# also needs:http://www.cs.unc.edu/research/assist/ packages/sapi5speechinstaller.msi# and Pywin32-204.win32-py2.4.exe at this date the latest version of win32com# From:http ://sourceforge.net/projects/pywin32/# tested with Python24 on a Windows XP computer vagaseat 15jun2005import pyttsimport Timetts = Pytts.create () # Set the speech rate, higher value = faster# just for fun try values of-10 to 10tts. Rate = 1print "Speech rate =", TTS. rate# set the speech volume percentage (0-100%) TTS. Volume = 90print "Speech Volume =", TTS. volume# get a list of all the available Voicesprint "List of voices =", TTS. Getvoicenames () # explicitly set a voicetts. Setvoicebyname (' msmary ') print "Voice is set ot msmary" print# announce the date and time, does a good jobtimestr = "The Dat E and time is "+ time.asctime () print TimestrttS.speak (timestr) printstr1 = "" "A Young executive is leaving the office at 6 pm if he found the CEO standing in front of A shredder with a piece of paper in hand. "Listen," said the CEO, "This is important, and my secretary have left. Can thing work? "" Certainly, "said the young executive. He turned the machine on, inserted the paper, and pressed the Start button. " Excellent, excellent! "said the CEO as his paper disappeared inside the machine. "I just need one copy." "" " Print Str1tts. Speak (STR1) TTS. Speak (' Haah haa haah haa ') printstr2 = "" Finagle ' s fourth law:once a job is fouled up, anything do to improve it's only m Akes it worse. "" " Print Str2printprint "The spoken text above have been written to a wave file (. wav)" TTS. Speaktowave (' Finagle4.wav ', str2) print "The wave file is a loaded back and spoken ..." TTS. Speakfromwave (' finagle4.wav ') printprint "substitute a hard-to-pronounce word like Ctrl key ..." #create an instance of the Pronunciation Correctorp = pytts.pronounce () # REplace words that's hard-to-pronounce with something that's spelled out or misspelled, but at least sounds like itp.a ddmisspelled (' Ctrl ', ' Control ') STR3 = P.correct (' Please press the Ctrl key! ') Tts. Speak (STR3) printprint "2 * 3 = 6" TTS. Speak (' 2 * 3 = 6 ') Printtts. Speak ("sounds goofy, let's replace * with Times") print "substitute * with times" # ' * ' needs the SPACESP. Addmisspelled (' * ', ' times ') STR4 = P.correct (' 2 * 3 = 6 ') TTS. Speak (STR4) printprint "Say that real fast a few times!" STR5 = "The Sinking steamer sunk!" Tts. Rate = 3for k in range (7): Print STR5 TTS. Speak (STR5) time.sleep (0.3) TTS. Rate = 0tts. Speak ("Wow, not one mispronounced word!")