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

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?
 

gimch

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?
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:

gimch

Member
Licensed User
Please use Code-tags when posting Code.
[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?
 
Top