Android Question Run TTS engine.

John Sturt

Active Member
Licensed User
Hello
How do I run a TTS engine
I have the package name
and cannot find out how to run it.

Currently this is what I have

dim t as tts
dim r as reflecto
r.target = t
r.runmethod2("setpackagebyname",tts enginee name,"java.lang.string")

This does not work no errors just no result.
I am trying to rub and compile at level 21.
 

John Sturt

Active Member
Licensed User
I read that link before and I get no errors at all.
I am filling a listview with the package names of all
the available installed TTS engines.
After selecting one of them I push the package name through
r.runmethod2
and nothing happens.
I am running the code through a 5.0.1 nexus 5
Compiling at target level 21.

Errors I can normally deal with but getting
nothing back stumps me.
Any help?
 

John Sturt

Active Member
Licensed User
H
I am getting the following error with the subsequent code.
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **

java.lang.RuntimeException: java.lang.ClassNotFoundException: java.lang.string

at anywheresoftware.b4a.agraham.reflection.Reflection.classforname(Reflection.java:170)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod2(Reflection.java:815)
at b4a.example.main._lvevent_itemclick(main.java:356)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA$2.run(BA.java:285)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Caused by: java.lang.ClassNotFoundException: java.lang.string
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at java.lang.Class.forName(Class.java:272)
at anywheresoftware.b4a.agraham.reflection.Reflection.classforname(Reflection.java:167)
... 14 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.string" on path: DexPathList[[zip file "/data/app/b4a.example-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 18 more
Suppressed: java.lang.ClassNotFoundException: java.lang.string
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 19 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
java.lang.RuntimeException: java.lang.ClassNotFoundException: java.lang.string

Code follows.

Sub Process_Globals

End Sub
Sub Globals
Dimpn,lbAsList
DimlvAsListView
DimTAsTTS
End Sub
Sub Activity_Create(FirstTime AsBoolean)
lv.Initialize("lvEvent")
Activity.AddView (lv,0,0,100%x,100%y-50dip)
pn.Initialize
lb.Initialize
pn.Clear
lb.Clear
T.Initialize("TTSEvent")

End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed AsBoolean)
End Sub

Sub lvEvent_itemClick (pos AsInt,v AsObject)
Dim r AsReflector
r.Target = T
r.RunMethod2("SetEngineByPackageName",pn.Get(pos), "java.lang.string")
wait(5000)
End Sub

Sub wait(delay AsInt)
Dim now AsLong = DateTime.now
DoWhileDateTime.now<now+delay
Loop
End Sub
Sub TTSEvent_Ready (Success AsBoolean)
If Success Then
Dim r AsReflector
r.Target = t
Dim engines AsList = r.RunMethod("getEngines")
ForEach o AsObjectIn engines

r.Target = o
lv.AddSingleLine (r.GetField("label"))
pn.Add(r.GetField("name"))
Next
lv.Invalidate
EndIf

End Sub
 

John Sturt

Active Member
Licensed User
Hello and apologies to you Erel.
Thank you that fixed the error
now I am back to the no result / error when selecting a engine.
I am going to have to have a think about this and try something else.

John.
 

John Sturt

Active Member
Licensed User
Hello Erel
After the r.runmethod2 I use a wait sub to loop for a period of time.
This does not have any effect.
I use talkback to operate my devices so the TTS service is
on before I try to switch the engine.
I am trying to create a simple way to switch TTS engines , I am beginning to think about
invoking the system TTS engine menu.
 
Top