B4A Library SpeechRecognitionNoUI - google speech recognition without popup

Brandsum

Well-Known Member
Licensed User
With this, you can add speech recognition feature to your application without google speech recognition popup (check attached example) like this,

demo.gif

SpeechRecognitionNoUI

Author:
@Brandsum
Version: 1.2
Dependency (Only if you use bas file): JavaObject, Phone
  • SpeechRecognitionNoUI
    • Events:
      • ReadyForSpeech
        Called when the endpointer is ready for the user to start speaking.
      • BeginningOfSpeech
        The user has started to speak.
      • EndOfSpeech
        The user has started to speak.
      • Error (Msg As String)
        The user has started to speak.
      • PartialResults (Texts As List)
        The user has started to speak.
      • Results (Texts As List)
        The user has started to speak.
      • RmsChanged (RmsValue As Int)
        The sound level in the audio stream has changed.
    • Functions:
      • NoRecognizerBeep As Boolean
        Set true if you don't want beep sound before and after speech recognition
      • Initialize (eventname As String, callback As Object) As Boolean
      • IsInitialized As Boolean
      • IsRecognitionAvailable As Boolean
        Check if Speech Recognition is available or not
      • StartListening (LANGUAGE As String, PARTIAL_RESULTS As Boolean, PREFER_OFFLINE As Boolean) As String
        Start listening.
        LANGUAGE : Recognition language. IETF language tag (as defined by BCP 47), for example "en-US"
        PARTIAL_RESULTS : indicate whether partial results should be returned by the recognizer as the user speaks.
        PREFER_OFFLINE : indicate whether to only use an offline speech recognition engine. If false then either network or offline recognition engines may be used
      • StopListening As String

Here is the original thread. I took some ideas and codes to build this library.

You can use either the bas file or the zipped jar file as you want. Add JavaObject and Phone library reference if you want to use the bas file.

Note: Remember to add RECORD_AUDIO permission.

Update 1.1: Added NoRecognizerBeep option. Set true if you don't want beep sound before and after speech recognition.
Update 1.2:
  1. Added ReadyForSpeech event.
  2. Fixed recognition language problem
 

Attachments

Last edited:

agraham

Expert
Licensed User
Many thanks for this. It seems to work well, apart from the fact that owing to American prudery while it recognises various profanities it returns them in sanitised form such as "s***" and "b*****" :( (Well I had to try didn't I) :)


I'm going to try to use it, with some text post processing, to enter lines of code in my on device Basic language IDE rather than enter code on the keyboard which can be quite laborious. Even with inevitably having to do some post-voice editing it could be faster - particularly on smaller devices.
 
Last edited:

Brandsum

Well-Known Member
Licensed User
Many thanks for this. It seems to work well, apart from the fact that owing to American prudery while it recognises various profanities it returns them in sanitised form such as "s***" and "b*****" :( (Well I had to try didn't I) :)
You can disable this.
  1. Open Google App
  2. Click on more option (bottom right corner)
  3. Click on Settings
  4. Click on voice
  5. Turn Hide offensive words off
Or
  1. Open phone settings app
  2. Go to google option
  3. Click on Search, Assistant & Voice
  4. Click on voice
  5. Turn Hide offensive words off
 

Brandsum

Well-Known Member
Licensed User
That's the sound level of the audio stream in dB unit. You can use this to show user voice input strength level.
 

leitor79

Active Member
Licensed User
Hi! Can the SR object be used within a service, or must it be within an activity?
Thank you very much!
 

agraham

Expert
Licensed User
The signature for the RmsChanged event in the XML is wrong. It should be float or double, not int. Declaring it as Int causes a runtime exception.
 

Brandsum

Well-Known Member
Licensed User
Because I think its easier to include a library rather than adding that class file to a project. Just like b4xlib.
I have mentioned the original thread. You can check that to know how it is working.

I have posted a few libraries as class file so that someone can modify if its not working as they want. But here I dont think any modifications is required. So I have posted as jar file. Also if you compile a module as library then users dont have to add dependencies along with the library as those will be compiled along with the class file.
 

agraham

Expert
Licensed User
But here I dont think any modifications is required.
Well, we have to disagree here. I see no point in posting a compiled class module instead of the source code. I wanted to play with the cancel() method but I now have to reverse engineer the source code to be able to do so.
 
Top