Sub Class_Globals
Private JO As JavaObject
Private RecognizerIntent As Intent
Private Initialized As Boolean=False
End sub
'
'
Public Sub Initialize(Act As Activity, centrar As Int, CadStart As String, CadEnd As String, sIdioma As String )
Act.LoadLayout("VR")
SpeechRecognizer.InitializeStatic("android.speech.SpeechRecognizer")
JO = SpeechRecognizer.RunMethod("createSpeechRecognizer",Array(JO.InitializeContext))
If Not(IsRecognitionAvailable) Then
Log("Speech Recognition Not Available")
lbl_Error.Text = "Speech Recognition Not Available"
Return
End If
RecognizerIntent.Initialize("android.speech.action.ACTION_RECOGNIZE_SPEECH",Null)
RecognizerIntent.PutExtra("android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS", 1000)
RecognizerIntent.PutExtra("android.speech.extra.LANGUAGE", sIdioma)
RecognizerIntent.PutExtra("android.speech.extra.LANGUAGE_MODEL", sIdioma)
RecognizerIntent.PutExtra("android.speech.extra.LANGUAGE_PREFERENCE" , sIdioma)
RecognizerIntent.PutExtra("android.speech.RecognizerIntent.LANGUAGE_PREFERENCE", sIdioma)
RecognizerIntent.PutExtra("android.speech.RecognizerIntent.EXTRA_LANGUAGE", sIdioma)
RecognizerIntent.PutExtra("android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL", sIdioma)
RecognizerIntent.PutExtra("android.speech.RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE", sIdioma)
RecognizerIntent.PutExtra("android.speech.extra.MAX_RESULTS",1)
RecognizerIntent.PutExtra("android.speech.extra.PREFER_OFFLINE", True)
Dim Event As Object = JO.CreateEvent("android.speech.RecognitionListener","Received","")
JO.RunMethod("setRecognitionListener",Array(Event))
End Sub
'
'
Public Sub IsInitialized As Boolean
Return Initialized
End Sub
'
'
Public Sub IsRecognitionAvailable As Boolean
Dim JO1 As JavaObject
JO1.InitializeContext
Return JO.RunMethod("isRecognitionAvailable",Array(JO1))
End Sub
'
'
Public Sub StartListening
Log("Sub StartListening")
JO.RunMethod("startListening",Array(RecognizerIntent))
End Sub
'
'
Public Sub StopListening
Log("StopListening()")
JO.RunMethod("stopListening",Null)
End Sub
'
'
Public Sub Destroy
Log("Destroy()")
JO.RunMethod("destroy",Null)
End Sub
'
'
Private Sub Received_Event (MethodName As String, Args() As Object)
'Log("Received_Event=" & MethodName)
Select MethodName
Case "onBeginningOfSpeech"
Log("Received_Event=" & MethodName)
Case "onReadyForSpeech"
Log("Received_Event=" & MethodName)
Case "onError"
Log("Received_Event=" & MethodName)
Case "onEndOfSpeech"
Log("Received_Event=" & MethodName)
Case "onResults"
Log("Received_Event=" & MethodName)
Dim Results As JavaObject = Args(0) ' EL RESULTADO MAS PROBABLE VA AL ARRAY 0
Dim Matches As List = Results.RunMethod("getStringArrayList",Array("results_recognition"))
'Log(" Size=" & Matches.Size)
Dim Text As String = ""
For Each Result As String In Matches
Text = Result
Exit
Next
Log("R0=" & Text)
Case "onRmsChanged"
Log("Received_Event=" & MethodName & "=" & Args(0))
Case "onPartialResults"
Dim s As String
Dim Results As JavaObject = Args(0)
Dim Matches As List = Results.RunMethod("getStringArrayList",Array("results_recognition"))
s=Matches.Get(0)
Log ("PR=" & s)
Case Else
Log("*** Received_Event=" & MethodName)
End Select
End Sub
'
'
private Sub GetErrorText(ErrorCode As Int) As String
Select ErrorCode
Case SpeechRecognizer.GetField("ERROR_AUDIO")
Return " Audio Recording error"
Case SpeechRecognizer.GetField("ERROR_CLIENT")
Return " cse" ' " Client side error"
Case SpeechRecognizer.GetField("ERROR_INSUFFICIENT_PERMISSIONS")
Return " Insufficient permissions"
Case SpeechRecognizer.GetField("ERROR_NETWORK")
Return " Network error"
Case SpeechRecognizer.GetField("ERROR_NETWORK_TIMEOUT")
Return " Network timeout"
Case SpeechRecognizer.GetField("ERROR_NO_MATCH")
Return " No match"
Case SpeechRecognizer.GetField("ERROR_RECOGNIZER_BUSY")
Return " RecognitionService busy"
Case SpeechRecognizer.GetField("ERROR_SERVER")
Return " error from server"
Case SpeechRecognizer.GetField("ERROR_SPEECH_TIMEOUT")
Return " No speech input"
Case Else
Return "Didn't understand, please try again."
End Select
End Sub