Android Question Voice Recognition and UDP

max123

Well-Known Member
Licensed User
Longtime User
Hi all,

in my project I have a working UDP socket that do some things.

Now I want use Voice Recognition, then send the result string over UDP socket, but for some strange reasons the
already initialized UDP socket is Null in the Voice Recognition _Result event.

The application will not crash here, the word is returned as expected, but in the log I see a 'red' error that packet cannot be sent because socket is Null.

When _Result is called, the app is paused, is this the problem ?
How I can solve it ?

Many thanks.

Here is my _Ready event sub:
B4X:
Sub VR_Result (success As Boolean, Texts As List)
      
    Log("VR Success: " & success)
          
    If success = True Then
        If Texts.Size > 1 Then
            Dim sb As StringBuilder
            sb.Initialize
            sb.Append("ACK").Append(CM).Append("VoiceRecognition").Append(CM)
            For i = 0 To Texts.Size -1
                Log (Texts.Get(i))
                sb.Append(Texts.Get(i))
                If i < Texts.Size Then sb.Append(CM)
            Next
            Log("Invio pacchetto StringBuilder VR: " & sb.ToString)
            SendPacket(sb.ToString)
        Else
            Log("Invio pacchetto VR: " & "ACK" & CM & "VoiceRecognition" & CM & Texts.Get(0))
      
          'SendPacket("ACK" & CM & "VoiceRecognition" & CM & Texts.Get(0))
      
            Log (Texts.Get(0))
            Dim data As String = "ACK" & CM & "VoiceRecognition" & CM & Texts.Get(0)
            Dim pkt As UDPPacket
            Dim buffer() As Byte = data.GetBytes("UTF8")
            pkt.Initialize(buffer, remoteIP, PortOut)  'DATA,HOST,PortOut   ' Inizializza il pacchetto in invio
                 
            udp.Send(pkt)
 
            Dim msgBack As String = BytesToString(buffer, 0, buffer.Length, "UTF8")
            Log("Successfully sent : " & remoteIP & ":" & PortOut & "  [" & msgBack & "]")
        End If
    Else
        Log("Cannot recognize voice")
        ToastMessageShow("Cannot recognize voice", True)
    End If

End Sub

and this is the log:
 
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
So has anyone ever had this problem ? You can help ?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…