B4A Library SpeechRecognitionNoUI - google speech recognition without popup

Discussion in 'Additional libraries, classes and official updates' started by Brandsum, Aug 13, 2019 at 10:01 PM.

  1. Brandsum

    Brandsum Active Member Licensed User

    With this, you can add speech recognition feature to your application without google speech recognition popup (check attached example) like this,



    Author: @Brandsum
    Version: 1.10
    Dependency (Only if you use bas file): JavaObject, Phone
    • SpeechRecognitionNoUI
      • Events:
        • BeginningOfSpeech
        • EndOfSpeech
        • Error (Msg As String)
        • PartialResults (Texts As List)
        • Results (Texts As List)
        • RmsChanged (RmsValue As Int)
      • 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, ONLY_RETURN_LANGUAGE_PREFERENCE As Boolean, PARTIAL_RESULTS As Boolean, PREFER_OFFLINE As Boolean) As String
          Start listening.
          LANGUAGE : Recognition language preference
          ONLY_RETURN_LANGUAGE_PREFERENCE : indicate whether only the current language preference is needed in the response. This avoids any additional computation if all you need is current language preference in the response.
          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

    is the original thread. I took some idea 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.10: Added NoRecognizerBeep option. Set true if you don't want beep sound before and after speech recognition.

    Attached Files:

    Last edited: Aug 15, 2019 at 4:15 PM
    iz0ndg, peacemaker, Mashiane and 18 others like this.
  2. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    Great job friend ...
    It is super fast and also works without internet.:)
  3. agraham

    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: Aug 14, 2019 at 6:59 PM
    Mashiane likes this.
  4. Brandsum

    Brandsum Active Member Licensed User

    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
    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
  5. agraham

    agraham Expert Licensed User

    Yay! :)

    What is RmsValue in the RMSChanged event - some sort of signal to noise measurement?
  6. Brandsum

    Brandsum Active 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.
  7. leitor79

    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!
  8. Brandsum

    Brandsum Active Member Licensed User

    Yes you can use this within service.
    Harris likes this.
  9. agraham

    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 likes this.
  10. Brandsum

    Brandsum Active Member Licensed User

    My bad!! Thanks for pointing out. I've updated the library in the first post.
  11. agraham

    agraham Expert Licensed User

    This library seems to be a compiled B4A class module so why not just post the source so we can see what is going on and modify it if we need to?
    peacemaker likes this.
  12. Brandsum

    Brandsum Active 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.
  13. agraham

    agraham Expert Licensed User

    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.
    peacemaker likes this.
  14. Brandsum

    Brandsum Active Member Licensed User

    Ok, then I think it is a good idea to post both files.
    peacemaker and Alexander Stolte like this.
  15. agraham

    agraham Expert Licensed User

    That IS a good idea - and I have to confess it hadn't occurred to me to suggest that :(
  16. Brandsum

    Brandsum Active Member Licensed User

    I've uploaded the class module. Click the first post.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice