B4A Library [Chargeable] SpeechRecognizer Library

SpeechRecognizer




I have received a lot of requests lately for my SpeechRecognizer library.
This is why I made a separate topic for SpeechRecognizer.
With SpeechRecognizer, you'll be able to recognize text from a service! No popups or anything else!

A2ae6l.png


Requirements:
- Android 2.1+ (API 8)



What will you get from me:
- The library files
- A sample project
- A readme file. (Disclaimer.)


Payment

The price of the library is 15 Euros.
Payment is done through PayPal.
If you are interested in the library, you can send me a private message here on the forums or send me an email to rootsoftllc@gmail.com.

Sample

You can find a sample here written by NJDude:
http://www.basic4ppc.com/forum/andr...eelance-library-development-6.html#post134332


Special thanks and credits goes to NJDude for the sample.

Kind regards,
Tomas
 
Last edited:

mcmanu

Active Member
Licensed User
Ah okay, i thought the startlistening event is fireing again automatically in hands free mode, Thanks you :)
Yes i will try the awesome Work around ;)
 

Rick Harris

Well-Known Member
Licensed User
Mhh Dont work for me at all :(
Listens once and then nothing happens.
I dont have a Stoplistening in my code.
I dont know what the problem is
Here is a simple test project
http://www.file-upload.net/download-8587192/TestRecognizer.rar.html
Use the smallest download button ;)


Maybe somebody can help me
Don't grumble! Your sourcecode had a number of issues. I modified your code (substantially) and now it is working.
Here is the main module:
B4X:
#Region Module Attributes
    #FullScreen: true
    #IncludeTitle: false
    #ApplicationLabel: SpeechRecognizerTest
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region
 
'Activity module
Sub Process_Globals
    Dim tts1 As TTS
    Dim MicAuto1 As Int
End Sub
 
Sub Globals
    Dim String1 As String
    Dim Button1 As Button
    Dim Ticks1 As Long
    Dim Ticks2 As Long
    Dim TTSklaar1 As Int
    Dim VULevel1 As Double
End Sub
 
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("testRegLayout")
    Button1.Enabled = False
    TTSklaar1 = 0
    tts1.Initialize("tts1")
    tts1.SetLanguage("de","DE")
    If FirstTime = True Then        'My experience has show that it is necessary to check whether TTS1 has initialised succesfully and is ready to speak!
      Ticks1 = DateTime.Now
      Do While TTSklaar1 = 0
        Ticks2 = DateTime.Now
        If Ticks2>Ticks1+3000 Then Exit
        DoEvents
      Loop
      tts1.Speak("Gutentag, Wie gehts Ihnen",True)
    End If
 
    MicAuto1 = 1
    StartService(RecognizerService)
    Button1.Enabled = True
End Sub
 
Sub Activity_Resume
End Sub
 
Sub Activity_Pause (UserClosed As Boolean)
End Sub
 
Sub ShowWords(Words As List)
    String1=Words.Get(0)
    String1=String1.ToLowerCase
 
    If String1.Contains("hallo") Then  'Simple test, not nice but for test okay
      CallSub(RecognizerService, "StopListening")  'Do not continue listening while TTS1 is speaking!
      tts1.Speak("hallo, schön dich kennenzulernen",True)
      DoEvents
    Else
      ToastMessageShow(String1,False)
    End If
    DoEvents
    If MicAuto1 = 1 Then GOOGLE_SILENT1
End Sub
 
Sub TTS1_Ready (Success As Boolean)
    If Success Then
      'Enable all views
      TTSklaar1 = 1
      For I = 0 To Activity.NumberOfViews - 1
        Activity.GetView(I).Enabled = True
      Next
    Else
      ToastMessageShow("Error initializing TTS engine.", True)
    End If
End Sub
 
Sub Button1_Click            'Press this button to start the handsfree mode (calling it from Activity_Create apparently gives problems)
    CallSub(RecognizerService, "StartListening")
End Sub
 
Sub ShowError(Error1 As Int)  'Code from the forum (Rick Harris) to test it
    If Error1 = 6 OR Error1 = 7 Then
      GOOGLE_SILENT1
    End If
    If Error1=8 Then
      'Bad situation!
    End If
End Sub
 
Sub GOOGLE_SILENT1
      Dim Volu1 As Int
    Dim Wticks1 As Long
    Dim Wticks2 As Long
    Dim p As Phone              'Suppress Google Voice Beep
    Volu1 = p.GetVolume(p.VOLUME_MUSIC)
    p.SetVolume(p.VOLUME_MUSIC, 0, False)
    Try
      CallSub(RecognizerService, "StartListening")    'Try Catch is needed to avoid Starting the recognizer more than once which will cause Error 8!
    Catch
      ToastMessageShow("Recognizer is busy, or other error",False)
    End Try
    Wticks1 = DateTime.Now
    Wticks2 = 0
    Do While Wticks2 < (Wticks1+800)
      Wticks2 = DateTime.Now
      DoEvents
    Loop
    p.SetVolume(p.VOLUME_MUSIC, Volu1, False)
End Sub
 
Sub ShowVU(rms As Float)
    VULevel1 = rms         'You can elaborate this sub further to make your own VU meter (Audio speech level indicator)
End Sub                    'For example use a progressbar or modify the width of a lable. RMS values are between 0 and 10

And here is the contents of the SpeechRecognizer BAS module:
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.
 
    'Declares the SpeechRecognizer; You should be able to call this in the activity too.
    Dim sr As SpeechRecognizer
    Dim obj As Object
End Sub
 
Sub Service_Create
    'Initializing the speech recogniter. We are using a default intent.
    'You can create your own intent with the desired parameters from :
    'http://developer.android.com/reference/android/speech/RecognizerIntent.html
    sr.Initialize("SpeechRecognition")
    obj = sr.CreateRecognizerIntent(sr.LANGUAGE_MODEL_FREE_FORM, "voice.recognition.test", 5)
    If sr.isRecognitionAvailable = True  Then ToastMessageShow("Spraakherkenning is beschikbaar! ", False)
    If sr.isRecognitionAvailable = False Then ToastMessageShow("Spraakherkenning is NIET beschikbaar! ", False)
End Sub
 
Sub Service_Start (StartingIntent As Intent)
End Sub
 
Sub Service_Destroy
End Sub
 
Sub StartListening            'Door mij aangepast n.a.v. mailtje Tomas Verhelst
    Dim i As Intent
    'Initialize intent door middel van constants van de api
    'http://developer.android.com/reference/android/speech/RecognizerIntent.html
 
    If Main.MicAuto1 = 0 Then i.Initialize("android.speech.action.RECOGNIZE_SPEECH", "")
    If Main.MicAuto1 = 1 Then i.Initialize("android.speech.action.VOICE_SEARCH_HANDS_FREE", "")  'In plaats van ...action.RECOGNIZE_SPEECH  !!
    i.PutExtra("android.speech.extra.LANGUAGE_MODEL", "free_form")
    i.PutExtra("calling_package", "your package name")
    ' i.PutExtra("android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS",500)  'Heb ik toegevoegd
    i.PutExtra("android.speech.extra.MAX_RESULTS", 5)
    i.PutExtra("android.speech.extra.LANGUAGE", "de")     'You need to set the correct language here
    sr.StartListening(sr.CreateRecognizeIntent2(i))
End Sub
 
Sub StopListening
    If Main.MicAuto1=1 Then Return
    sr.StopListening
    Log("----- Stopped -----")
End Sub
 
'Beginning of the speech.
Sub SpeechRecognition_ReadyForSpeech
    Log("Ready for Speech")
    'ToastMessageShow("Zeg iets alsjeblief", False)
End Sub
 
'Beginning of the speech.
Sub SpeechRecognition_BeginningOfSpeech
    Log("Spraak begin")
End Sub
 
'End of the speech.
Sub SpeechRecognition_EndOfSpeech
    Log("End of Speech")
    'ToastMessageShow("Gereed!", False)
End Sub
 
'Buffer received
Sub SpeechRecognition_BufferReceived (buffer() As Byte)
    Log("Buffer received")
End Sub
 
'An error has occured.
Sub SpeechRecognition_Error (ErrorType As Int)
    Log("Error: " & ErrorType)
    CallSub2(Main, "ShowError", ErrorType)    'Dit heb ik toegevoegd!
End Sub
 
'An event has been done
Sub SpeechRecognition_Event (EventType As Int)
    Log("Event: " & EventType)
End Sub
 
'PartialResults arrived
Sub SpeechRecognition_PartialResults
    Log("PartialResults arrived")
End Sub
 
'The Results has arrived.
Sub SpeechRecognition_Results (Words As List)
    Log("RESULTS: " & Words)
    CallSub2(Main, "ShowWords", Words)
End Sub
 
'Rms has changed
Sub SpeechRecognition_RmsChanged (rms As Float)
    Log("RMS: " & rms)
    CallSub2(Main, "ShowVU", rms)    'Dit heb ik toegevoegd!
End Sub

It is working OK. I did however get frequent Error=8 which stops voice recognition entirely. I don't know what causes it, other than the possibility that the voice recognition stays busy after being called from more than one source.

Please take a look at this Youtube video that shows my latest (Dutch) app for blind and visually impaired users on a hyper-modern smart watch: This "ARTI" software has over 1200 functions and has been made entirely with B4A (30,000 lines of code). This week I have added a handsfree mode using parts of the above source code.
 
Last edited:

mcmanu

Active Member
Licensed User
Woah you´re Awesome Thank you very much ;) sorry for beeing so stupid haha ;)
Thats fantastic :)
your Application is very nice, especialy for blind people :)
 

brelto85

Active Member
Licensed User
Hi, using the VOICE_SEARCH_HANDS_FREE intent the AGC problem audio was solved but i've yet a little bug
I monitored all events (incluse errors) of SpeechRecognizer object, and in some cases collapses the recognition without any error (captured in SpeechRecognition_Error event)
Practically sometimes goes wrong after recognition (SpeechRecognition_EndOfSpeech event) and sometimes goes wrong after StartListening method

There a way to trace it?
 

Rick Harris

Well-Known Member
Licensed User
Hi, using the VOICE_SEARCH_HANDS_FREE intent the AGC problem audio was solved but i've yet a little bug
I monitored all events (incluse errors) of SpeechRecognizer object, and in some cases collapses the recognition without any error (captured in SpeechRecognition_Error event)
Practically sometimes goes wrong after recognition (SpeechRecognition_EndOfSpeech event) and sometimes goes wrong after StartListening method

There a way to trace it?
I have not witnessed this problem so far. Have you tried my code in thread #62?
Errors do occur, in particular 6 and 7. They are explainable an interceptable. However error 8 can be nasty because it halts the speechrecognition.
Pity Tomas (XVerhelstX) has been totally silent on all these issues during the past two weeks. He sells his library, but that's it... It is impossible for me to get any idea of which problems (like yours) might be caused by his library.
I don't even understand what this library does at all because most sourcecode in the speechrecognizer bas module directly interacts with the Google Voice API on the basis of intents. The main purpose of his library seems to be to intercept the events, so my bet is that your problem might be caused by Tomas's library.
 
Last edited:

Rick Harris

Well-Known Member
Licensed User
Hi, using the VOICE_SEARCH_HANDS_FREE intent the AGC problem audio was solved but i've yet a little bug
I monitored all events (incluse errors) of SpeechRecognizer object, and in some cases collapses the recognition without any error (captured in SpeechRecognition_Error event)
Practically sometimes goes wrong after recognition (SpeechRecognition_EndOfSpeech event) and sometimes goes wrong after StartListening method

There a way to trace it?
Today I found a new speech recognizer library by "vpires" in the forum:
http://www.basic4ppc.com/android/forum/attachments/speech2textlib-zip.22511/
I tried it a moment ago and it works very well. I recommend adding my code from thread #57 to suppress the repetitive Google Voice "beep" and you have a perfect solution (simpler and just as good as XVerhelstX library, free of charge as well).
 

grafsoft

Well-Known Member
Licensed User
Hi,
I am not sure that I understood everything properly.
What I need is either
- voice recognition from a file or
- voice recognition, and saving the spoken text to a WAV or whatever.
The reason is - and I think that others might need this too - the user talks, the text and the sound are upload3ed to a server. If the text is good, OK. If not, you can still listen to the voice.
Can this be done?
Thanks
Peter
 

Rick Harris

Well-Known Member
Licensed User
Hi,
I am not sure that I understood everything properly.
What I need is either
- voice recognition from a file or
- voice recognition, and saving the spoken text to a WAV or whatever.
The reason is - and I think that others might need this too - the user talks, the text and the sound are upload3ed to a server. If the text is good, OK. If not, you can still listen to the voice.
Can this be done?
Thanks
Peter
Hello Peter. I'm not sure what you are trying to do. The user will know what he or she has spoken. Playing back what was spoken seems a bit useless. The user will be far more interested in what the speech recognizer has understood. In Tomas Verhelst's library, as well as the new library mentioned above, the speech recognizer provides multiple results (5 or more) to choose from.
Regrettably it does not seem possible to use Google Voice and at the same time record what is being spoken to a WAV file. The microphone can only be connected to one object at a time.
Speech recognition from a pre-recorded wave file also does not seem possible because linking the loudspeaker output to the microphone input is prohibited in Android. Many people have tried to make an answering machine this way but nobody (I know off) has succeeded.
 

brelto85

Active Member
Licensed User
The SpeechToText library works well but i've notice that return always a result although the MAX_RESULTS extra was set to 5
 

grafsoft

Well-Known Member
Licensed User
Hello Peter. I'm not sure what you are trying to do. The user will know what he or she has spoken. Playing back what was spoken seems a bit useless. The user will be far more interested in what the speech recognizer has understood. In Tomas Verhelst's library, as well as the new library mentioned above, the speech recognizer provides multiple results (5 or more) to choose from.
Regrettably it does not seem possible to use Google Voice and at the same time record what is being spoken to a WAV file. The microphone can only be connected to one object at a time.
Speech recognition from a pre-recorded wave file also does not seem possible because linking the loudspeaker output to the microphone input is prohibited in Android. Many people have tried to make an answering machine this way but nobody (I know off) has succeeded.

Thank you! You saved me a lot of research time!
 

M. Giray Ozkan

Member
Licensed User
Hello,

How can I buy that library? I sent a private message to XverhelstX from this forum but I can't get any answer.
 

grafsoft

Well-Known Member
Licensed User
In my case it took him 2-3 days to answer. I think he will answer, but you might need a little patience.
 

Rick Harris

Well-Known Member
Licensed User
Hello,

How can I buy that library? I sent a private message to XverhelstX from this forum but I can't get any answer.
Did you ever get an answer from Tomas? It seems he has vanished entirely. Various e-mails that I sent him asking for help were never answered. My opinion is that chargeable source code that no longer is supported by their maker should be removed from this Forum because it only leads to frustration that you, I and others have experienced.
Asking money for sourcecode implies that it includes some support, at least that is my opinion.
 

grafsoft

Well-Known Member
Licensed User
I got an answer in March, but I think I am one of the lucky ones. Maybe someone else can answer your question?
 

Rusty

Well-Known Member
Licensed User
Rick,
to address your question in post 70, here is my opinion: I have the same need to: record the audio to a file WHILE transcribing to text. the purpose of this is so that the text, if for any reason is incorrect, the audio and the text can be heard/viewed simultaneously by the receiving party. I currently record and transcribe; send both results to my customer via the internet; they can see the text and validate it (if necessary) by listening to the audio.
HOWEVER, this capability was removed from the Android OS after Ice Cream Sandwich.
If you know of a way to accomplish this in Kit Kat or ??? (post ICS), I would very much like to know how!
Your input on this will be greatly appreciated.
Thanks,
Rusty
 

grafsoft

Well-Known Member
Licensed User
This is also my problem. I am currently working on the following solution: A .3gpp-file is recorded, uploaded to my server, converted into .wav, then set to AT&T for conversion into text. If anybody has a simpler solution I would like to hear it :) If anybody wants to hear my experiences, I am willing to tell.
Peter
 

Rusty

Well-Known Member
Licensed User
Peter,
I would be very interested in hearing how you are using AT&T for this...
Thanks,
Rusty
 
Top