iOS Question TTS utterance delay

Branko Milosevic

Active Member
Licensed User
I need to use pre and post uttreance delay in a TTS app which I just ported from b4A. On Android I used play silence method. AVSpeachSynthesizer has preutterancedelay and postutterancedelay available for this purpose.
B4X:
var preUtteranceDelay: TimeInterval { get set }
Can someone help with implementing this?. TYIA
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to add a pre and post delay:
B4X:
Sub SpeakWithDelay(ts As TTS, PreDelayMs As Int, Text As String, PostDelayMs As Int)
   Dim sp As NativeObject
   sp = sp.Initialize("AVSpeechUtterance").RunMethod("alloc", Null).RunMethod("initWithString:", Array(Text))
   sp.SetField("preUtteranceDelay", PreDelayMs / 1000)
   sp.SetField("postUtteranceDelay", PostDelayMs / 1000)
   sp.SetField("rate", ts.SpeechRate)
   sp.SetField("pitchMultiplier", ts.Pitch)
   Dim voice As NativeObject
   voice = voice.Initialize("B4IObjectWrapper").RunMethod("getMap:", Array(ts)).RunMethod("objectForKey:", Array("voice"))
   If voice.IsInitialized Then
     sp.SetField("voice", voice)
   End If
   Dim no As NativeObject = ts
   no.RunMethod("speakUtterance:", Array(sp))
End Sub
 
Upvote 0
Top