•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 397,761 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,524 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser:
Text to speech can be implemented in its simplest form using Microsoft's Component Object Model (COM) connecting to the Speech API (SAPI). The attached Python code shows you how to do this.
# to bring text to speech capability to your Windows computer # install SAPI5Speech (XP and Vista should have it already) # http://www.nolad.com/vt/redist/SAPI5SpeechInstaller.msi # # Windows XP has Sam, SAPI5Voice adds Mary and Mike # http://www.nolad.com/vt/redist/SAPI5VoiceInstaller.msi # # the Python for Windows extensions should be installed # for COM to work eg. pywin32-210.win32-py2.5.exe # from http://sourceforge.net/projects/pywin32/ # # tested with Python25 on a Windows XP machine by vegaseat import win32com.client voices = { 'Sam' : 'Microsoft Sam', 'Mary' : 'Microsoft Mary', 'Mike' : 'Microsoft Mike' } # choose voice from the voices dictionary voice = 'Sam' # range 0(low) - 100(loud) volume = 100 # range -10(slow) - 10(fast) rate = -1 # some text to speak text = """\ It is said, that if you line up all the cars in the world end to end, someone would be stupid enough and try to pass them. """ # initialize COM components of MS Speech API # COM is Microsoft's Component Object Model # (COM is also used by Peter Parente's pyTTS) speak = win32com.client.Dispatch('Sapi.SpVoice') # assign a voice speak.Voice = speak.GetVoices('Name='+voices[voice]).Item(0) speak.Rate = rate speak.Volume = volume # now speak out the text speak.Speak(text)
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)