B4J Question Help Converting .aar files to .arr.jar

MrKim

Well-Known Member
Licensed User
Longtime User
I am trying to convert THIS Speech to text Project to B4XPages (specifically for me B4J). The B4A version is working just fine.
I tried copying the Speech to text libraries from B4A libs to B4J libs but it fails with:
B4X:
Cannot find: C:\Program Files\Anywhere Software\B4J\libraries\vosk-android-0.3.47.aar.jar
and
B4X:
Cannot find: C:\Program Files\Anywhere Software\B4J\libraries\jna-5.13.0.aar.jar
I understand it is possible to convert .arr files to .jar and I did that using the instructions HERE. It did create files as advertised but they don't work.
The compile works but fails on this line:
B4X:
Sub Class_Globals
    Private STT As SpeechToText
With the following error:
B4X:
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
Error occurred on line: 11 (B4XMainPage)
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at b4j.example.b4xmainpage.innerInitialize(b4xmainpage.java:21)
    at b4j.example.b4xmainpage._initialize(b4xmainpage.java:377)
    at b4j.example.b4xpagesmanager._initialize(b4xpagesmanager.java:110)
    at b4j.example.main._appstart(main.java:85)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.example.main.start(main.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.NoClassDefFoundError: org/vosk/android/RecognitionListener
    at b4j.example.b4xmainpage._class_globals(b4xmainpage.java:124)
    ... 32 more
Caused by: java.lang.ClassNotFoundException: org.vosk.android.RecognitionListener
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 33 more
I honestly don't know if this is even possible but I would like to have windows stand alone STT for security reasons.
Any help appreciated.
 

DonManfred

Expert
Licensed User
Longtime User
AAR are ANDROID-Specific. They are not meant to use in B4J!

surely you can get the classes inside. the classes.jar is inside the AAR (which is a ZIP-File) but you can not use them in B4J if they are not meant to run not on Android.

Find a java-version of it which you can port
 
Upvote 0

teddybear

Well-Known Member
Licensed User
As DonManfred said, you dont't simply convert the library aar to jar. especially such as the jna library contains dynamic libraries related to the OS platform, they can't be converted. if you would like to use them, you may download the jars from maven and rewrap them.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
A Java version of vosk can be found on Github. In theory it should be able to compile. However, old SUN libraries are being called. Then you should convert the SUN libraries to Oracle Java 1.8. That will be quite an adjustment and my personal experience with such a conversion process is that you can come a long way, but still get stuck at the end.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Thanks everyone for your input. This means things go to a technical level beyond both my understanding and my desire to learn. I have enough other fun things to work on.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I played a bit with VOSK on weekend.
Basically i got the thing in B4J working.

The results are very poor though: I guess the quality is based on the WAV -File i provide to the library. With the ones i tried i got no good results at all.
i mean the bitrate the wav files has or something. Audio is not my strong part....
 
Last edited:
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
I played a bit with VOSK on weekend.
Basically i got the thing in B4J working.

The results are very poor though: I guess the quality is based on the WAV -File i provide to the library. With the ones i tried i got no good results at all.
i mean the bitrate the wav files has or something. Audio is not my string part....
That's wonderful! Maybe it has to do with the model you used? The one I used on Android seemed to work pretty well. I picked on of the larger models that it says was pretty accurate. Also, I was using voice, not an audio file. I would love to try it if you are willing to share..
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Yes, it is a very difficult area with minefields and you also run into the fact that the number of languages for the remaining recently updated open source solutions is very limited. I wonder whether there really is a broad need to use voice applications for B4J.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Yes, it is a very difficult area with minefields and you also run into the fact that the number of languages for the remaining recently updated open source solutions is very limited. I wonder whether there really is a broad need to use voice applications for B4J.
I understand. This is a very simple very specific solution for one client. If I can do it quickly and simply I will, otherwise no. Doesn't need to be perfect and doesn't need a lot of whiz-bang options. I was hoping to do it in Windows but I may just do it on in Android but that brings up more complicated Database connection issues.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I´ll ZIP something together this evening.
Togeher with a broad description of setup and where to put models and how.

The library
- can "parse" a wav-file of voice
- can parse a bytearray of voice

For both i can not help in which format they must be! This is completely out of my knowledge.

I just was curious to see whether i could get it work in B4J or not... :D
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Download, extract the files and put them into your additional libs folder.... Only the files. not folders....



Description follow later. For now you can try to see how it works.
All the models are on my VOSK folder UNZIPPED....

For example
E:\VOSK
is my basefolder where i do have my models.

A testmodel.zip is extracted to a folder testmodel with all files inside. So the path to your model is
Path: E:\VOSK
Foldername: testmodel
-> E:\VOSK\testmodel\

The same concept applies to the speaker-models too.
 

Attachments

  • VoskApi.zip
    2.3 KB · Views: 105
Last edited:
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
All the models are on my VOSK folder UNZIPPED....

For example
E:\VOSK
is my basefolder where i do have my models.

A testmodel.zip is extracted to a folder testmodel with all files inside. So the path to your model is
Path: E:\VOSK
Foldername: testmodel
-> E:\VOSK\testmodel\

The same concept applies to the speaker-models too.
Forgive me but I am a little lost. Am I supplying my own models?
The B4J example you gave me contains only the three #AdditionalJar lines. Other than that it is The B4J Directory of a new B4XPages Project.
I am not sure exactly what I am supposed to be trying here...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Am I supplying my own models?
yes. exactly the same like in the library for android you linked in #1.
There are also no models included.

You need to provide (or download a model.zip). Extract it. Use the new folder with the extracted files as path to your model.
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
The point is how much effort you want to put into it. When it comes to repeating standard text, you could record this text and play it as an MP3.

The problem is that Text To Speak is a revenue model today. In addition to costs, this means that the user must create an account and therefore must be online. The development of open source solutions has therefore come to a standstill.

In addition, they are often based on Java 1.8 and have hard coded references and a limited number of English voices. I can let speech a Java-based TTS voice with Eclipse, but I cannot make this voice speak in B4J with the compiled library.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Sorry for reading STT backwards ?
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Download, extract the files and put them into your additional libs folder.... Only the files. not folders....



Description follow later. For now you can try to see how it works.
All the models are on my VOSK folder UNZIPPED....

For example
E:\VOSK
is my basefolder where i do have my models.

A testmodel.zip is extracted to a folder testmodel with all files inside. So the path to your model is
Path: E:\VOSK
Foldername: testmodel
-> E:\VOSK\testmodel\

The same concept applies to the speaker-models too.
Finally got back to this (I had to go do real work). When I try to run the program it fails in Class Globals on the Following line:
B4X:
Private STT As SpeechToText
With this error:
B4X:
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
Error occurred on line: 19 (B4XMainPage)
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at b4j.example.b4xmainpage.innerInitialize(b4xmainpage.java:21)
    at b4j.example.b4xmainpage._initialize(b4xmainpage.java:370)
    at b4j.example.b4xpagesmanager._initialize(b4xpagesmanager.java:110)
    at b4j.example.main._appstart(main.java:85)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.example.main.start(main.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.NoClassDefFoundError: org/vosk/android/RecognitionListener
    at b4j.example.b4xmainpage._class_globals(b4xmainpage.java:346)
    ... 32 more
Caused by: java.lang.ClassNotFoundException: org.vosk.android.RecognitionListener
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 33 more
The lib is there and no errors are shown. If I rem that line the program compiles and runs but of course does nothing.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Download, extract the files and put them into your additional libs folder.... Only the files. not folders....



Description follow later. For now you can try to see how it works.
All the models are on my VOSK folder UNZIPPED....

For example
E:\VOSK
is my basefolder where i do have my models.

A testmodel.zip is extracted to a folder testmodel with all files inside. So the path to your model is
Path: E:\VOSK
Foldername: testmodel
-> E:\VOSK\testmodel\

The same concept applies to the speaker-models too.

@DonManfred the attachment of B4J code misses the B4XMainPage.
 
Upvote 0
Top