Android Question ICOSTextToSpeech not working in B4XPages

Phayao

Active Member
Licensed User
Longtime User
Hello,

I know it's an old library - nevertheless it worked fine in the "old" way.
I like it to read text from a DB verse by verse. When I place the code into B4XPages, it stops before speaking anything.
The example is from the ICOSTTS library website, modified with DB use in B4XMainPage:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private SQL2, SQLBib As SQL
    Private DBFileDir As String
    Private rp As RuntimePermissions
    Private tts As ICOSTextToSpeech
    Dim lb As Label
End Sub

Public Sub Initialize
    tts.InitializeTTs("tts","en")

        DBFileDir = rp.GetSafeDirDefaultExternal("db")
        If File.Exists(DBFileDir, "biblesm.db") = False Then
            'copy the default DB
            File.Copy(File.DirAssets, "biblesm.db", DBFileDir, "biblesm.db")
            MsgboxAsync("Diary DB copied from default","DB Copy")
        End If
        SQLBib.initialize(DBFileDir, "biblesm.db", False)
        If File.Exists(DBFileDir, "verses.db") = False Then
            'copy the default DB
            File.Copy(File.DirAssets, "verses.db", DBFileDir, "verses.db")
            MsgboxAsync("Diary DB copied from default","DB Copy")
        End If

        SQL2.Initialize(DBFileDir,"verses.db",False)

End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("icostts")
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    wait for B4XPage_PermissionResult(Permision As String, Result As Boolean)
    If Result = False Then
        ExitApplication
    End If
End Sub

Sub b8_Click

    ' tts.Speaks = a         '<========== not working, program just halts without error
    speaktest
 
End Sub

Sub speaktest
    Dim cur As Cursor
    Dim q, ref, txt, txt1, txt2 As String
    q = $"SELECT main_id,Verse FROM MEMORY JOIN Ref USING(main_id) "$
    cur = SQL2.ExecQuery(q)

    For i = 1 To cur.RowCount-1
        cur.Position = i
        Log("Speak row "&i)   ' < ========== OK
        ref = refSearch(cur.GetString2(0),True)
        Log(ref)                '<========= OK
        tts.Speaks = ref   '<=========== not happening, instead get 'wait' progressdialog and program halts (no error)
        wait for tts_TTsCompleted
        Log("---tts 1 completed")
        Sleep(500)
      
        txt = cur.GetString2(1)      
        tts.Speaks = txt
        wait for tts_TTsCompleted
        Log("---tts completed")
        Sleep(500)
    Next
    ' wait for 2 secs until allow to press btnSpeak again:
    Sleep(2000)
    tts.stop

End Sub

Sub refSearch(id As String,longname As Boolean) As String
    Dim q As String
    If longname Then
        q = "SELECT book_name||' '||Chapter||':'||Verse FROM WEB JOIN Book ON(Book = book_id) WHERE main_id='"& id &"'"
    Else
        q = "SELECT book_shortname||' '||Chapter||':'||Verse FROM WEB JOIN Book ON(Book = book_id) WHERE main_id='"& id &"'"
        ' Log(q)
    End If
    Return SQLBib.ExecQuerySingleResult(q)
End Sub

Even I put the tts.Speaks command before, without any DB use, the program will hang at this command without error message.
The log without filter is just too long to be evaluated, it's an endless message chaos ;-)
The same code without Pages works OK !?!?

Any idea what happened ? - thanks in advance very much !
Chris
 
Last edited:
Top