Android Question Switching TTS engines

stevieg

Member
Licensed User
Longtime User
Does anyone know how to switch to different TTS engines that have been installed on a device?

I have looked at a post by Erel that suggest:

Dim r As Reflector
r.Target = TTS
r.RunMethod2("setEngineByPackageName", "new.package", "java.lang.String")


But the "setEngineByPackageName" has been Deprecated in version 4 and above so that method cannot be called.


I have an Android Tablet that is running Version 4.0 and would like to switch to different TTS engines when needed.


I know how to get the name of the engines and its language capabilities, I just can't figure out how to switch between them programmatically.
 
Last edited by a moderator:
The method should still work, even if it is deprecated.

The new method added in Android 4 cannot be called with Reflection.

I'm sorry but I don't know how you would call it directly.
Could you give me an example?

Thanks.
 
Upvote 0
Does anyone know how to switch to different TTS engines that have been installed on a device?

I have looked at a post by Erel that suggest:

Dim r AsReflector
r.Target = TTS
r.RunMethod2("setEngineByPackageName", "new.package", "java.lang.String")


But the "setEngineByPackageName" has been Deprecated in version 4 and above so that method cannot be called.


I have an Android Tablet that is running Version 4.0 and would like to switch to different TTS engines when needed.


I know how to get the name of the engines and its language capabilities, I just can't figure out how to switch between them programmatically.

Can you explain exactly how to get the name of the engines and its language capabilities?.
 
Upvote 0
Here is the code that I used:

Code: Copy
Dim TTS1 As TTS

Code: Copy
Sub TTS1_Ready (Success As Boolean)

  If Success Then
 
      Dim R As Reflector
    R.Target = TTS1
    R.RunMethod2("setEngineByPackageName", "com.google.android.tts", "java.lang.String")
         
  End If


End Sub

It worked fine for me, hope this helps.
 
Upvote 0
Here is the code that I used:

Code: Copy
Dim TTS1 As TTS

Code: Copy
Sub TTS1_Ready (Success As Boolean)
 
  If Success Then
 
      Dim R As Reflector
    R.Target = TTS1
    R.RunMethod2("setEngineByPackageName", "com.google.android.tts", "java.lang.String")
        
  End If
 
 
End Sub

It worked fine for me, hope this helps.
I tried and this works. Thank you very much for help.
 
Upvote 0
Some questions about changing: I have different voices with different engines. What is the correct order to switch? Do i have to release the TTS Engine and initialize as new? Should the engine switched before and then i select the the language with tts1.setlanguage?
 
Upvote 0
Some questions about changing: I have different voices with different engines. What is the correct order to switch? Do i have to release the TTS Engine and initialize as new? Should the engine switched before and then i select the the language with tts1.setlanguage?
You don't need to release and initialize. Just switch to new engine and then select language.
 
Upvote 0
I have two additional engines installed:
There package names are

Ivona: com.ivona.tts
SVoc: com.svoc.classic

To find out the package name, first install it and you can use a tool like Stanley from playstore - it shows deeper information beginning from package name, version code, activities etc.
 
Upvote 0
Hi
1. You can see the installed TTS engines by the following code that was posted earlier:
Code: Copy
  Dim t As TTS
  t.Initialize("t")
  Dim r As Reflector
  r.Target = t
  Dim engines As List = r.RunMethod("getEngines")
  For Each o As Object In engines
      r.Target = o
    Log(r.GetField("name"))
  Next

2. The "setEngineByPackageName" is still available and you can use it. It works on my Android 4.1 and 4.3.
 
Upvote 0
You are right; its svox.
The other's: com.acapelagroup.android.tts
and com.cereproc.Leopold for this one voice; i dont see any generic cereproc tool; maybe each voice has its own package name.
 
Upvote 0
Thank you very much. However, I also want to switch between voices programmatically (same language or even mixed languages). Any idea how to do that?

From TTS example:
Sub spnrLanguages_ItemClick (Position As Int, Value As Object)
If tts1.SetLanguage(Value, "") = False Then
ToastMessageShow("Language data not found.", True)
Return
End If
End Sub

You can change languages within engine by tts.SetLanguage method.
first parameter is language itself, second is language dialect if available(for example: "en", "UK" - english of United Kingdom. Please look at TTS library in documentation.
 
Upvote 0
Back
Top