Python implements the method of converting text to speech

Source: Internet
Author: User
# 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!")
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.