B4A Library [Custom View] Speak Button

Erel

Administrator
Staff member
Licensed User
This class implements a "speak button":



It makes it very simple to add a speak button to an EditText.

You should add the button with the designer. Add a CustomView and set its type to SpeakButton.

In your code you should set the SpeakButton TargetEditText to the relevant EditText.

The code in the above example:
B4X:
Sub Globals
   Dim EditText1 As EditText
   Dim EditText2 As EditText
   Dim Speak1 As SpeakButton
   Dim Speak2 As SpeakButton
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   Speak1.TargetEditText = EditText1
   Speak2.TargetEditText = EditText2
End Sub
This class depends on the Phone library and Reflection library.
 

Attachments

Theera

Well-Known Member
Licensed User
I'm not understand

Hi Erel,
B4X:
Private Sub LoadResourceDrawable(id As Int) As Object
   Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod("getResources")
   Return r.RunMethod2("getDrawable", id, "java.lang.int")
End Sub
Why do you assigned r.Target again and again?
 

GMan

Well-Known Member
Licensed User
Cool Tool 4 @ nice device :sign0098:
 

Theera

Well-Known Member
Licensed User
First it references the Context object and then after the call to getResources it references the Resources object.
Hi Erel again,
1.) assigned twice ,information of r.Target is changed,isn't it?
2.) Could I split coding ?
B4X:
Private Sub GetResources As Object
    Dim r As Reflector
    Return r.RunMethod("getResources")
End Sub
Private Sub GetDrawable(id As Int) As Object
    Dim r As Reflector
    Return r.RunMethod2("getDrawable", id, "java.lang.int")
End Sub
 
Last edited:

brelto85

Active Member
Licensed User
don't works with B4A 2.52

Parsing code. 0.00
Compiling code. Error
Error compiling program.
Error description: Unknown member: targetedittext
Occurred on line: 30
Speak1.TargetEditText = EditText1
Word: targetedittext

If i run the Designer returns this error

"could not load type "Dbasic.designer.MetaCustomView" from the assembly Basic4Android, version 2.5.0.0 .."

Phone library 2.01
 

Theera

Well-Known Member
Licensed User
Hi brelto85,
Only version 2.70 and 2.71 could use the custom views. I recommend you using v.2.71.
 

Mahares

Well Known Member
Licensed User
I set one of the edittext box to have decimals as input type. How can I get the vr to recognize the point in decimal like 67.8. Not only it allowed entry of alpha characters, but also added a space like this 67. 8 (a space after the period. Sometimes I sneak one by it and it works, but most of the time it is inconsistent with decimals. Does anyone have a trick to make it consistent with the decimal point and to prevent letters in only numeric text boxes.
Thank you
 

Mahares

Well Known Member
Licensed User
@Erel: I modified the below class sub to make it accept only NUMBERS, but the problem becomes this: All edittext boxes must have numbers which is not what I want for each edittext box. Do you have an idea how to change it where some edittext boxes accept only numbers and others accept text. Please make a concerted effort to make this class worthwhile.

B4X:
Private Sub vr_Result (Success As Boolean, Texts As List)
   If Success AND Texts.Size > 0 Then
      et.Text = Texts.Get(0)      
      If IsNumber(et.Text)=False Then ' 6/15/13
           et.Text=""
           ToastMessageShow("No letters",False)
      End If
   End If
End Sub
 

Mahares

Well Known Member
Licensed User
You should modify the class and add an "only numbers" flag. This way you will be able to decide for each button whether to allow numbers only or not.
How do you exactly do that. I have been struggling with it for two days now.
I use this code, but it allows letters in a numeric field textbox, unless I start the entry with a digit:
B4X:
Private Sub vr_Result (Success As Boolean, Texts As List)
   If Success AND Texts.Size > 0 Then
     Dim MyEntry As String
      MyEntry=Texts.Get(0)
      If IsNumber(MyEntry.SubString2(0,1)) Then       
            MyEntry=MyEntry.Replace(" ","")
            If IsNumber(MyEntry)=False Then
                   MyEntry=""
                 ToastMessageShow("No letters",False)
            End If      
      End If
      et.Text = MyEntry
   End If
End Sub
 

Mahares

Well Known Member
Licensed User
How To Configure Voice Recognition

Is there a way to configure voice recognition where you can simply pronounce the letters of the alphabet rather than explicitly pronounce a full word. For example: I like to say A then B then L then E in succession instead of pronouncing the entire word ABLE.
Thank you for opening a new world.
 

brelto85

Active Member
Licensed User
what is the difference between this CustomView and use a standard button that starts the voice recognition and put the result in a EditText?
 
Top