Android Example Offline Continuous Speech Recognition

This is a very old project which is unlikely to function correctly on newer versions of Android. The link to the project should still be active and if you want to use it for reference to update to a newer version feel free.

This is a proof of concept port of CMU PocketSphinx for Android demo app.

It's written in B4a using JavaObject to access the PocketSphinx library.

There is a wealth of information on the website : http://cmusphinx.sourceforge.net/ on tailoring the dictionaries, grammar and models.

If you want to control simple tasks or games with a few keywords, it doesn't look like it would be too difficult to implement. I'll let you know in a few weeks when I have integrated it into a current project.

I've used B4a 3.82, so if you're using an older version you will have to change some of the JavaObject calls relating to the array definitions i.e. change them to Array As Object(..) instead of Array(...)

In line with recommendations from CMU the setup copies the files from the assets directory to the apps default directory if it's not there, or the MD5 ID has changed. This is done in a thread in a separate class that has the #ExcludeFormDebugger: True directive, so you should be able to debug the rest of the app.



Download and unzip the library file and copy it to your additional libraries folder.

The project is located on my Google Drive as, with the dictionaries, it is too large (about 10 MB) to upload to the forum you can download it here : SpeechRecognizerContinuous


It's a bit confusing to download if you haven't done it before (as I just found out), click on the file, then there will be a download icon somewhere at the top middle of the screen.

The copyright.txt file contains the original copyright notice from the demo app.

Update to V1.1
  • Replaced threading with wait for
  • Replaced File.DirExternal with RuntimePermissions GetSafeDirDefaultExternal
  • Changed listener event handler (not quite sure why that needed changing)
  • Changed manifest to android:targetSdkVersion="29"
  • Recognizer object is passed back on configuration completion instead of being shared.

  • Updated link to project on Google drive due to their change in security.


Download the new project from SpeechRecognizerContinuous. The library zip is unchanged if you already have it.

Have fun, and let me know how you get on with it.
 

Attachments

  • copyright.txt
    1.5 KB · Views: 1,966
  • Library.zip
    403.1 KB · Views: 960
Last edited:

stevel05

Expert
Licensed User
Longtime User
Sorry guys, I lost my internet for a week, then I've been in the studio rehearsing and recording, so haven't been able to get on the site.

@petr4ppc

Without rewriting the app (this was a proof of concept after all) I think you will either have to move the initialize statement to Activity_Resume, or only call stop if the app is user closed, then test if it's running in Activity resume before running the initialize. It really depends on how you want the recognizer to work, and to clean up after itself when it goes into the background.
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
steveI05 and Erel, thank you for your answers.....

Please for advice:

1) if recognition is started then I get sometime this error:
java.lang.RuntimeException: Object should first be initialized (JavaObject).
why please? I am using program as is...

2)
As wrote David about obfuscation mode
It is possible to change something in the app for using it in obfuscation mode?

Thank you very much
best regards
p4ppc
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

MaFu, thank you,

I change the
Private Sub Configurerecognizer
to
Private Sub Configure_recognizer

Now B4A can compile the program,

but I get new message:
Failed to initialize recogniser Exception : Field: _keyphrase not found in: BA.bfa.bfatry.speechrecognizer

If I try run program in standard Release mode (without obfuscation) everything is OK.

Please, why?

Thank you very much
p4ppc
 

brelto85

Active Member
Licensed User
Longtime User
the library works very well
i've these question:

1- this library, works also with screen off? is possible to run it in the service
2- this library suffer the Automatic Gain Control (AGC) of device? the voice recognition standard library suffer of AGC
 

stevel05

Expert
Licensed User
Longtime User
I think it should run in a service, you'll need to rewrite the Gui interaction.
The AGC will be hardware dependent, so there would be no difference using this or the standard library.
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Love this idea and thanks stevel05.
But for me it is just not reliable. Works great for a few minutes and just stops working
 

carchek

Member
Licensed User
Longtime User
I'm having problems. I try to run your example but I get Failed to initialize recogniser reference: null
Using android 2.3.4
 

stevel05

Expert
Licensed User
Longtime User
I can't find any reference on their web site to a minimum Android requirement, but I'm afraid I don't have a device running Android 2 to try it on. This was done 18 months ago as an experiment, I'm sure their software has moved on since then.

Maybe someone has created a more up to date version that would like to share.
 

trueboss323

Active Member
Licensed User
Longtime User
Hello,
I am also having some problems. I run the app in Release mode and I get stuck on the "computer" screen. Nothing happens after I say "computer"
 

stevel05

Expert
Licensed User
Longtime User
According to the web site it does.
 

Licht2002

Member
Licensed User
Longtime User
Hi,

do someone know - how to change the language?


Only copy the files do not work...

Thx Tom
 

supriono

Member
Licensed User
Longtime User
i have same error like this
private TH As Thread

missing library...
can same one help me.where to download library for thread..

i am use b4a v4
 
Top