Playing with the new dispatch helper commands:
IDispatch speech
string text
speech = CreateComObject("Sapi.SpVoice","")
if speech <> NULL
while ucase$(text) <> "END"
PRINT "Enter something to say, \"END\" to exit"
INPUT ">",text
CallObjectMethod(speech,".Speak(%s)",text)
endwhile
speech->release()
else
PRINT "Sapi object not available"
do:until inkey$ <> ""
endif
END
Works if you have the speech API installed, or one of the Microsoft products that install it, such as Office. On Vista I beleive it is included with the os.
Paul.
Part 2. Selecting which voice to use. Works if you have the Speech SDK (Sapi 5.1) installed.
DECLARE CDECL EXTERN _dhPutRef(pointer pDisp, WSTRING szMember, ...),int
IDispatch speech
IDispatch voice
string text
pointer pText
int count,x
speech = CreateComObject("Sapi.SpVoice","")
if speech+0 <> NULL
SetComProperty(speech,".Rate = %d",0)
GetComProperty(speech,"%d",&count,".GetVoices.Count")
PRINT "Select which voice to use"
for x = 1 to count
GetComProperty(speech,"%o",&voice,".GetVoices.Item(%d)",x-1)
GetComProperty(voice,"%s",&pText,".GetDescription")
PRINT x,#<STRING>pText
FreeCOMString(pText)
next x
input ">",x
GetComProperty(speech,"%o",&voice,".GetVoices.Item(%d)",x-1)
if(voice <> NULL)
print "Voice found!"
_dhPutRef(speech,L".Voice = %o",voice)
endif
while ucase$(text) <> "END"
PRINT "Enter something to say, \"END\" to exit"
INPUT ">",text
CallObjectMethod(speech,".Speak(%s)",text)
endwhile
speech->release()
else
PRINT "Sapi object not available"
do:until inkey$ <> ""
endif
END
I havent converted _dhPutRef to a built in command yet, hence the need for the declare.
Paul.
Paul,
Works for me (XP SP2)! Can you alter the speed and intonation somehow?
Brian
The first line
SetComProperty(speech,".Rate = %d",0)
Change the '0' to any value from -10 to 10 and the rate will change.
Have to look up the pitch property.
SetComProperty(speech,".Volume = %d",50)
Works too.
What fun! I can see myself getting into all sorts of trouble :D
I haven't gone into this yet.... Can I make the speech anything I want, like phonetic transcription or foreign language?
Looking briefly at the API you can pronounce anything you want with phonemes.
Larry
When I try to compile, I get the following messages:
QuoteCompiling...
speech.eba
File: F:\EBDev\projects\BOB\speech.eba (1) unknown type
File: F:\EBDev\projects\BOB\speech.eba (3) Warning: undeclared function 'CreateComObject'
File: F:\EBDev\projects\BOB\speech.eba (8) Warning: undeclared function 'CallObjectMethod' - )
File: F:\EBDev\projects\BOB\speech.eba (10) invalid argument - )
File: F:\EBDev\projects\BOB\speech.eba (10) undeclared method - )
Error(s) in compiling F:\EBDev\projects\BOB\speech.eba
I downloaded in 2005 and installed it on my winxp/sp 2.
The download said it was the 5.1 version.
I searched my WINDOWS for a dll named speech but found none. What I did find was SPEECHSDK51.EXE-0047143A.pf.
Hi BOB!
I assume you installed the latest version of Ebasic.
Bob,
you need 1.6 or 1.61
Paul
Thanks all.
I will install that right away.
if speech+0 <> NULL
...
There is something i don't understand.
Assuming "speech+0" = speech, why adding "0" to "speech" then ?
Maybe my assumption is false.
Any explanations please ?