Sky7ure Sky7ure - 3 months ago 18
Vb.net Question

SAPI Execution Priority

I use (SAPI) object in my application. However, whenever I executes its function, the voice runs but the application's performance (everything else) gets paused until the voice finishes! I wonder if that has something to do with the priority of this Speaking-Object. Can I somehow lower it until the rest of the code executes first? o_O

Private Function Lara(ByVal script As String) As Object
Lara = CreateObject("SAPI.spvoice")
Lara.Voice = Lara.GetVoices.Item(1)
Return Lara.speak(script)
End Function

Private Sub Test_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Logo.Visible = True
Logo.Image = ResizeImage(My.Resources.Spell)
Lara("Welcome")
End Sub


Can (Lara) say "welcome" AFTER loading the form and its Logo?

Thank you.

Answer

If you take a look at MSDN's documentation SpVoice Speak method, it states that

"When synchronous speech is used in an application, the application's execution is blocked while the voice speaks, and the user is effectively locked out. This may be acceptable for simple applications, or those with no graphical user interface (GUI), but when sophisticated user interaction is intended, asynchronous speaking will generally be more appropriate."

So what you'll probably want to do is look into calling speak with the SVSFlagsAsync being set. As it is right now your execution is being blocked.

I'm thinking your code would look like:

Lara.speak(script, SpeechVoiceSpeakFlags.SVSFlagsAsync)