B4A Library Another SpeechRecognizer Library

JackKirk

Well-Known Member
Licensed User
Longtime User
Hi,

I am developing an app that, amongst other things, needs to take a photo with the camera while the phone is held very steady.

Tapping the screen to take the photo doesn't allow you to keep phone very steady.

I have already developed an alternate mechanism to take the photo which involves measuring "steadiness" via the accelerometer/magnetometer and a time delay. This works but is not perfect.

I am experimenting with this library with a view to adding a simple voice activation mechanism to take the photo.

Initial experiments are encouraging with one small issue.

I can rig my phone (Samsung S5) so that voice recognition with this library will work offline (in flight mode).

When I take flight mode off it reacts somewhat slower so it is obviously using a remote service - this is not desirable.

I tried fiddling with the library's .xml to add EXTRA_PREFER_OFFLINE but that just raised a compile time error - so obviously something needs to be changed in the library's .jar (this sentence spells out my total lack of expertise in this area).

So I totally support Chris160179's post above.

Thanks in advance...
 

JackKirk

Well-Known Member
Licensed User
Longtime User
Further to the previous post...

It turns out that this library is basically totally eclipsed by the class published by stevel05 at:

https://www.b4x.com/android/forum/threads/android-speech-recognition-api-wrapper.62959/

I was able to take that class, tidy it up for my needs and add:

RecognizerIntent.PutExtra("android.speech.extra.PREFER_OFFLINE", True)

in the Initialize method.

This gave me offline voice recognition.

Details of all of the RecognizerIntent constants ("android.speech.extra.PREFER_OFFLINE" etc) are available in the bottom part of this page:

https://developer.android.com/reference/android/speech/RecognizerIntent.html

Happy coding...
 

ddk1

Member
Licensed User
Thanks for the great bit of code vpires.
Its 2021, I'm on Android 11, and I've been using the VoiceRecognition class, part of Phone. But I don't like the way it pops up a 'Speak now' dialog, and worse, if I don't speak quick enough it make me have to click a link to get it listening again. Not so good when driving.
So I tried your code and it works brilliantly and doesn't force any dialog on me, I can choose what sort of prompt I might want to show the user.
For anyone else trying this, I found it kept giving error 9, no permission.
I used RuntimePermissions class to obtain permission PERMISSION_RECORD_AUDIO, at runtime.
I didn't need to do any of what Alberto Iglesias did, obtaining permission CHANGE_CONFIGURATION via ADB.
Many thanks
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…