I can compile the following code in EBASIC but not IWBASIC. I am trying to add TTS and this lists what voices are available. What am I not doing right?
DECLARE CDECL EXTERN _dhPutRef(pointer pDisp, WSTRING szMember, ...),int
WINDOW w1
INT run=0
CONST VoiceList=1
OPENWINDOW w1,100,100,400,340,@TOOLWINDOW|@TOPMOST,0,"TTS Test",&main
CONTROL w1,@LISTBOX,"",10,10,200,100,@TABSTOP|@CTLISTNOTIFY|@VSCROLL,VoiceList
SETFONT w1,"Times New Roman",10,500,0,VoiceList
GetVoices(w1,VoiceList)
WAITUNTIL run=1
CLOSEWINDOW w1
END
SUB main
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1
CASE @IDCLOSEWINDOW
run=1
CASE @IDCONTROL
SELECT @CONTROLID
CASE VoiceList
SELECT @NOTIFYCODE
CASE 0
ENDSELECT
ENDSELECT
ENDSELECT
RETURN 0
ENDSUB
SUB Speak (string a,INT VoiceID)
IDispatch speech
IDispatch spvoice
speech = createComObject("Sapi.SPVoice","")
IF speech+0 <> NULL
GetComProperty(speech,"%o",&spvoice,".GetVoices.Item(%d)",VoiceID)
IF (spvoice <> NULL)
_dhPutRef(speech,L".Voice = %o",spvoice)
ENDIF
callObjectMethod(speech,".Speak(%s,0)",a)
speech->release()
ENDIF
ENDSUB
SUB GetVoices(WINDOW win,INT vList)
'clear list
WHILE GETSTRINGCOUNT(win,vList)>0
DELETESTRING win,vList,0
ENDWHILE
IDispatch speech
IDispatch spvoice
string text
pointer pText
int count,x
speech = CreateComObject("Sapi.SpVoice","")
if speech+0 <> NULL
GetComProperty(speech,"%d",&count,".GetVoices.Count")
FOR x = 1 TO count
GetComProperty(speech,"%o",&spvoice,".GetVoices.Item(%d)",x-1)
GetComProperty(spvoice,"%s",&pText,".GetDescription")
text=#<STRING>pText
ADDSTRING win,vList,text
FreeCOMString(pText)
NEXT x
speech->release()
endif
ENDSUB
Later,
Clint
You said you can't compile in IWBasic.
What compile error are you getting?
LarryMc
The code below compiles for me.
Make sure disphelper.inc is in your iwbdev/include folder
and disphelper.lib is in your iwbdev/libs folder
$include "disphelper.inc"
WINDOW w1
INT run=0
CONST VoiceList=1
OPENWINDOW w1,100,100,400,340,@TOOLWINDOW|@TOPMOST,0,"TTS Test",&main
CONTROL w1,@LISTBOX,"",10,10,200,100,@TABSTOP|@CTLISTNOTIFY|@VSCROLL,VoiceList
SETFONT w1,"Times New Roman",10,500,0,VoiceList
GetVoices(w1,VoiceList)
WAITUNTIL run=1
CLOSEWINDOW w1
END
SUB main
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1
CASE @IDCLOSEWINDOW
run=1
CASE @IDCONTROL
SELECT @CONTROLID
CASE VoiceList
SELECT @NOTIFYCODE
CASE 0
ENDSELECT
ENDSELECT
ENDSELECT
RETURN 0
ENDSUB
SUB Speak (string a,INT VoiceID)
IDispatch speech
IDispatch spvoice
speech = createComObject("Sapi.SPVoice","")
IF speech+0 <> NULL
GetComProperty(speech,"%o",&spvoice,".GetVoices.Item(%d)",VoiceID)
IF (spvoice <> NULL)
dhPutRef(speech,L".Voice = %o",spvoice)
ENDIF
callObjectMethod(speech,".Speak(%s,0)",a)
speech->release()
ENDIF
ENDSUB
SUB GetVoices(WINDOW win,INT vList)
'clear list
WHILE GETSTRINGCOUNT(win,vList)>0
DELETESTRING win,vList,0
ENDWHILE
IDispatch speech
IDispatch spvoice
string text
pointer pText
int count,x
speech = CreateComObject("Sapi.SpVoice","")
if speech+0 <> NULL
GetComProperty(speech,"%d",&count,".GetVoices.Count")
FOR x = 1 TO count
GetComProperty(speech,"%o",&spvoice,".GetVoices.Item(%d)",x-1)
GetComProperty(spvoice,"%s",&pText,".GetDescription")
text=#<STRING>pText
ADDSTRING win,vList,text
FreeCOMString(pText)
NEXT x
speech->release()
endif
ENDSUB
LarryMc
It compiles fine on 'puter also, but the list box has nothing in it. Is there something else I need for the list to be populated with anything?
whitenite1
QuoteError: Unresolved extern _dhPutRef
The disphelper library has been un-decorated, remove the leading underscore.
My SPVoice returns Count=1, GetDescription=NULL
I did get it to compile, by removing the underscore and including disphelper.inc. But it ended up with nothing in it like whitenite1. With EBASIC it is populated with all the voices available on my system.
Thanks,
Clint
It didn't have anything in the list in IWB or EB for me.
One of the things I noticed is that even though speech has a non-zero value
after executing this line
speech = CreateComObject("Sapi.SpVoice","")
the following IF statement is acting as if speech=NULL.
This is in IWB on my win7 64 machine.
LarryMc
I am using a Win7 64 machine. The following line..
Quotespeech = CreateComObject("Sapi.SpVoice","")
doesn't look like it is creating the "Sapi.SpVoice".
Speech is returning 0. Why does EBASIC work?
Later,
Clint
Just remove the empty string from CreateComObject. The default value for machine name is NULL.
Sapero,
I did that but the IDispatch "speech" still is 0 and it doesn't work.
Later,
Clint
My bad. Once again I had some settings wrong in the compiler options.
Thanks for your help,
Clint