Android Tutorial Voice Recognition Example

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

Attachments

  • VoiceRecognition.zip
    5.6 KB · Views: 5,251

Chicao99

Member
Licensed User
Longtime User
I was testing this library and one time it returned a number in currency format (for example r$ 35,53), but it happened just one time, now it always returns the number extended (in portuguese is "trinta e cinco reais e cinquenta e três centavos", like (in english) "thirty five dolars and fifty three cents") , how can I choose it?
 

Danbicky

Member
Licensed User
Longtime User
This is brilliant, I now have version 5.20 and voice command control works flawless :)

Thanks Erel

Dans
 

JTKEK

Member
Licensed User
Longtime User
can the Voice recognition work on background means, the pop of voice recognition is not shown
it is possible ?
 

tsteward

Well-Known Member
Licensed User
Longtime User
The idea of voice recognition appeals to me for my app. On a certain Activity I woul like to press the listen button only once.
Then listen for a command word. After a short pause process what was heard then do nothing but wait for that command word again. On closing this activity or pressing the button again it would stop listening.

How might I do this or is this beyond this library?
 

PoleStar

Member
Licensed User
Longtime User
How can use VoiceRecognition1.Listen2 with intent?
What is the use of this option?
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Hi,

I have successfully tested the voice recognition example.
However from time to time I have an error and a promt message saying (from french to english) :
"I have not understood, please retry"

And to retry I must push on the microphone icon.

Is there a way to automatically retry wihtout the message box ?

I would like to have an "everlasting" voice listener with voice recognition without user touching the screen...

Thanks
 

freedom2000

Well-Known Member
Licensed User
Longtime User
thank you for this clear answer.

How do you get the EndOfSpeech or PartialResults events ?

In the given exemple there is only : VR_Result (Success As Boolean, Texts As List)
 
Last edited:

freedom2000

Well-Known Member
Licensed User
Longtime User
You can however make sourcecode involving re-calling SR.startlistening as soon as the results from the previous dialog have been received (i.e. after the EndOfSpeech or PartialResults events). However, this will still cause pauses of about 2 seconds during which no speech is recognized.
.

Hi again !

I tried to relaunch the "startlistening" and it works (with a little delay) but when I get the "I have not understood, please retry" window, I need to push again the "micro button"
Any way to trap this event by code ?
 

freedom2000

Well-Known Member
Licensed User
Longtime User
I recommend that you don't use the standard VR library but use the one by Vpires or Stevel05:
1: https://www.b4x.com/android/forum/threads/another-speechrecognizer-library.37584/#post-221995
2: https://www.b4x.com/android/forum/threads/android-speech-recognition-api-wrapper.62959/#content
3: https://www.b4x.com/android/forum/threads/chargeable-speechrecognizer-library.27409/
Number 3 (by XverhelstX) is chargable, but the maker is no longer active in this forum. Go for number 1!
The standard VR library (to my opinion) is somewhat outdated: it opens a new Window with a microphone, whereas the other three solutions can be better integrated into your project.

I tried "1" and it works great in fully auto mode

Thanks :)
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

have you experiences with conditions of using this voice recognition? As wrote "Syd Wright" - are here some parameters of free using of this function or we must pay something? 0-60 min free and 61-1000000minutes for 0,006 dolar per month and per 15 sec? If we use voice recognition in our app via B4A, we must pay or not?

Best regards
p4ppc
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
Syd Wright - thank you for your reply. I can´t find on the google web the date of beginning this paid service.
How long will be this service free. You have this onformations please? Because I thing that we can still use this B4A VR tutorial for free.

Its naturaly step form google and Bing to change from free to pay service, but I thing that 15 second is long interval. Some apps are using one or two words and the price for two words is very high.

Thank you an have a good day
p4ppc
 
Last edited:

petr4ppc

Well-Known Member
Licensed User
Longtime User
Hi Syd Wright,

Thank you very much for your links to web pages. I read them before and I know about it. I was not found the date of ending free use of voice recognition (for example this VR tutorial).
Its absolutely right what you wrote about continuous speech recognition and the prices.

I dont know too, who has to pay Google, if the user or developer/app seller. It looks, that comes the day and Google and Bing show us final results and show us the date of ending free services and starting the pay-services.

Thank you very much SYD
Best regards
p4ppc
 
Top