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
 

DonManfred

Expert
Licensed User
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."
where does the long text come from? Not from your variable TESTO...

MAybe you should always create a new variable.
B4X:
DIM TESTO as STring ="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."
 
Last edited:

emexes

Well-Known Member
Licensed User
I just modified a TTS1 app of mine to output a 700 character string, and it worked fine (except that it's using repetitive numbered phrases, and it's getting a bit tedious listening to it over and over and over again!)

So the differences are:
1/ I'm outputting to the speaker, not a WAV file, and
2/ is in English, not Italian (although I'm sure it'd sound better with an Italian accent).

Does yours output long strings to the speaker? I'm wondering if there is some size limit on the output WAV file size, given that string length does not seem to be the constraint.

Just in case you'd like a 700 character test string (or you're having trouble sleeping at night...)
B4X:
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)

TTS1.Speak(Temp, True)
 

emexes

Well-Known Member
Licensed User
Or is there a limit on source code line length, and perhaps your long string is suffering from premature truncation.
 

udg

Expert
Licensed User
Or with stringbuilder:
B4X:
Dim sb As StringBuilder
sb.Initialize
For i = 1 To 100
  sb.Append($" Now is the time for all good men to come to the aid of the $3.0{i} party."$)
Next
edit: my "or" relates to message #3 above..ehehe
 

Giusy

Active Member
Licensed User
where does the long text come from? Not from your variable TESTO...

MAybe you should always create a new variable.
B4X:
DIM TESTO as STring ="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."
Hi, @DonManfred ,
The text variable is created by reading some records of a darabase
 

Giusy

Active Member
Licensed User
I just modified a TTS1 app of mine to output a 700 character string, and it worked fine (except that it's using repetitive numbered phrases, and it's getting a bit tedious listening to it over and over and over again!)

So the differences are:
1/ I'm outputting to the speaker, not a WAV file, and
2/ is in English, not Italian (although I'm sure it'd sound better with an Italian accent).

Does yours output long strings to the speaker? I'm wondering if there is some size limit on the output WAV file size, given that string length does not seem to be the constraint.

Just in case you'd like a 700 character test string (or you're having trouble sleeping at night...)
B4X:
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)

TTS1.Speak(Temp, True)
Hi, @emexes,
My string is built similarly to yours, but I need to write the file and then read it with mediaplayer. But with a length of over 100 crt it does not create the file, so ....
 

emexes

Well-Known Member
Licensed User
Or with stringbuilder:
I should probably "like" that stringbuilder tip, but I was thinking ahead to perhaps needing a more typical example like:

B4X:
Temp = Temp & "That would be the end of the story, until years later, at another job, I had to troubleshoot "
Temp = Temp & "some microcontroller firmware with only one or two bits of GPIO I could configure as output "
Temp = Temp & "for instrumentation. I could have used any logic analyzer, or even an oscilloscope, in a pinch, "
Temp = Temp & "to capture whatever instrumentation I could shove out on those two lines, or, I could dust "
Temp = Temp & "off the state-analysis mode of an HP1650B we just happened to have laying around the office: "
Temp = Temp & "I would use one I/O as a strobe, and whatever other lines I could scrounge for data. With a "
Temp = Temp & "tiny bit of additional firmware, I had a tiny, quick subroutine that could clock out whatever "
Temp = Temp & "data I wished to see on the analyzer. Any other output lines I could repurpose made my "
Temp = Temp & "instrumentation that many bits wider."
and by doing it this way rather than the multi-line super-strings, I can see exactly what I'm getting (and not getting).

If there was a "half-like" button, I'd press it, though ;-)
 

emexes

Well-Known Member
Licensed User
following my example would seem yes
That sounds like you're saying the problem is with the source code line length.

When you log the string length, just before sending it off to TTS, how long is the string?
 

DonManfred

Expert
Licensed User
It is more easy using Smart String Literal.
B4X:
Temp = $"That would be the end of the story, until years later, at another job, I had to troubleshoot some microcontroller firmware with only one or two bits of GPIO I could configure as output for instrumentation. I could have used any logic analyzer, or even an oscilloscope, in a pinch, to capture whatever instrumentation I could shove out on those two lines, or, I could dust off the state-analysis mode of an HP1650B we just happened to have laying around the office: 
I would use one I/O as a strobe, and whatever other lines I could scrounge for data. 

With a tiny bit of additional firmware, I had a tiny, quick subroutine that could clock out whatever data I wished to see on the analyzer. Any other output lines I could repurpose made my instrumentation that many bits wider."$
 

udg

Expert
Licensed User
eheh, half-likes would be a nice addition (and generate a lot of chaos/discussions too :) )
The OP said she read text from a DB, so the StringBuild should be ok (maybe this second consideration will win me a second half-like ehehe)
And I used the Smart String Literals too :D
 

emexes

Well-Known Member
Licensed User
It is more easy using Smart String Literal.
and for power-users, that's probably true, but for lesser mortals who have been bitten when the far ends of lines are truncated unseen, or worry about precisely what leading and trailing whitespace is included in the string... sometimes slow and steady is better. But to each, their own. I'm still reeling from that library-at-the-speed-of-light trick the other day :)
 

Giusy

Active Member
Licensed User
with TTS1.speak(TESTO,True) a long text work fine, but so it is not "Pause" in TTS1, so I need the file.
How to do?
 

emexes

Well-Known Member
Licensed User
And does your long string work if sent to the speaker? If it does, then it sounds like there might be a limit on the output WAV file length, in which case I'll give that a go here. Perhaps all that will prove is that you're not alone with this problem, but that's still progress: a problem shared is a problem halved!
 

emexes

Well-Known 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")
 
Top