Sub StartRecognizer()
TLogcolor("Step 2 ==== StartRecognizer ====",Colors.Blue)
TLogcolor("Listenstate was " & Starter.ListenState,ColorByName.Green_DarkGreen)
SpeechRecognizer.InitializeStatic("android.speech.SpeechRecognizer")
JO = SpeechRecognizer.RunMethod("createSpeechRecognizer",Array(JO.InitializeContext))
If Not(IsRecognitionAvailable) Then
TLog("Speech Recognition Not Available")
EText1.Text = "Speech Recognition Not Available"
Return
End If
'try to get list of languages here
'Maybe
Dim Language As String ="en-UK"
Try
Language=PM.GetString("Language")
Catch
TLog(LastException)
Language="en-UK"
End Try
Try
Starter.PreferOffline=PM.GetBoolean("PreferOffline")
Catch
TLog(LastException)
End Try
'UpdateOnlineStatus
TLogcolor("Recognition Language was " & Language,ColorByName.Blue_RoyalBlue)
RecognizerIntent.Initialize("android.speech.action.RECOGNIZE_SPEECH",Null)
RecognizerIntent.PutExtra("android.speech.extra.LANGUAGE_PREFERENCE",Language)
RecognizerIntent.PutExtra("calling_package",Application.PackageName)
RecognizerIntent.PutExtra("android.speech.extra.LANGUAGE_MODEL","free_form")
RecognizerIntent.PutExtra("android.speech.extra.PARTIAL_RESULTS",True)
RecognizerIntent.PutExtra("android.speech.extra.MAX_RESULTS",3) 'was 3
TLog("Working Offline ====> " & Starter.PreferOffline)
RecognizerIntent.PutExtra("android.speech.extra.PREFER_OFFLINE", Starter.PreferOffline)
' RecognizerIntent.PutExtra("android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS", 1000)
' RecognizerIntent.PutExtra("android.speech.extras.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS", 2000)
' RecognizerIntent.PutExtra("android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS", 1000 * 10)
TLogcolor(" Creating Starting intent",ColorByName.Yellow_DarkGoldenrod)
Dim Event As Object = JO.CreateEvent("android.speech.RecognitionListener","Received","")
JO.RunMethod("setRecognitionListener",Array(Event))
Initialized = True
If Starter.ListenState="Destroyed" Or Starter.ListenState="Cancelled" Then
StartListening
End If
Starter.ListenState="Init"
HiddenEdit.RequestFocus
'Starter.Message="Restart ===>" & Starter.Message
TLog(" ===== Start Recogniser complete =====")
TLog("Initialise SpeechRecognition: IsListening " & Starter.IsListening)
End Sub