Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Callbacks and Timers » How to set a TimeCallback
How to set a TimeCallback [message #50667] Sun, 02 December 2018 00:48 Go to next message
forlano is currently offline  forlano
Messages: 1030
Registered: March 2006
Location: Italy
Experienced Contributor
Hello,

after reading many posts on the forum I am not able to realize what I want.

After pressing button btnStart the program begin to read a sequence of words. This is done via the SAPI library (text to speech). However I want permit the user to stop the reading at any time, button btnStop, even before the end of the sequence. To do it I used a SetTimeCallback linked to the callback Play. This is one of the version I used:

void VegaTab3::Start()
{   btnStart.Disable();
    btnStop.Enable();
    int int_row = arrp.GetCursor();
    if (int_row < 0) return; //prevent the crash of the application when int_row = -1)
    for (int i = int_row; i<arrp.GetCount(); i++) {
    	SetTimeCallback(500, THISBACK1(Play, i));
    }
    btnStart.Enable();
    btnStop.Disable();
}

void VegaTab3::Play(int i)
{	
    ISpVoice * pVoice = NULL;
    if (FAILED(::CoInitialize(NULL))) return ;

    //std::wstring in = L"";
    WString in;

    HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);    
	if(SUCCEEDED(hr))
	{					
        	//...
                // select a word
                // ...

                hr = pVoice->Speak((LPCWSTR)in, NULL, NULL);  //play it             
	
		pVoice->Release();
                pVoice = NULL;
	}
    ::CoUninitialize();
}

void VegaTab3::Stop()
{ 	
    KillTimeCallback();
	btnStart.Enable();
	btnStop.Disable();
}


Unfortunatly, in all my temptive, the btnStop cannot be pressed and the reading proceede till the end before I get again the control of the program. It is like the btnStop is freezed.

So the problem is: how to use the timecallback, or any other mean, to start a loop and stop it at any time?

Thanks,
Luigi
Re: How to set a TimeCallback [message #50669 is a reply to message #50667] Sun, 02 December 2018 09:42 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1756
Registered: August 2008
Location: Czech Republic
Senior Contributor

Hi Luigi,

It sounds like Speak() is blocking, effectively freezing you GUI until it finishes. I couldn't find relevant docs for C API (my google-fu is weak today Smile ), but the Visual Basic reference mentions that you need to pass some flag to actually make the call asynchronous. With a little luck, the C API could be the same Smile

Best regards,
Honza
Re: How to set a TimeCallback [message #50670 is a reply to message #50669] Sun, 02 December 2018 14:01 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1030
Registered: March 2006
Location: Italy
Experienced Contributor
Hi Honza,

thanks for the reply. I found something about event here

https://docs.microsoft.com/en-us/previous-versions/windows/d esktop/ee125084(v%3dvs.85)

but it's a mess that comes with no full working example to make it worse.
I'll continue to look for some good example online.

Luigi
Re: How to set a TimeCallback [message #50671 is a reply to message #50670] Sun, 02 December 2018 14:29 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1756
Registered: August 2008
Location: Czech Republic
Senior Contributor

Well, from that example it looks, like you need the SPF_ASYNC flag, which I found described here.

No Set/KillTimeCallback should be necessary for this. Just launch the Speak with the async flag in Start button callback and stop it by Stop button callback, which calls something like Speak("", SPF_PURGEBEFORESPEAK, NULL).

Best regards,
Honza

PS: Just guessing based on the docs, I haven't tried any of this. I actually didn't even touch any windows API for years Smile
Re: How to set a TimeCallback [message #50672 is a reply to message #50671] Sun, 02 December 2018 17:27 Go to previous message
forlano is currently offline  forlano
Messages: 1030
Registered: March 2006
Location: Italy
Experienced Contributor
It seems do not work.
However I found
https://github.com/roukaour/TTSApp
that is a full SAPI application with speak and stop feature.

index.php?t=getfile&id=5711&private=0

Now I am studying the code hoping to grab the right solution.
Thanks,
Luigi
Previous Topic: How to properly set a timer
Goto Forum:
  


Current Time: Thu Dec 13 05:43:40 CET 2018

Total time taken to generate the page: 0.00887 seconds