Hi!
I just wanted to post the Python creation of speech which also has the
needed load of the module for speech once created which is used only when
the executable file has been made and you are not near any computer that has
windoweyes installed or a windows speech package.
For when the python file is first compiled you must be on a computer
that has all the speech packages installed on besides Python.
Eventually all the needed software is loaded using the generated python
file, or windoweyes.py file where the extension .py is called a module and
is imported as a module.
Python has this unique ability to generate a python file of the object
you created and it is done automatically in the background. Once you have
run the program and created the object, it also has a generated copy in a
sub folder called gen, which is inside the comtypes sub folder which are all
inside the python lib site packages sub folder.
This is done using the imported module below:
import win32com.client
So below is the python code to do all the needed stuff and what is
needed to import for most games and such.
Note: the sign called the pound or number sign, # is the python version for
a comment line.
Remember that all python code is indent based.
# Load Modules
import pygame #The game module which has video and sound drivers.
from pygame.locals import *
from pygame.event import Event
import random, sys, os
import time
from math import *
#Import the client side commands and there constants name list:
from win32com.client import constants
import win32com.client
import BattleSapi5 #A modified version of SAPI engine.
#Below Reduces program Code Name Size and Generates Needed 3'rd Applications
For Compiling .exe Files.
from comtypes.client import CreateObject
#If you did not use the from command above the code would have to be:
comtypes.client.CreateObject each time you wanted to create an object.
# Fetch Generated Speech, if not trap the error:
#Fetch Windoweyes Engine:
try:
from comtypes.gen import WindowEyes
except:
print " Windoweyes Not Generated Yet "
#Fetch SAPI Windows Voices:
try:
from comtypes.gen import SpeechLib
except:
print " Speech Lib Not Generated Yet "
#Fix for no video device on XP machines placed in as Pygame 1.9.1 bug fix.
os.environ['SDL_VIDEODRIVER']='windib'
INIFile = 0
#Set Windoweyes voice parameter defaults:
# Below is the Windoweyes application model under the object model list:
#Trap error if computer did not install Windoweyes:
try:
WeTts = CreateObject( "windoweyes.application")
#Same As:
# WeTts = win32com.client.Dispatch("WindowEyes.Application")
#Now Make dictionary Keys For Speech:
WeScreenVoice = {"v": WeTts.ActiveSettings.Screen.Tone, "rl":
WeTts.ActiveSettings.Screen.Rate, "pl": WeTts.ActiveSettings.Screen.Pitch,
"vl": WeTts.ActiveSettings.Screen.Volume}
WeTtsDict[ "Org"] = WeScreenVoice
WeVoices = True
INIFile = WeTts.INIFile( myIniFile)
except:
print
print "Error!"
print " No Windoweyes Voice Engine!"
print
# Below works but using my sapi module.
#Creating or Fetch The SAPI Engine:
#tts = win32com.client.Dispatch("SAPI.SpVoice") #, constants.SVSFlagsAsync)
# Use my BattleSapi 5 module instead:
SapiVoices = False
try:
tts = BattleSapi5.SynthDriver()
tts.init()
SYNC = tts._sync
ASYNC = tts._async
PURGE = tts._purge
ISAFILE = tts._is_filename
XML = tts._xml
NOT_XML = tts._not_xml
PERSIST = tts._persist_xml
PUNC = tts._punc
WAIT = tts._wait
tts.setVolume( 100)
tts.setRate( 1)
SapiVoices = True
except:
print
print "Error!"
print " No SAPI Voice Engine!"
print
SYNC = 0
ASYNC = 1
PURGE = 2
PUNC = 64
#Save Windoweyes and SAPI engine flags Dictionary Keys:
WeTtsDict[ "weVoices"] = WeVoices
WeTtsDict[ "sapiVoices"] = SapiVoices
WeTtsDict[ "WeTts"] = WeTts
WeTtsDict[ "iniFile"] = INIFile
WeTtsDict[ "tts"] = tts
The above dictionaries are used when needed inside the game or program
you run. As I stated above, before creating the object modules I loaded the
created versions of these modules in python code so they are the called upon
when created if you have compiled the code inside an executable. By
generating the python module version you now have windoweyes inside an
exectable that can be transported any place you want to place it.
You don't have to do all I did, just do it for Windoweyes and import
only the windoweyes module at the top once it has been saved as a generated
python module, Windoweyes.py
I placed the error trap in for you have to skip the error to get to the
create part. Once it has made the create part then the error trap will load
the module and the create section will use it.
As I stated this sequence is needed to have the game or script to run to
install the python module version of Windoweyes. You must on the first run
use a computer that has these speech libraries installed.
Once you have generated there python code version, you then do not need the
voice engines installed, but still must have Python installed in order to
find those modules.
but,
Once you have compiled the game or script as an executable, then you do
not need any of them, Python, Windoweyes, nor SAPI engine on the computer
that runs the executable.
I use Pyinstaller for it is the best one out there and you can only use
up to Python 2.7 using that installer.
Also Pygame module is best run using the Python 2.7 version.
Hope my explanation is understandable.
Bruce
---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com
_______________________________________________
Any views or opinions presented in this email are solely those of the author
and do not necessarily represent those of Ai Squared.
For membership options, visit
http://lists.window-eyes.com/options.cgi/scripting-window-eyes.com/archive%40mail-archive.com.
For subscription options, visit
http://lists.window-eyes.com/listinfo.cgi/scripting-window-eyes.com
List archives can be found at
http://lists.window-eyes.com/private.cgi/scripting-window-eyes.com