speak完成如何判斷?如何使用SpVoice.SpeakCompleteEvent,這個(gè)問(wèn)題困擾了我兩天,最后看到msdn上的例子才知道要使用WaitForSingleObject函數處理它返回的時(shí)間句柄,之前的想speak或者偏移量的是多么荒謬啊。
peech API 5.3
Object: SpVoice
Type: Hidden
- SpVoice.SpeakCompleteEvent() As Long
Return Value
A Long variable containing the event handle.
Example
- Dim objVoice As SpeechLib.SpVoice
- Dim lngHandle As Long
- Dim lngRtn As Long
- Const INFINITE = -1&
- Set objVoice = New SpVoice
- objVoice.Speak "please wait until this text has been spoken", SVSFlagsAsync
- lngHandle = objVoice.SpeakCompleteEvent 'Get a handle on this stream
- lngRtn = WaitForSingleObject(lngHandle, INFINITE) 'Wait for completion
一開(kāi)始用 if WaitForSingleObject(SpVoice.SpeakCompleteEvent, INIFINTE) = WAIT_OBJECT_0 then判斷發(fā)現當朗讀時(shí)它會(huì )一直讀下去,界面上按鈕都不能點(diǎn),就改成WaitForSingleObject(SpVoice.SpeakCompleteEvent, 200)就好了,其中也參考了下面百度文庫中的文章
一下子跳到等待函數 WaitForSingleObject, 是因為下面的 Mutex、Semaphore、Event、WaitableTimer 等同步手段都要使用這個(gè)函數; 不過(guò)等待函數可不止 WaitForSingleObject 它一個(gè), 但它最簡(jiǎn)單.
function WaitForSingleObject(
hHandle: THandle; {要等待的對象句柄}
dwMilliseconds: DWORD {等待的時(shí)間, 單位是毫秒}
): DWORD; stdcall; {返回值如下:}
WAIT_OBJECT_0 {等著(zhù)了, 本例中是: 等的那個(gè)進(jìn)程終于結束了}
WAIT_TIMEOUT {等過(guò)了點(diǎn)(你指定的時(shí)間), 也沒(méi)等著(zhù)}
WAIT_ABANDONED {好不容易等著(zhù)了, 但人家還是不讓咱執行; 這一般是互斥對象}
//WaitForSingleObject 的第二個(gè)參數一般給常數值 INFINITE, 表示一直等下去, 死等.

