Android Question tts synthesizeToFile() save audio

Status
Not open for further replies.

Douglas Farias

Expert
Licensed User
Longtime User
Hi all.
how can i put the synthesizeToFile() event on tts lib?
i want to save a audio file and this is the native method.

it already is on tts lib?

some functions i can get with JavaObject like isSpeaking event.
B4X:
Dim jTTS As JavaObject = tts1 'not TTS
    If jTTS.RunMethod("isSpeaking", Null) = False Then

and get max getMaxSpeechInputLength
B4X:
       Dim jTTS As JavaObject = tts1
       suportado = jTTS.RunMethod("getMaxSpeechInputLength", Null)

but how to use synthesizeToFile usign JavaObject or reflection? its possible?

http://developer.android.com/reference/android/speech/tts/TextToSpeech.html

synthesizeToFile(String text, HashMap<String, String> params, String filename)

i know, i can try record a audio with AudioStreamer(can not work on some devices).
but if exist a native function to this on tts why not use?

its possible use this function with JavaObject or reflection libs? if yes how?

thx all.
 
Last edited:

rboeck

Well-Known Member
Licensed User
Longtime User
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?!
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
Hi @Erel
sorry for the delay on the response.
i m tested your example code today and i got this error.


reading the tts by android documentation this show
synthesizeToFile(String text, HashMap<String, String> params, String filename)
This method was deprecated in API level 21. As of API level 21, replaced by synthesizeToFile(CharSequence, Bundle, File, String).

my device its api 22 and i compiled the app with 23

the new code for synthesizeToFile its
synthesizeToFile(CharSequence text, Bundle params, File file, String utteranceId)
Synthesizes the given text to a file using the specified parameters.

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

thx again
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
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
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
lol many thx erel i will test. thx again.
you have plans to put this on TTS lib?
getMaxSpeechInputLength and
isSpeaking event?
 
Upvote 0
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…