why this winform hangs and become unresponsive?

  • Thread starter Thread starter anuragtseven
  • Start date Start date
A

anuragtseven

Guest
I have this visual basic winform which converts speech to text. This winform has 1 button and one textbox and uses azure Speech to text service. When I click button , It converts speech to text and shows in textbox but the problem is, the winform starts hanging and i cant do anything else and not even able close the winform. Anyone know what is going wrong? Thanks in advance.

Form1.vb

Imports Microsoft.CognitiveServices.Speech
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SpeechContinuousRecognitionAsync().Wait()



End Sub

Public Async Function SpeechContinuousRecognitionAsync() As Task
Dim config = SpeechConfig.FromSubscription("api key", "westus")

Using recognizer = New SpeechRecognizer(config)

AddHandler recognizer.SessionStarted, AddressOf recognizer_sessionstarted
AddHandler recognizer.SessionStopped, AddressOf recognizer_sessionstopped
AddHandler recognizer.Recognizing, AddressOf recognizer_Recognizing
AddHandler recognizer.Recognized, AddressOf recognizer_Recognized
AddHandler recognizer.Canceled, AddressOf recognizer_Canceled
Await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(True)




End Using
End Function

Private Sub recognizer_sessionstarted(ByVal sender As Object, ByVal e As SessionEventArgs)
Console.WriteLine("\n Session started event.")


End Sub
Private Sub recognizer_sessionstopped(ByVal sender As Object, ByVal e As SessionEventArgs)
Console.WriteLine("\n Session stopped event.")


End Sub
Private Sub recognizer_Recognizing(ByVal sender As Object, ByVal e As SpeechRecognitionEventArgs)
Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}")


End Sub
Private Sub recognizer_Recognized(ByVal sender As Object, ByVal e As SpeechRecognitionEventArgs)
TextBox1.Text = e.Result.Text


End Sub
Private Sub recognizer_Canceled(ByVal sender As Object, ByVal e As SpeechRecognitionCanceledEventArgs)
Console.WriteLine($"\n Recognition Canceled. Reason: {e.Reason.ToString()}, CanceledReason: {e.Reason}")


End Sub

End Class

Continue reading...
 
Back
Top