I am using MS SAPI (5.1 or 5.3) to read a script using a call like this (in MS VC++):

Voice -> Speak(script.AllocSysString(), SPF_DEFAULT, NULL);

I want to be able to limit the total duration of the time spent reading the text to length X (hard limit). Is there a way to do that? I could put a character limit on the script string, but that's unreliable at best. I want to tell it to speak the script string and, if it's shorter than time X it will stop when done reading and continue execution, if it's longer than time X it will stop after reading time X worth of the script and continue execution.

Possible?

Recommended Answers

All 2 Replies

You can call ISpVoice::Speak asynchronously and then use the ISpVoice::WaitUntilDone method, which does exactly what you want.

pVoice->Speak( szText, SPF_ASYNC, NULL );
pVoice->WaitUntilDone( 3000 ); // 3 seconds
commented: Awesome! Thanks so much! Exactly what I needed. +1

Thanks, gashtio! That works perfectly in a little test program I whipped up, so it should do just what I need to do in my "real" program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.