Joseph Fuller Joseph Fuller - 1 month ago 14
Vb.net Question

Text to speech portion of code (VB.NET) works fine on windows 7 but not on windows 10

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim SAPI As Object
Select Case TextBox1.Text
Case "1"
PictureBox1.Image = My.Resources.picture1
RichTextBox1.Text = "Information here."
SAPI = CreateObject("SAPI.spvoice")
SAPI.speak(RichTextBox1.Text)
End Select
End Sub
End Class


On two windows 7 machines the pictures and text appear first and then the TTS happens. While on two win10 machines the speech happens first and then the picture and text appear.

I've tried adding a try catch and finally statement and setting up a delay but the problem still persists!

Is there anything I can do to fix this?

Update for blackwood

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim SAPI As Object
Select Case TextBox1.Text
Case "1"
PictureBox1.Image = My.Resources.picture1
RichTextBox1.Text = "Information here."
System.Threading.Thread.Sleep(100)
SAPI = CreateObject("SAPI.spvoice")
SAPI.speak(RichTextBox1.Text)
End Select
End Sub
End Class

Answer

Maybe try sticking an Application.DoEvents in there just before the SAPI = CreateObject call. Though it's not the solution, it's the easiest to implement. It'll cause the window get updated (the message loop is handled) before continuing.

If that works, go for the real solution: a background thread or async/await (whenever possible) for the playback of the TTS.