Android Question Run TTS engine.

Discussion in 'Android Questions' started by John Sturt, Jan 29, 2015.

  1. John Sturt

    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.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Do you need to change the engine?
     
  3. John Sturt

    John Sturt Active Member Licensed User

    Yes I have a few engines I would like to choose from.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. John Sturt

    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?
     
    dar2o3 likes this.
  6. Erel

    Erel Administrator Staff Member Licensed User

    Check the output of r.RunMethod2 when you set the engine name. It should be 0.

    Wait a few seconds before you try to use TTS after you set the engine.
     
  7. John Sturt

    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
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    It should be java.lang.String instead of java.lang.String.
     
  9. John Sturt

    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.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Check the output:
    Code:
    Log(r.RunMethod2("SetEngineByPackageName",...)
    If it not 0 then it failed to set the engine.
     
  11. John Sturt

    John Sturt Active Member Licensed User

    Hi Erel
    The output is zero for all engines.
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Are you waiting a few seconds before you call TTS.Speak?
     
  13. John Sturt

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice