A large button is displayed. When the user presses on the button, the user is asked to say something.
The voice recognition engine converts the audio to text.
Then the text is converted back to speech using the TTS (text to speech) library:
VR is a VoiceRecognition object. We call its Listen method. This method launches the external voice recognition application. When the result is ready the Result event is raised.
We need to check the Success flag to make sure that there is at least one text available.
The Texts list holds all the possible results. We take the supposedly best one which is the first.
The program is attached.
The voice recognition engine converts the audio to text.
Then the text is converted back to speech using the TTS (text to speech) library:
B4X:
'Activity module
Sub Process_Globals
Dim VR As VoiceRecognition
Dim TTS1 As TTS
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
VR.Initialize("VR")
TTS1.Initialize("TTS1")
End If
Activity.LoadLayout("1")
If VR.IsSupported Then
ToastMessageShow("Voice recognition is supported.", False)
Else
ToastMessageShow("Voice recognition is not supported.", True)
End If
VR.Prompt = "Say your message"
End Sub
Sub Button1_Click
VR.Listen 'calls the voice recognition external activity. Result event will be raised.
End Sub
Sub VR_Result (Success As Boolean, Texts As List)
If Success = True Then
ToastMessageShow(Texts.Get(0), True)
TTS1.Speak(Texts.Get(0), True)
End If
End Sub
We need to check the Success flag to make sure that there is at least one text available.
The Texts list holds all the possible results. We take the supposedly best one which is the first.
The program is attached.