B4A Library SpeechRecognitionNoUI - Google Speech Recognition Without Popup

Guenter Becker

Active Member
Licensed User
  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.

This is very helpfull, thank you.
Going the way on my phone I identify that two languages (German and English US) are already installed!
Next I took your B4A Example and changed the parameters: sr.StartListening("tested this lng codes: en / de / DE / de-US / DE-US / GE / GE-US",TRUE,TRUE) nothing works, always 'No Match'.
Changing Back to: sr.StartListening("tested this lng codes: en / de ",TRUE,FALSE) it works.

I looked on the Google Developer API Page ( Languages Codes | Directory API | Google Developers ). There is a list of lng codes and for Germany it says it's 'de'.

At the end if I set offline=false it works, setting it to true it works not!
 

Guenter Becker

Active Member
Licensed User
Hello Biswajit,
Do you have time to give me an answer/idea why the lib will not work in Offline Mode?
 

bsnqt

Active Member
Licensed User
Longtime User
Hi Guenter Becker and All

Same to me, it does not work if I set the PREFER_OFFLINE parameter to "False"... Try many ways but it does not work at all. Actually I also cannot change the language as well (have checked my Google setting for downloaded language package).
 

Biswajit

Active Member
Licensed User
Longtime User
Hello Biswajit,
Do you have time to give me an answer/idea why the lib will not work in Offline Mode?

After so many testing finally I found the issue. Now android takes all the parameters for SpeechRecognizer as string that's why it wasn't working. I will post the update in a moment.
 

Guenter Becker

Active Member
Licensed User
Hi bsnqt
sr.StartListening("de",True,False)

Notice! 'de' stands for German. Abbreviation/LNG Code must be taken from Google Dev!
 

Guenter Becker

Active Member
Licensed User
Biswajit
great and well done awaiting your update. Stay well.
 

bsnqt

Active Member
Licensed User
Longtime User
Hi bsnqt
sr.StartListening("de",True,False)

Notice! 'de' stands for German. Abbreviation/LNG Code must be taken from Google Dev!
Thank you, appreciate.
Yes I can change the language now. The only issue left now is the offline preference parameter, I hope we can get it done soon from Biswajit's update ?
 

bsnqt

Active Member
Licensed User
Longtime User
Just a quick report to Biswajit... I downloaded the lib 1.6 few minutes ago (as I got an update notification). Have checked and can see that the offline feature does not work yet. Please ignore this message if you have not yet updated it.

 

Biswajit

Active Member
Licensed User
Longtime User
New version of google now app will automatically try to use online speech recognition when the offline language is not installed on the device. Try to install that language and then try again. And while using offline speech recognition you have to specify the country code along with the language code. "en" will not work where "en-US" will work for the offline mode.
 

bsnqt

Active Member
Licensed User
Longtime User
Hi Biswajit,

Sorry I am still unsuccessful. Now I can make it done with "en-US" offline, but could not yet make it with my local language. I am using Samsung Galaxy phone. Where I can download the offline Speech-To-Text language package. It is a little confusing for me.

First, I can see that Google Speech Services say "now all voices for the language downloaded together"?



I also have selected Google Services as the default as per what they require (pls see pictures attached)
But still can select the local language but on the other setting I can see only English?
I missed something or doing totally wrong thing? Where I can download the offline language package?
 

Attachments

  • only english.jpg
    146 KB · Views: 276
  • selected2.jpg
    497.1 KB · Views: 277

Guenter Becker

Active Member
Licensed User
Hello, together,

with the new update the correct language code (sr.startlistening("de-DE",True,True) and the language downloaded from Google Dev the lib is now working as followes:
  • The correct language is taken. In my way de-DE for German (ISO LNG Codes)
  • Online Mode works correct.
  • Offline Mode no more errors reported but.....
  • Offline mode for example speaking 123 the lib returns 12312 12 3 ???? Tried it with different values always the same.

There must be still something wrong.

By the way I downloaded the offline language file its one per language and not the language package.
 

Biswajit

Active Member
Licensed User
Longtime User
Open google app, click the three dot icon at the bottom right corner. Then settings > voice > offline speech recognition then download the language pack you want.
 

Biswajit

Active Member
Licensed User
Longtime User
If its returning incorrect results then its related to the speech recognition engine. The library just create a bridge between B4A code and the android speech recognition API.
 

bsnqt

Active Member
Licensed User
Longtime User
Hi Biswajit,

Thanks for your reply and help to me and forum.
I confirm the library now works offline for "en-US". But for my local language (Vietnamese) it does not work at all and give a message saying "Network error".

I am not sure which Google app (by Google LLC) you are talking about, I am afraid that I may misunderstand you so I attached here the screenshot of "my" Google app, where I don't see any three dot icon even I have go thru to the bottom of the app screen. Did I go to wrong app?



(Instead I did go to Settings -> Google Voice Typing -> Voice Typing Language. And I already downloaded the local language, however voice recognition also does not work offline)
 

Biswajit

Active Member
Licensed User
Longtime User
Yes this is the right app. Google voice typing will not work. The android speech recognition API actually uses a hidden service of the google search app. So you have to download the language from that app.

I think you are using a tab. So the option may be placed somewhere else for that screen size. Check the screenshot below.
 

bsnqt

Active Member
Licensed User
Longtime User
Oh, now I understand... that is why I could not find it out (the three dots). Actually I tried (thought maybe it is hidden) but without success, there is no more tab in the app, just only 4 as shown in the picture I attached earlier. For an unknown reason, "my" Google app does not have it ? . Very strange.

I have only Samsung phones at home (the screenshot was taken from Galaxy Z Fold2). I will need to borrow somebody's phone with other brand to look at. Or Samsung may customize the apps (which I think impossible for the case of Google)? I will update you. Thank you very much.

(Next question I ask myself is then how can I download the package?)
 

Guenter Becker

Active Member
Licensed User
Hello hope you are well,

up to the problems with the OFFline Mode I found a workaround. In my App I need only numbers as spoken input. Using the code below it will work with the correct return either in Online or in Offline Mode. As biswajit says the problem does not come from his lib! It is comming from the speech recognition engine. In Offline mode it returns more than one value and the PartialResults sub is used, don't know why:

B4X:
Sub sr_Results(Texts As List)
    Dim Text As String
    For Each t As String In Texts
        Text = Text & t
    Next
    If IsNumber(Text) Then    DLGinputEdt.Text = Text
End Sub

Sub sr_PartialResults(Texts As List)
    If Texts.Size > 0  Then
        Dim Text As String = Texts.Get(0)
        If IsNumber(Text) Then    DLGinputEdt.Text = Text
    End If
End Sub
 
Last edited:

Biswajit

Active Member
Licensed User
Longtime User
A better alternative for offline recognition is available here.
 
Dear Mr Biswajit,
Please accept my deepest possible appreciation to you. You are allowing B4A programmers to use The best available and up to date voice recognition technology. Very very well done. Yours Java knowledge is outstanding, because you are even familiar with JNI standard to access native .so libraryes. Sure, Google recognizer do not require this programmers knowledge. But yours other big programmers library in The thread continuous voice recognition require that. So thank you for yours excellent activity on this forum.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…