B4A Library SpeechRecognitionNoUI - Google Speech Recognition Without Popup

A better alternative for offline recognition is available here.

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

SpeechRecognitionNoUI

Author:
@Biswajit
Version: 1.6
  • 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 stops speaking.
      • Error (Msg As String)
        A network or recognition error occurred.
      • PartialResults (Texts As List)
        Partial recognition results are available.
      • Results (Texts As List)
        Recognition results are ready.
      • RmsChanged (RmsValue As Int)
        The sound level in the audio stream has changed. There is no guarantee that this method will be called.
      • BufferReceived(buffer() As Byte)
        The purpose of this function is to allow giving feedback to the user regarding the captured audio. There is no guarantee that this method will be called.
    • Functions:
      • NoRecognizerBeep As Boolean
        Set true if you dont want beep sound before and after speech recognition.
        Starting from Android 7+ this method will throw an exception if the user set the Do Not Disturb mode,
        unless your app has requested a special permission with NOTIFICATION_POLICY_ACCESS_SETTINGS.
        (Check example)
      • 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.

Note: Remember to INTERNET, RECORD_AUDIO and NOTIFICATION_POLICY_ACCESS_SETTINGS permission.
For SDK v30: Add this following code to your project manifest.
B4X:
AddManifestText(
<queries>
    <intent>
        <action android:name="android.speech.RecognitionService" />
    </intent>
</queries>)

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
Update 1.3: Fixed crashing issue in DND mode.
Update 1.4: Added proper error handling and warning message for DND mode. (Check the example)
Update 1.5: Added BufferReceived event.
Update 1.6: Fixed an issue with the offline voice recognition.
 

Attachments

  • SpeechRecognitionNoUI_example.zip
    10.5 KB · Views: 866
  • SpeechRecognitionNoUI_v1.6.zip
    7.5 KB · Views: 231
Last edited:
Hello
thank you
I tried this library and sample on two friends. Works on Samsung phone without any problems, but does not work on Lenovo Android 7 tablet. There is no response when the volume button is pressed at the bottom of the page, but on this device the speech engine works perfectly on Google's own text.
where is the problem from?
 

free2end

Member
Licensed User
Hi, Biswajit
many thanks for your effort!

1. PartialResults (Texts As List): always have only one item with all the spoken words spaced.
2. StopListening As String: please give an example of syntax
3. BufferReceived(buffer() As Byte): please give an example of syntax

best wishes!
 

Biswajit

Active Member
Licensed User
Hi, Biswajit
many thanks for your effort!

1. PartialResults (Texts As List): always have only one item with all the spoken words spaced.
2. StopListening As String: please give an example of syntax
3. BufferReceived(buffer() As Byte): please give an example of syntax

best wishes!
1. you have to set partial result = true then starting the listerner StartListening("en_US", true, false)
2. call this if you want to stop the listener just like sr.StopListening
3. there is no guarantee that this method will be called. (As per the Android documentation)
 

free2end

Member
Licensed User
1. you have to set partial result = true then starting the listerner StartListening("en_US", true, false)
allready done it but at PartialResults (Texts As List): always have only one list item with all the spoken words spaced... not a List with the recognized words as seperate items
 

DonManfred

Expert
Licensed User
Longtime User
not a List with the recognized words as seperate items
You can split the string at the space and put then in a seperate list.
 

Biswajit

Active Member
Licensed User
allready done it but at PartialResults (Texts As List): always have only one list item with all the spoken words spaced... not a List with the recognized words as seperate items

PartialResults doesn't mean you will get all the words separately.

Check the android documentation for better understanding.
 

Dave O

Well-Known Member
Licensed User
Longtime User
Ideally I'd like to be able to do speech to text and also save the voice recording. This isn't possible with XSpeechRecognizer (because of a Google limitation for Android 4.1 and later?), but wondering if this library offers anything extra that way?

Thanks.
 

Biswajit

Active Member
Licensed User
Ideally I'd like to be able to do speech to text and also save the voice recording. This isn't possible with XSpeechRecognizer (because of a Google limitation for Android 4.1 and later?), but wondering if this library offers anything extra that way?

Thanks.
No. This is actually not a custom voice recognition library. It's a bridge between your app to the inbuilt android speech recognizer.
 

brown8

New Member
Hi! I'm trying to use this great library, but I'm getting some problems when I set target Sdk version to 30 (as Google demands). When I run the app, it simply doesn't do anything if I try to use the recognition and I get the log "Speech Recognition Not Available", but only with Sdk set to 30. If I change it to 29, everything works like a charm. Do you know what can I do to solve this issue?
 

Biswajit

Active Member
Licensed User
Hi! I'm trying to use this great library, but I'm getting some problems when I set target Sdk version to 30 (as Google demands). When I run the app, it simply doesn't do anything if I try to use the recognition and I get the log "Speech Recognition Not Available", but only with Sdk set to 30. If I change it to 29, everything works like a charm. Do you know what can I do to solve this issue?
For Android 11 (SDK 30) you have to add the below code to your manifest for speech recognition.

B4X:
AddManifestText(
<queries>
    <intent>
        <action android:name="android.speech.RecognitionService" />
    </intent>
</queries>)
 

brown8

New Member
For Android 11 (SDK 30) you have to add the below code to your manifest for speech recognition.

B4X:
AddManifestText(
<queries>
    <intent>
        <action android:name="android.speech.RecognitionService" />
    </intent>
</queries>)

Thank you very much! Solved with your code.
 

Biswajit

Active Member
Licensed User
Don't take Spanish Words
Use "es-US" instead of "en-US" for Spanish language.
B4X:
sr.StartListening ("es-US", true, false)

You can find the IETF language tag list here.
 

Guenter Becker

Active Member
Licensed User
Dear Biswajit
I am using your lib on a Huawei p20Pro and Android API 29. It is working good except if I am setting StartListening PREFER_OFFLINE Parameter to TRUE. sr_error reports the message "no match". Whats going wrong? Any Idea. Thank you for your help.

Start Listening:
If sr.IsInitialized Then
      'Language, Partial Results, Offline
       sr.StartListening("de",True,True)
End If
 

Biswajit

Active Member
Licensed User
Dear Biswajit
I am using your lib on a Huawei p20Pro and Android API 29. It is working good except if I am setting StartListening PREFER_OFFLINE Parameter to TRUE. sr_error reports the message "no match". Whats going wrong? Any Idea. Thank you for your help.

Start Listening:
If sr.IsInitialized Then
      'Language, Partial Results, Offline
       sr.StartListening("de",True,True)
End If
If you are using offline speech recognition then make sure you have the correct language pack installed.
 

Guenter Becker

Active Member
Licensed User
If you are using offline speech recognition then make sure you have the correct language pack installed.

Ok, understood sorry this is my first time using the lib.
Question: where will the language pack come from? In my current understanding it should be part of the android system installed on my smartphone. Do I have to download it from Google?
Are you able to help me with an download link and some help how to install please?
 

Biswajit

Active Member
Licensed User
Ok, understood sorry this is my first time using the lib.
Question: where will the language pack come from? In my current understanding it should be part of the android system installed on my smartphone. Do I have to download it from Google?
Are you able to help me with an download link and some help how to install please?
  1. Open Google App
  2. click on the "more" button at the bottom right corner
  3. goto settings
  4. goto voice
  5. click on offline speech recognition
  6. goto All tab
  7. click on the language pack you want to use for offline speech recognition.
 
Top