Android Question How to TTS.stop without releasing TTS object?

Discussion in 'Android Questions' started by gimch, Jul 29, 2019.

Similar threads

B4A Tutorial Automatic Foreground Mode
B4A Tutorial [B4X] OkHttpUtils2 with Wait For
B4A Tutorial Android Text To Speech example
B4A Question TTS Stop
B4A Question TTS isSpeaking listener
  1. gimch

    gimch Member Licensed User

    How to TTS.stop without releasing TTS object?
    TTSFunctions.bas uses tts.speak(" ",True) before stop,
    but, also raise error when click btnSpeak again.
    Inserting sleep(100) before stop is work well with debug mode,
    but, same problem with release mode.
    Maybe, solution is shutdown for release on every stop,
    and Initialize tts object again.
    How do you think about?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    What is TTSFuctions? Why is it needed?

    You can call TTS.Stop to make it stop speaking.
     
  3. gimch

    gimch Member Licensed User

    It is used only code.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I don't understand. Which error have you encountered? Where is the full error message? Why aren't you using TTS directly?
     
  5. gimch

    gimch Member Licensed User

    I use TTS directly, and needed some implements only. like this...
    Sub ts_Ready(Success As Boolean)
    If Success Then
    'enable all views
    For i = 0 To Activity.NumberOfViews - 1
    Activity.GetView(i).Enabled = True
    Next
    ts.SetLanguage("ko","kr")
    wait for (TTSFunctions.GetListOfAvailableLanguages("")) Complete(sAvail As String)
    LogColor(sAvail, Colors.Blue)
    LogColor(TTSFunctions.GetTTSCurrentLocale(ts), Colors.Green)

    Dim l As List,m As Map,id As Long
    l.Initialize
    m.Initialize
    l=TTSFunctions.GetTTSNamesAndPackages(ts)
    Dim ttsP(l.Size) As String
    spnEngine.Clear
    For ii = 0 To l.Size - 1
    m = l.Get(ii)
    LogColor(m,Colors.Magenta)
    ttsP(ii)=m.Get("TTSPackage")
    spnEngine.Add(m.Get("TTSName"))
    If m.Get("IsDefaultTTS") Then id=ii
    Next
    ttsPackage=ttsP
    spnEngine.SelectedIndex = id
    spnrLanguages_ItemClick(spnrLanguages.SelectedIndex,"ko")
    Else
    Msgbox("Error initializing TTS engine.", "")
    End If
    End Sub
    Sub Activity_Resume
    If ts.IsInitialized = False Then
    ts.Initialize("ts")
    End If
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
    ts.Release
    End Sub

    Sub btnSpeak_Click
    Dim isSpeak As Boolean
    isSpeak=TTSFunctions.IsTTSSpeaking(ts)
    Sleep(100)
    If btnSpeak.Tag=1 Then
    ts.Speak(".", True)
    Sleep(100)
    ts.Stop
    btnSpeak.Tag=Null
    btnSpeak.Text="Speak"
    If isSpeak Then Return
    ' Return
    End If
    If EditText1.Text.Length > 0 Then
    ts.Speak(EditText1.Text, True)
    btnSpeak.Tag=1
    btnSpeak.Text="Stop"
    End If
    End Sub
    Sub barSpeechRate_ValueChanged (Value As Int, UserChanged As Boolean)
    If UserChanged Then
    ts.SpeechRate = Value / 10
    lblSpeed.Text="Speed " & (Value / 10)
    End If
    End Sub
    Sub barPitch_ValueChanged (Value As Int, UserChanged As Boolean)
    If UserChanged Then
    ts.Pitch = Value / 10
    lblPitch.Text= "Pitch " & (Value / 10)
    End If
    End Sub
     
    Last edited: Jul 29, 2019
  6. DonManfred

    DonManfred Expert Licensed User

    Please use Code-tags when posting Code.
     
  7. gimch

    gimch Member Licensed User

    [Solved] Thanks!
    With compiled java code, found the btnSpeak.Tag is not compared with integer.
    So, solved using a code - btnSpeak.Text.EndsWith("p") .

    PS: How to use Code-tags?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice