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:

bparent

Member
Licensed User
Longtime User
This can be big. Look forward to your results from integrating this into your project.
 

stevel05

Expert
Licensed User
Longtime User
Yes, unfortunately the language choice is a bit limited, but you can always create your own, if you have the time.
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friend,

I am trying your example with version B4A 3.50
I change Array() to ArrayAsObject
If I run the App I get black screen and if I say something (for example "wakeup") - nothing happen

I found after short time that the mistakes are because of my version of B4A.

Thank you
p4ppc
 
Last edited:

aaronk

Well-Known Member
Licensed User
Longtime User
I am running your demo, and when I run the app is says to say "Computer" but nothing happens. (doing this in debug mode)

If I run it in release mode, it comes up saying:
"An Error has occurred in Sub: java.lang.RuntimeException: Thread.Start : Sub configurerecognizer not found! Continue?"

I have copied the attached libarary to my libararys directory. (C:\Program Files\Anywhere Software\Basic4android\Libraries)
And I am running the code from your Google Drive

Am I doing something wrong ?
 

stevel05

Expert
Licensed User
Longtime User
When you open the project you should see three modules, Main, SetupRecognizer and SpeechRecognizer. The ConfigureRecognizer sub is in SetupRecognizer. Do you see the three Modules and the Sub?
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
steveI05 and dear friends,

If I run app, everything is OK, then if I stop the app (pause mode of app) and then I run app again, the voice recognition is not running.....

How can I run again the recognition if the app is starting again (wakeup-resume)? Here is not function START or something else....

how can I start voice recognition again, please?

Thank you very much
Best regards
p4ppc
 
Last edited:

stp

Member
Licensed User
Longtime User
Sub Globals
Dim pw As PhoneWakeState
End Sub

Sub Activity_Resume
pw.KeepAlive(True)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
pw.ReleaseKeepAlive
' release if user closes the app
End If
End Sub



on pause you can use pw.KeepAlive(True)
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear FRIENDS, STP

thank you very much...
I think, that here are not troubles with going to sleep...

In Sub Activity_Pause (in STEVI05 program) is this code:
B4X:
SR.Stop

this code stopped the voice recognition when the app is in PAUSE mode
how can I start voice recognition again - from Sub Activity_Resume, please?

I hope, that it is not bad or dumb question

Please ,help me,
Thank you very much
p4ppc
 
Last edited:

petr4ppc

Well-Known Member
Licensed User
Longtime User
Please, friends,

do you have some tips?
Or is it dumb question form my side? = how can I start voice recognition again - from Sub Activity_Resume, please?

i can stop voice recognition with this: SR.Stop
How can I start it again?

Thank you
p4ppc
 

stevel05

Expert
Licensed User
Longtime User
I've been away so haven't responded sooner, I'll take a look at it this evening.
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
steveI05 -

Have you some new informations, please?
Can you help us, please?

Thank you
p4ppc
 

David Hawkins

Active Member
Licensed User
Longtime User
Hi I am getting this error when trying to run your project. The Sub is there.

java.lang.RuntimeException: Thread.Start : Sub configurerecognizer not found!

Regards

David
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Doesn't work for me too even in release mode and obfuscated. I have seen that at line 17 of SetupRecognizer, the initialize is written initialise and I am provided with an error

SRC.png


and it generates an error while executed on KitKat 4.4.4 (Nexus 5)

java.lang.RuntimeException: Thread.Start : Sub configurerecognizer not found!
 
Top