Android Question TTS com.iflytek.speechcloud

Philip Prins

Active Member
Licensed User
Longtime User
Hello,

I need some help converting the following function to B4A:
B4X:
Voice assistance interface
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_S
ERVICE);
if(tm != null){
tm.textToVoice(mTTSText);
}

The normal TTS doesn't work on this device.
 

drgottjr

Expert
Licensed User
Longtime User
i'm not seeing that the telephonemanager has a textToVoice() method. where are you getting this from? iflytek has a speech app; there's an sdk too? if it's tied to a particular phone, it might be difficult for someone without that phone to be of much help to you.
 
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
Hello ,it was supplied in the document by the manufacturer, see attachment.

I used some code I found from Erel to get the TTS engine on the device.

If I use the normal TTS library I can,t make it work.

The devices have a modified Android version, debug with the USB cable or bridge is not working, so I can,t see the error codes if there are anym
 

Attachments

  • Screenshot_2022-12-15-19-57-58-63_e2d5b3f32b79de1d45acd1fad96fbb0f.jpg
    Screenshot_2022-12-15-19-57-58-63_e2d5b3f32b79de1d45acd1fad96fbb0f.jpg
    446.5 KB · Views: 68
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you should be able to download a usb driver from the "manufacturer".
how are you supposed to know what's going on? a log is pretty
essential.

unless your modified android OS has an SDK, i don't understand how
you are able to build projects. B4X would have to use the other SDK,
not the regular SDK. and, as i mentioned, the normal telephonymanager
class does not have a textToVoice() method.

the only thing you can do with the code you posted is to test whether
or not you've instantiated the telephone manager. does the project
even compile? it should fail to compile when it sees you're trying
to run textToVoice(). are you at least able to tell if compilation has been
successful?
 
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
I have an ADB connection but the log in the IDE remains empty,only when i unfilter i can see limited log texts from the OS.

However this is a different problem,

How can i convert the pm instructions they provided in B4A ?
Do you have an example with JavaObject or Reflector ?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
so, here's an example with javaobject. i've spread things out a little to show step by step. it compiles but throws a runtime error:
textToVoice failed: (RuntimeException) java.lang.RuntimeException: Method: textToVoice not found in: android.telephony.TelephonyManager


B4X:
    Dim message As String = "hello, world"
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim telephonymanager As JavaObject = ctxt.RunMethod("getSystemService", Array("phone"))
    If telephonymanager.isinitialized Then
        Try
            telephonymanager.RunMethod("textToVoice",Array(message))
        Catch
            Log("textToVoice failed: " & LastException)
        End Try
    Else
        Log("could not initialize telephony manager")
    End If

as i mentioned early on, textToVoice() is not in the telephonymanager class used by b4a (or android studio, i would think).
technically, if you had a third party jar, you can use it with b4a with the #additionaljar option. in which case, you would point
a java object to it. do you have such a jar?
 
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
No jar was supplied,

I asked them to explain more details on this function.

There are 2 models wich are referred by the same document.
The e600 works with normal TTS, e690 is the headache one.

Will try your code example tomorrow.

Thanks for your help
 
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
so, here's an example with javaobject. i've spread things out a little to show step by step. it compiles but throws a runtime error:
textToVoice failed: (RuntimeException) java.lang.RuntimeException: Method: textToVoice not found in: android.telephony.TelephonyManager


B4X:
    Dim message As String = "hello, world"
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim telephonymanager As JavaObject = ctxt.RunMethod("getSystemService", Array("phone"))
    If telephonymanager.isinitialized Then
        Try
            telephonymanager.RunMethod("textToVoice",Array(message))
        Catch
            Log("textToVoice failed: " & LastException)
        End Try
    Else
        Log("could not initialize telephony manager")
    End If

as i mentioned early on, textToVoice() is not in the telephonymanager class used by b4a (or android studio, i would think).
technically, if you had a third party jar, you can use it with b4a with the #additionaljar option. in which case, you would point
a java object to it. do you have such a jar?
Yes this works perfectly

Thank you very much,
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Yes this works perfectly

Thank you very much,
i wish @Erel would explain how my solution works perfectly because i sure as hell don't see how. how do you build an android project without android.jar?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i get that. but, clearly, i don't get what android.jar is. or maybe i don't get what javaobject is. if i use my "perfect" snippet in inline java, i cannot even compile it with b4a because textToVoice() does not exist in android.jar (used by b4a). yet, if i use a javaobject object (as in my code), the textToVoice() method not only compiles with b4a, but it runs on your device (it does not run on my device, obviously). with the javaobject object, my code is apparently not resolved at compiletime, but at runtime. yet again the magic of b4a!
 
Upvote 0
Top