Sample code
Unzip speech2TextLib.zip into extralibs folder & provide results reports, please.
Nelson Pires
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim sr As SpeechToText
Dim ri As RecognizerIntent
Dim i As Intent
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim EditText1 As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
EditText1.Initialize("")
EditText1.SingleLine=False
EditText1.Gravity=Gravity.TOP
Activity.AddView(EditText1,0,0,100%x,100%y)
sr.initialize("sr")
i.Initialize( ri.ACTION_VOICE_SEARCH_HANDS_FREE,"")
i.PutExtra(ri.EXTRA_CALLING_PACKAGE,"com.inforpires.testSpeech")
i.PutExtra(ri.EXTRA_LANGUAGE_MODEL, ri.LANGUAGE_MODEL_FREE_FORM)
'i.PutExtra(ri.EXTRA_LANGUAGE,"pt_PT")
i.PutExtra(ri.EXTRA_MAX_RESULTS,3)
i.PutExtra(ri.EXTRA_PARTIAL_RESULTS,True)
End Sub
Sub sr_onResults(results As Object)
Log(results)
Dim words As List
'Log(words)
words.Initialize2(results)
For Each word As String In words
Log(word)
EditText1.Text = EditText1.Text & word
Next
EditText1.Text = EditText1.Text & CRLF
sr.startListening(i)
End Sub
Sub sr_onError(erro As Int)
Log("ERROR : " & erro)
If erro=8 Then
sr.stopListening
sr.destroy
sr.createSpeechRecognizer
sr.startListening(i)
Else
sr.startListening(i)
End If
End Sub
Sub sr_onEndOfSpeech
Log("End of speech")
'sr.startListening(i)
End Sub
Sub sr_onRmsChanged(rmsdB As Float)
'Log("RMS" & rmsdB)
End Sub
Sub Activity_Resume
If sr.isRecognitionAvailable Then
sr.createSpeechRecognizer
sr.startListening(i)
Log("OK")
Else
Log("Not OK")
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
sr.destroy
End Sub
Unzip speech2TextLib.zip into extralibs folder & provide results reports, please.
Nelson Pires
Attachments
Last edited: