A few questions about VoiceRecognition...

nachoap10

Member
Licensed User
Longtime User
Hi again!

I've been doing a few experiments with this function. I would like to duplicate all my app interface in order it works with voice. This way, it would be possible to put a book filter or a book sort order without writing anything.

But at the moment I have two problems:

a) I want TTS says a message and, afterwards, VR activates voice recording, in order to capture the human answer, but I haven't found a way to detect a TTS "Speak" command has finished. If I put somethig like this:

B4X:
TTS1.Speak("Please, tell me witch field do you want to use for filtering", True)
VR.Listen

VR starts before Speak finishes, so VR detects what Speak is saying, and takes it as part of human response.

Is there a way to know when Speak finishes?

b) I would like VR were "listening" what humans are saying without showing the VR recognition screen, in order to do the process a little cleaner. Is it possible to hide the VR screen? (in my tablet, it's a microphone with the word "google" down it)

Thank you in advance.

If I add this option to my lipapa app, I promise to translate my source and variables comments to english and put the complete and final code again (two months ago, I put the 1.0.6 version source, but the app version is actually 1.0.22). Well, I promise to translate the code, but I can't promise it would be written in a "perfect english" :sign0137:
 

nachoap10

Member
Licensed User
Longtime User
Well, I've got my service working but I have a new problem: how can I pass a variable to this service.

I have created a bFinished variable in order to tell my Timer that Speak has finished, and I've tried to change his value from the service, and it compiles, it changes, but only in the service, in the app it remains to false.

This is my trial code:

App:

B4X:
'Activity module
Sub Process_Globals
   Dim VR As VoiceRecognition
   Dim TTS1 As TTS
   Dim Timer1 As Timer
   Dim Telling As String
   Dim bFinished As Boolean
End Sub

Sub Globals

End Sub


Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      StartService(S1)
      VR.Initialize("VR")
      TTS1.Initialize("TTS1")
      
      ' We will work with Timer1 in order to know when Speak finishes
      Timer1.Initialize("Timer1", 500)
      Timer1.Enabled = False
   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 = ""
   
   'Initializes human response
   Telling = ""
End Sub

Sub Timer1_Tick
   ' Deactivates Timer if Speak has finished
   If bFinished Then
      Timer1.Enabled = False
      VR.Listen 'calls the voice recognition external activity
   End If
End Sub

' Speaks message and activates Timer1 to wait speak finishes
Sub Tell(Message As String)
   bFinished = False
   Timer1.Enabled = True
   TTS1.Speak(Message, True)
End Sub

Sub Button1_Click
   
   Tell("Por favor, indica el campo que quieres usar para el filtro")
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

Service:

B4X:
'Service module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim PE As PhoneEvents
End Sub
Sub Service_Create
   PE.Initialize("PE")
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_Destroy

End Sub

Sub PE_TextToSpeechFinish (Intent As Intent)
    bFinished = True
End Sub

I supposed I couldn't call bFinished from service, but it compiles well. But, when the Timer1.Tick is executed bFinished is always "false".

How could I call this variable from Service code?

Thank you again for your time
 
Upvote 0

nachoap10

Member
Licensed User
Longtime User
You should change it to:
B4X:
Main.bFinished = True
You can also use CallSub to call a sub in the activity.

:sign0060::sign0060::sign0060::sign0060::sign0060::sign0060:

Now it works perfectly!!!!

Thank you very very much!
 
Upvote 0
Top