Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Global hDlg As Dword, Words() As String, StopTalking As Long
Function PBMain() As Long
ReDim Words(2)
Array Assign Words() = "Power", "BASIC","Rules"
Dialog New Pixels, 0, "Speaking Test",300,300,200,120, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Say List", 50,20,100,20
Control Add Button, hDlg, 200,"Stop Talking", 50,60,100,20
Dialog Show Modal hDlg Call DlgProc
Do : Sleep 100 : Loop While ThreadCount > 1
End Function
CallBack Function DlgProc() As Long
Local i,hThread As Dword
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
Thread Create TalkThread(0) To hThread
StopTalking = 0
End If
If Cb.Msg = %WM_Command And Cb.Ctl = 200 And Cb.CtlMsg = %BN_Clicked Then StopTalking = 1
End Function
Thread Function TalkThread(ByVal StringAddress As Dword) As Dword
Local oSp As Dispatch, i As Long
Let oSp = NewCom "SAPI.SpVoice"
Local vRes,vTxt,vTime As Variant
For i = 0 To 20
vTxt = Str$(i)
Object Call oSp.Speak(vTxt) To vRes
vTime = -1 As Long
Object Call oSp.WaitUntilDone(vTime) To vRes
Sleep 4000
If StopTalking Then Exit For
Next i
End Function
'gbs_01367
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm