Kevin Lozano Kevin Lozano - 1 year ago 90 Question

VB.NEt SpVoice / SAPI always first in action

Hello guys i want to get some help.. because my program "BINGO caller" the SAPI/SpVoice is always speaking first before displaying the value in my textbox. and other problem is while speaking the SAPI all buttons and commands are not functioning they become ok when the SAPI is done speaking and the number they speak is showing in texbox after the speak. please help me.. i want to my program is displaying the number while SAPI speak the value in my textbox. please help me. this is my code in displaying the Number and letter in textbox and this is the code in SAPI

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

nos = randomarray(index)
index = index + 1

If nos <= 15 And nos >= 1 Then
col = "B"
ElseIf nos <= 30 And nos >= 16 Then
col = "I"
ElseIf nos <= 45 And nos >= 31 Then
col = "N"
ElseIf nos <= 60 And nos >= 46 Then
col = "G"
ElseIf nos <= 75 And nos >= 61 Then
col = "O"
End If

lbl_no.Text = nos
lbl_let.Text = col

sVar = Mid(nos, 1, 1)
sVar2 = Mid(nos, 2)

CType(Me.Controls("lbl_" & nos.ToString), Label).BackColor = Color.Yellow

If index = randomarray.Count Then
btn_pause.Enabled = False

End If


txt_count.Text = index - 1

End Sub

This is the SAPI code

Sub voice()
Dim VObj As Object
VObj = CreateObject("SAPI.SpVoice")

With VObj
.Volume = 100
.Rate = -2
.Speak(col & " " & nos)
.Speak(col & " " & sVar & " " & sVar2)
End With
End Sub

This is my Screenshot of my program

Answer Source

instead of calling voice() on the ui thread just call it on a thread pool thread.

System.Threading.ThreadPool.QueueUserWorkItem(AddressOf voice)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download