I have a question related also to Text To Speach: Is is possible now to switch between different speach engines without user intervention? I use primary google text to speach, but some languages are only available with svox engine. I hope that newer android api's can switch between speach engines?!
Hi @Erel
sorry for the delay on the response.
i m tested your example code today and i got this error.
Installing file.
PackageAdded: package:leitor.df.texto
Copying updated assets files (18)
** Activity (main) Create, isFirst = true **
Class not found: leitor.texto.like.speakbutton, trying: leitor.df.texto.speakbutton
** Activity (main) Resume **
BR
Error occurred on line: 1232 (Main)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at leitor.df.texto.main._btshare_click(main.java:2409)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5246)
at android.view.View$PerformClick.run(View.java:21200)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.HashMap.get(java.lang.Object)' on a null object reference
at android.speech.tts.TextToSpeech.synthesizeToFile(TextToSpeech.java:1918)
... 25 more
what this changes at your example code?
i think your code its working and its correct for android < 21, but how to make this new synthesizeToFile to android > 21 ? CharSequence, Bundle etc...
i m tryed this
B4X:
Dim jo As JavaObject = tts1
jo.RunMethod("synthesizeToFile", Array(s, Null, File.Combine(FP, "1.wav"),"casa"))
but return error
** Activity (main) Create, isFirst = true **
Class not found: leitor.texto.like.speakbutton, trying: leitor.df.texto.speakbutton
** Activity (main) Resume **
BR
** Activity (main) Resume **
WakeLock already held.
Error occurred on line: 1232 (Main)
java.lang.RuntimeException: Method: synthesizeToFile not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:128)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:742)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5246)
at android.view.View$PerformClick.run(View.java:21200)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
The documentation says that the Map parameter can be null. Based on the error it cannot be null.
This code works:
B4X:
Sub tts1_Ready (Success As Boolean)
Log(Success)
Dim jo As JavaObject = tts1
Dim m As JavaObject
m.InitializeNewInstance("java.util.HashMap", Null)
jo.RunMethod("synthesizeToFile", Array("a b c", m, File.Combine(File.DirRootExternal, "1.wav")))
End Sub
Sub Activity_Click
Dim mp As MediaPlayer
mp.Initialize
mp.Load(File.DirRootExternal, "1.wav")
mp.Play
End Sub