Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "sapi.inc"
#Resource Manifest, 1, "xptheme.xml"
Enum Equates Singular
IDC_RichEdit = 500
IDC_Speak
IDC_Stop
End Enum
%Msg_SAPI_Event = %WM_User + 1
Global hDlg,hRichEdit As Dword
Global wTextZ,wTempZ As WStringZ*1000, pSp As ISpVoice
Function PBMain() As Long
Dialog Default Font "Tahoma", 14, 1
Dialog New Pixels, 0, "SAPI Test",,,300,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Speak,"Speak", 10,10,100,30
Control Add Button, hDlg, %IDC_Stop,"Stop", 120,10,100,30
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h,iPos As Long, P As CharRange
Local eventItem As SPEVENT, eventStatus As SPVOICESTATUS
Select Case Cb.Msg
Case %WM_InitDialog
InitializeSAPI
wTextZ = "Now is the time for all good men to read"
wTextZ += " this sentence and head to the enlistment"
wTextZ += " center to help their country fight for justice!"
CreateLocalRichEdit
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_RichEdit, w-20,h-60
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Speak
SendMessage hRichEdit, %EM_ExGetSel, 0, VarPtr(P)
iPos = InStr(P.cpMin,wTextZ,$$Spc)
wTempZ = Mid$(wTextZ,iPos+1)
pSp.Speak(wTempZ, %SPF_Async, ByVal %Null)
Case %IDC_Stop : pSp.Speak("", %SVSFPurgeBeforeSpeak, ByVal %NULL) 'stops speaking by sending empty string
End Select
End Select
End Function
Sub InitializeSAPI
pSp = NewCom "SAPI.SpVoice"
pSp.SetInterest(SPFEI(%SPEI_WORD_BOUNDARY) Or SPFEI(%SPEI_END_INPUT_STREAM), SPFEI(%SPEI_WORD_BOUNDARY) Or SPFEI(%SPEI_END_INPUT_STREAM))
pSp.SetNotifyWindowMessage(hDlg, %MSG_SAPI_EVENT, 0, 0)
End Sub
Sub CreateLocalRichEdit
LoadLibrary("msftedit.dll")
Control Add "RichEdit50W", hDlg, %IDC_RichEdit, wTextZ,10,50,100,100,%WS_Child Or %WS_ClipSiblings Or %WS_Visible _
Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop, %WS_Ex_ClientEdge
Control Handle hDlg, %IDC_RichEdit To hRichEdit
End Sub
http://www.garybeene.com/sw/gbsnippets.htm