I need help with VoiceRecognition

marbellapc

Member
Licensed User
Longtime User
Good morning, I commented, I have the TTS VoiceRecognition and running in the application, and it works perfectly, the problem is that I have two days reading the forum up and down and not find what I'm looking for, I explain a little better.

Need information or a basic example of how to do the following:
I have a phone number that is home, tucked into the application itself and what I want is that when you press the voice button and say home, check this and if this, click on the number to dial home.

example:
Speak > I say "home" > check > and check the house number on the dial

Not if possible, or if it is very difficult to do, but is that even though I read the forum, I get more questions and I do not see an example where saying something that makes a predefined function.

Again sorry for my English (Google Translate) and thank you very much in advance.
 

Ricky D

Well-Known Member
Licensed User
Longtime User
Do a search on Voice recognition and click on the one titled

B4X:
Voice Recognition

Then look for the one titled
B4X:
Voice Recognition Example
and the author is the king of b4a Erel.

I have downloaded this example and it works perfectly on my Samsung Galaxy s2 running android 4.0.3

The example is very simple.

If you have trouble understanding what's going on then ask away.

I hope this helps.

regards, Ricky
 
Upvote 0

marbellapc

Member
Licensed User
Longtime User
Thanks Ricky D, I already had looked but in the example of Erel, repeats what you say and show a ToastMessageShow not see it anywhere and if you check this, make an action, not maybe I am very clumsy, but as I say I've read the forum and I see nothing.

Thank you again.
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
this sub is where you find out what was spoken :

B4X:
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

The word(s) are in Texts.Get(0)

If you do something like this

B4X:
If Texts.Get(0)="home" Then   'Do something related to that word
End If

'or try this if you have multiples
Select Texts.Get(0)
  Case "home"
      'insert call home code here
  Case "office"
      'insert call office code here
  Case "beach"
      'insert code to call the beach house
  Case Else
    TTS1.Speak("I am sorry but that isn't a valid response", True)
End Select

regards, Ricky
 
Last edited:
Upvote 0

marbellapc

Member
Licensed User
Longtime User
Ricky D thank you very much, it's perfect.

It works great, the truth if not for people like you, the more new would cost us an eternity to learn ...

A greeting and thank you very much again
 
Upvote 0

marbellapc

Member
Licensed User
Longtime User
Sorry again for being here, but I have not been a problem and how to fix it.

I tell you that Ricky D after I put the code for recognition, which actually works perfectly:
B4X:
If Success = True Then
      ToastMessageShow(Texts.Get(0), True)
      TTS2.Speak(Texts.Get(0), True)
   End If
Last night, when I was testing, I noticed that when I activate the voice recognition, if I jump cancel an error:

An error has occurred in sub: main_vr_result (java line: 1286) java.lang.RuntimeException: Object should first be initialized (list)

I initialize the list:
B4X:
Sub VR_Result (Success As Boolean, Texts As List)
    Texts.Initialize
If Success = True Then
      ToastMessageShow(Texts.Get(0), True)
      TTS2.Speak(Texts.Get(0), True)
   End If

If Texts.Get(0) = "help" Then
   Activity.LoadLayout("help")
      ToastMessageShow(Texts.Get(0), True)
      TTS2.Speak(Texts.Get(0), True)
   End If
End Sub

I tried again stating:
B4X:
Sub VR_Result (Success As Boolean, Texts As List)
    Texts As List
    Texts.Initialize
If Success = True Then
      ToastMessageShow(Texts.Get(0), True)
      TTS2.Speak(Texts.Get(0), True)
   End If

If Texts.Get(0) = "help" Then
   Activity.LoadLayout("help")
      ToastMessageShow(Texts.Get(0), True)
      TTS2.Speak(Texts.Get(0), True)
   End If
End Sub

Without positive, always get the error, it has to do with:
B4X:
If Texts.Get(0) = "help" Then  
' By changing "True" to "help" it stops working when the Cancel button and displays the error.
   Activity.LoadLayout("help")
      ToastMessageShow(Texts.Get(0), True)
      TTS2.Speak(Texts.Get(0), True)
   End If
It takes the original, but for voice commands, and it does not take him when the error occurs, anyone know how to fix it, I saw that the forum has some users also happens:

http://www.b4x.com/forum/basic4android-updates-questions/19587-vr_result-crash.html

http://www.b4x.com/forum/basic4andr...227-object-should-first-initialized-list.html

But I'm not clear if it was sorted and how.
Again thanks in advance, greetings
 
Upvote 0

marbellapc

Member
Licensed User
Longtime User
Ok, I have it fixed, I have rewritten the code and I have added a couple of lines, and no longer breaks.
B4X:
Dim Info0 As Label
      Info0.Initialize("Info0.Text")
      Info0.Text = "help"
If Success = True Then
      Info0.Text = Texts.Get(0)
      ToastMessageShow(Texts.Get(0), True)
      TTS2.Speak(Texts.Get(0), True)
      Activity.LoadLayout("help")
End If
I leave it in case someone else had better example.

Regards
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
There is no need to re-initialize the list Texts - that will cause all sorts of grief for you.

regards, Ricky
 
Upvote 0

marbellapc

Member
Licensed User
Longtime User
Hello, because if you're right Ricky D, I was doing everything wrong.

In the end it was easier than I thought, all I've done is add:
B4X:
If Success = False Then Return
So that if the value is false, I return to the application, now no longer breaks when you press cancel.

Regards
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
Better results from recognition

Hi,

i have read your problems and i think you did not see all the possibilities from VR:

My List Name is Texts. You can look with Texts.Size, how many different words the VR can give back to you. In most cases you get 2 to 10 different words, you should step trough this words and compare them with your wanted word

For i=0 To Texts.Size-1
log(Texts.Get(i))
next

I hope it helps; Greetings from austria
Reinhard
 
Upvote 0
Top