Android Question SynthesizeToFile and text length

Giusy

Active Member
Licensed User
Hi,
this is my code with an example text (TESTO)

B4X:
Sub tts1_Ready (Success As Boolean)
    Log(Success)
   
    Dim jo As JavaObject = TTS1
    Dim m As JavaObject
    m.InitializeNewInstance("java.util.HashMap", Null)

    TESTO="Gelatine luccicavano nella penombra di quel pomeriggio di settembre. Sul bancone un gatto si insinuava tra bastoncini di liquirizia e barrette al cioccolato e cicche."

    jo.RunMethod("synthesizeToFile", Array(TESTO, m, File.Combine(File.DirRootExternal, "1.wav")))

End Sub
The routine works correctly and the file 1.wav is created.
But if the text becomes:

TESTO="Gelatine luccicavano nella penombra di quel pomeriggio di settembre. Sul bancone un gatto si insinuava tra bastoncini di liquirizia e barrette al cioccolato e cicche. Fuori le foglie morivano e cadevano. Il vento aveva spazzato via il sole. Una ragazza entrò di corsa."

the routine don't work.

The first text contain 166 characters, the second 269.

Is it normal or can I overcome the mistake?

Thanks
 

emexes

Expert
Licensed User
That code above produced a 2.5 MB WAV file, which I'd upload to eliminate any doubt, but...


upload_2019-3-8_23-34-5.png
 
Upvote 0

emexes

Expert
Licensed User
What about things like: write permission to the output directory, running out of space to save new files, which reminds me, hang on a sec...
 
Upvote 0

emexes

Expert
Licensed User
This forum software does NOT want you to hear that file. However, perseverance has triumphed over obstinance.

(and the software knows I'm talking about it, because it's marking the word "obstinance" as an error) (twice)
 

Attachments

  • 1mp3.zip
    360.9 KB · Views: 144
Upvote 0

Giusy

Active Member
Licensed User
B4X:
Log("start test")

Dim Temp As String = ""
Temp = Temp & " Now is the time for all good men to come to the aid of the 001 party."
Temp = Temp & " Now is the time for all good men to come to the aid of the 002 party."
Temp = Temp & " Now is the time for all good men to come to the aid of the 003 party."
Temp = Temp & " Now is the time for all good men to come to the aid of the 004 party."
Temp = Temp & " Now is the time for all good men to come to the aid of the 005 party."
Temp = Temp & " Now is the time for all good men to come to the aid of the 006 party."
Temp = Temp & " Now is the time for all good men to come to the aid of the 007 party."
Temp = Temp & " Now is the time for all good men to come to the aid of the 008 party."
Temp = Temp & " Now is the time for all good men to come to the aid of the 009 party."
Temp = Temp & " Now is the time for all good men to come to the aid of the 010 party."
Log(Temp.Length)

Dim rp As RuntimePermissions
Dim SaveDir As String = rp.GetSafeDirDefaultExternal("test")
Log(SaveDir)

Dim m As JavaObject
m.InitializeNewInstance("java.util.HashMap", Null)

Dim jo As JavaObject = TTS1
jo.RunMethod("synthesizeToFile", Array(Temp, m, File.Combine(SaveDir, "1.wav")))

Log("end test")
Hi, @emexes
It work work very well, you are a genius, thank you very much :D
 
Upvote 0

emexes

Expert
Licensed User
But now I'm thinking it's some problem with writing the output file, maybe a limit on what you can put into File.DirRootExternal vs me playing it safe and using rp.GetSafeDirDefaultExternal - just 'cause I'm wearing a crash helmet above, don't mean I be taking no unnecessary risks ;-)
 
Upvote 0

Giusy

Active Member
Licensed User
Hello everyone,
the problems aren't finish :(
In my program I recreate the text several times but the file name must always be "1.wav".
When the file does not exist in "savedir", it writes it and reads it perfectly.
In the second step when he has to write a new "1.wav" (but the previous one still exists, the program stops)
if I try to delete "1.wav"
B4X:
If File.Exists(SaveDir, "1.wav") Then
        File.Delete(SaveDir, "1.wav")
    End If
do not delete it.
Help :(
 
Upvote 0

emexes

Expert
Licensed User
The first problem sounds like a space issue, eg, there isn't enough room for *two* files, but if you use the same name, then the space of the previous instance is reclaimed when you write over that existing file and all is sweet.

The second problem sounds like somebody else still has a hold on the file. What happens if you kill the media player when it is done? - perhaps it is paused at the end of the file, ready for instant replay, rather than letting go of it. Can you delete the file after you have closed and restarted *your* app? (not that *you* would forget to close a file, but... we all have our little moments ;-) Do you get any messages if you enable b4abridge ftp and go in via tools, b4abridge, file explorer?
 
Last edited:
Upvote 0

Giusy

Active Member
Licensed User
The first problem sounds like a space issue, eg, there isn't enough room for *two* files, but if you use the same name, then the space of the previous instance is reclaimed when you write over that existing file and all is sweet.

The second problem sounds like somebody else still has a hold on the file. Wehat happens if you kill the media player when it is done? - perhaps it is paused at the end of the file, ready for instant replay, rather than letting go of it. Can you delete the file after you have closed and restarted *your* app? (not that *you* would forget to close a file, but... we all have our little moments ;-) Do you get any messages if you enable b4abridge ftp and go in via tools, b4abridge, file explorer?

Hi @emexes,
The strange thing is that there was a moment where I was enthusiastic ... everything worked perfectly. always cyclic in the same way: testo1, testo2, testo3, testo2 ... Even if they were long texts ... he wrote the file and read it perfectly. At some point it goes into error because the file is not written correctly.
Clean Proget, Clear, I close the program, I delete it from the device, I reinstall it. Finished ... it does not work anymore. I have seen in other programs use the TTS separating the sentences to the point, it is thus possible to avoid writing files.
I know myself, I will do some more tests. For now, I thank you for having listened to me and helped me. I will let you know if I discover something new.
Thanks again

(forgiveness for my English with Google translator :D )
 
Upvote 0

Giusy

Active Member
Licensed User
:D :D D: SOLVED :D :D :D
B4X:
Sub read
    Dim jo As JavaObject = tts1
    Dim m As JavaObject
    m.InitializeNewInstance("java.util.HashMap", Null)
    jo.RunMethod("synthesizeToFile", Array(TESTO, m, File.Combine(File.DirRootExternal, "1.wav")))
    Sleep(3000) <----------------------------------------------------------------------------------------------------------
    mp.Load(File.DirRootExternal, "1.wav")
    mp.Play
End Sub
I am very Happy now :D
 
Upvote 0

emexes

Expert
Licensed User
Maybe there is a limit on how much one user can use the TTS service in a hour/day/week/month (I think it sends it out over the internet to be done, and if so, then somebody has to pay to run that server). That would explain why it sometimes works for you, and why it now works for me but not you.
 
Upvote 0

emexes

Expert
Licensed User
Well, that's a coincidence that we both post at the same time.

In English: Great minds think alike!

;-)
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
That would explain why it sometimes works for you, and why it now works for me but not you.

Also that you were using the file immediately, whereas I had to go to another program, which acted as a poor person's Sleep(3000).

I am happy now that we have a reason that explains all of the symptoms.
 
Upvote 0

Giusy

Active Member
Licensed User
Also that you were using the file immediately, whereas I had to go to another program, which acted as a poor person's Sleep(3000).

I am happy now that we have a reason that explains all of the symptoms.

Now I calculate the length of the text and, with an equation, recalculate the new sleep. Now it works great (thanks to you :))
Have a nice Sunday
 
Upvote 0
Top