I should have stated in the original thread that SAPI5 defaults to synchronous mode whereas SAPI4 defaults to asynchronous. Sorry Vince..
Please see NOTES at end.
This code demos setting:
synchronous mode (default)
Rate (how fast it speaks..)
Pausing and Resuming asynchronous speech
and how to speak the contents of a file (please spec a REAL FILE!)
Code: Select all
#define SPF_DEFAULT 0 'not asynchronous
#define SPF_ASYNC 1 'mmmm... asynchronous
#define SPF_PURGEBEFORESPEAK 2 'Purges all pending speak requests prior to this speak call.
#define SPF_IS_FILENAME 4 'The string passed is a file name, and the file text should be spoken.
#define SPF_IS_XML 8 'The input text will be parsed for XML markup.
#define SPF_IS_NOT_XML 16
#include once "disphelper/disphelper.bi"
#include once "windows.bi"
dim as HRESULT hr
dim myt as wstring * 512
dim as string tempstr
dim shared as IDispatch ptr tts=NULL 'DISPATCH_OBJ(tts)
declare sub imouttahere() destructor
dhToggleExceptions(TRUE)'FALSE) 'set this TRUE to get error codes
myt="Now is the time for all good men to come to the aid of the party"
dhPutValue(tts, ".Volume = %d", 80) 'Volume range is 0 to 100
'test speaking a text file, have it long enough for
' the pause and resume tests that follow..
myt="c:\whatever\long\file.txt" 'PLEASE change to something real..
if dir(myt)="" then
print "Abandoning further tests, ";myt;" file doesn't exist"
print "Exit in 5 seconds.."
dhPutValue(tts,".Volume = %d",100)
SPF_IS_NOT_XML or SPF_IS_FILENAME or SPF_ASYNC)'async from file
dhPutValue(tts,".Rate = %d",2) 'Rate range is -10 to 10
print "Sleeping to exit.."
sub imouttahere() destructor
This code is specific to SAPI5 which in theory will run on Win98. The core elements (see other thread) were/are a part of WinXP. The speech engine et al are not installed with XP, however installing any Office prod that has speech capabilities does. Without Office installed (I'm not sure what flavors) you must install the speech engine etc (again see other thread) separately.
Kristopher reports that all works on Vista without additional installations.
There is a method to wait for the asynchronous speech to complete, say before exiting your program, - if I have time I'll finger that out later.
ETA "destructor" on sub.. won't work without it..