Charles Pegge
06-08-2010, 19:41
These examples are included in the examples/COM folder.
Basic access to SAPI voice Interface
'-----------------------------------------
'SAPI VOICE
'=========================================
Uses "oxygen"
Dim src As String
src="
#basic
#include Voice.inc
'
'
'
' ###############
' ###################
' ### ###
' ### ### ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### #### ## ###
' ### #### ###
' ### ###
' ### ###
' #############
' #########
CoInitialize(byval 0)
dim as GUID VoiceObjGuid, ISpVoiceGuid
dim as HRESULT hr
dim as ISpVoice ptr voice
dim as LPUNKNOWN pUnkOuter
dim as dword flags
const as PVOID NULL=0
guidval VoiceObjGuid, "96749377-3391-11D2-9EE3-00C04F797396"
guidval ISpVoiceGuid, "6C44DF74-72B9-4992-A1EC-EF996E0422D4"
& pUnkouter=0
hr=CoCreateInstance VoiceObjGuid, pUnkouter, context, ISpVoiceGuid, voice
if hr then print "SAPI Error " hex(hr) : jmp fwd done
voice.Speak w("Hello Everyone!"),flags,NULL
voice.WaitUntilDone &hFFFFFFFF
voice.Release
& voice=0
done:
CoUninitialize()
"
'msgbox 0,O2_prep src+o2_error
O2_asmo src
if Len(O2_ERROR) Then
msgbox 0,O2_ERROR
else
o2_exec
end if
OOPIFIED:
'=================================
'ATTACHING SAPI VOICE TO AN OBJECT
'=================================
'
'
' ###############
' ###################
' ### ###
' ### ### ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### #### ## ###
' ### #### ###
' ### ###
' ### ###
' #############
' #########
Uses "oxygen"
Dim c,src As String
dim v as long
src="
#basic
#include Voice.inc
incl VoiceMacros
Connect voice
ErrorHandler jmp fwd done
'---------
class mind
'=========
memory as string
end class
'-----------
class person
'===========
ISpVoice * voice
has mind
'
method new()
memory="<>"
end method
'
method del()
memory=""
end method
'
method learn(string s)
memory+=s "<>"
end method
'
method recall(string s)
sys a,b,c
string r
a=instr(memory,s)
if a then
a+=len(s)
b=instr(a,memory,"<>")
end if
if a then
r=mid(memory,a,b-a)
else
r="I do not remember " s
end if
if & voice then
voice.speak w(r)
voice.WaitUntilDone forever
else
print r
end if
end method
'
end class
def Create
{
%1 %2
%2.new()
}
def CreatePersistent
{
%1 * %2
& %2=news sizeof %1
%2.new
}
def Delete
{
%1.del
frees & %1
& %1=0
}
'====
'MAIN
'====
CreatePersistent Person Hilda
Give Hilda voice
'Remove Hilda voice
Hilda.learn ".greeting. Hello Everyone"
Hilda.recall ".greeting."
Delete Hilda
'====
done:
'====
DisConnect voice
"
'msgbox 0,O2_prep src+o2_error
O2_asmo src
if Len(O2_ERROR) Then
msgbox 0,O2_ERROR
else
o2_exec
end if
Latest Oxygen
http://community.thinbasic.com/index.php?topic=2517
Charles
Basic access to SAPI voice Interface
'-----------------------------------------
'SAPI VOICE
'=========================================
Uses "oxygen"
Dim src As String
src="
#basic
#include Voice.inc
'
'
'
' ###############
' ###################
' ### ###
' ### ### ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### #### ## ###
' ### #### ###
' ### ###
' ### ###
' #############
' #########
CoInitialize(byval 0)
dim as GUID VoiceObjGuid, ISpVoiceGuid
dim as HRESULT hr
dim as ISpVoice ptr voice
dim as LPUNKNOWN pUnkOuter
dim as dword flags
const as PVOID NULL=0
guidval VoiceObjGuid, "96749377-3391-11D2-9EE3-00C04F797396"
guidval ISpVoiceGuid, "6C44DF74-72B9-4992-A1EC-EF996E0422D4"
& pUnkouter=0
hr=CoCreateInstance VoiceObjGuid, pUnkouter, context, ISpVoiceGuid, voice
if hr then print "SAPI Error " hex(hr) : jmp fwd done
voice.Speak w("Hello Everyone!"),flags,NULL
voice.WaitUntilDone &hFFFFFFFF
voice.Release
& voice=0
done:
CoUninitialize()
"
'msgbox 0,O2_prep src+o2_error
O2_asmo src
if Len(O2_ERROR) Then
msgbox 0,O2_ERROR
else
o2_exec
end if
OOPIFIED:
'=================================
'ATTACHING SAPI VOICE TO AN OBJECT
'=================================
'
'
' ###############
' ###################
' ### ###
' ### ### ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### ## ## ###
' ### #### ## ###
' ### #### ###
' ### ###
' ### ###
' #############
' #########
Uses "oxygen"
Dim c,src As String
dim v as long
src="
#basic
#include Voice.inc
incl VoiceMacros
Connect voice
ErrorHandler jmp fwd done
'---------
class mind
'=========
memory as string
end class
'-----------
class person
'===========
ISpVoice * voice
has mind
'
method new()
memory="<>"
end method
'
method del()
memory=""
end method
'
method learn(string s)
memory+=s "<>"
end method
'
method recall(string s)
sys a,b,c
string r
a=instr(memory,s)
if a then
a+=len(s)
b=instr(a,memory,"<>")
end if
if a then
r=mid(memory,a,b-a)
else
r="I do not remember " s
end if
if & voice then
voice.speak w(r)
voice.WaitUntilDone forever
else
print r
end if
end method
'
end class
def Create
{
%1 %2
%2.new()
}
def CreatePersistent
{
%1 * %2
& %2=news sizeof %1
%2.new
}
def Delete
{
%1.del
frees & %1
& %1=0
}
'====
'MAIN
'====
CreatePersistent Person Hilda
Give Hilda voice
'Remove Hilda voice
Hilda.learn ".greeting. Hello Everyone"
Hilda.recall ".greeting."
Delete Hilda
'====
done:
'====
DisConnect voice
"
'msgbox 0,O2_prep src+o2_error
O2_asmo src
if Len(O2_ERROR) Then
msgbox 0,O2_ERROR
else
o2_exec
end if
Latest Oxygen
http://community.thinbasic.com/index.php?topic=2517
Charles