Date: 02-16-2022
Return to Index
created by gbSnippets
'There are a thousand ways that a program can benefit from being able to
'tell the user information, instead of just presenting it as text on the screen.
'In this snippet, the ReadText() function is called by a thread so that
'the main program can continue working while the computer reads the text
'to the user.
'Compiler Comments:
'This code is written to compile in PBWin10. To compile in PBWin9, replace this line:
Set oSp = New Dispatch In "SAPI.SpVoice"
'with this line:
Let oSp = NewCOM "SAPI.SpVoice"
'Primary Code:
'Credit: Jose Roca
Sub ReadText (sText)
Local vRes, vTxt, vTime As Variant, oSp as Dispatch
Set oSp = New Dispatch In "SAPI.SpVoice"
If IsFalse IsObject(oSp) Then Exit Sub
vTxt = sText
Object Call oSp.Speak(vTxt) To vRes
vTime = -1 As Long
Object Call oSp.WaitUntilDone(vTime) To vRes
End Sub
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
ReadText "Hello from Garey Beene"
End If
End Function
Sub ReadText (sText As String)
Local vRes, vTxt, vTime As Variant, oSp as Dispatch
Let oSp = NewCOM "SAPI.SpVoice"
If IsFalse IsObject(oSp) Then Exit Sub
vTxt = sText
Object Call oSp.Speak(vTxt) To vRes
vTime = -1 As Long
Object Call oSp.WaitUntilDone(vTime) To vRes
End Sub
'gbs_00210
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm