#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: ICOSTextToSpeech
#VersionCode: 18
#VersionName: 1.8
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
Sub Process_Globals
Dim AT1 As AudioTrack
Dim Ra As RandomAccessFile
End Sub
Sub Globals
Dim tts As ICOSTextToSpeech
Dim SayText1 As String
Dim at As AudioTrack
Dim BufferSize As Int
Dim SampleRate As Int
Dim ChannelConfig As Int
Dim AudioFormat As Int
Dim NoChnls,BitsPerSample,DataSize As Int
Dim Button1 As Button
Dim Button2 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.Title="ICOSTextToSpeech Library v1.90: Left/Right audio version"
Button1.Initialize("Button1")
Button2.Initialize("Button2")
Activity.AddView(Button1,5%x,20%y,90%x,15%y)
Activity.AddView(Button2,5%x,40%y,90%x,15%y)
Button1.Text= "SPEAK Right!"
Button2.Text= "SPEAK Left!"
tts.InitializeTTs("tts","en")
SayText1 = ", A very old Somali man has been charged with attempted murder, assault and kidnapping after an alleged armed rampage across Christchurch which ended when he was shot by the police."
End Sub
Sub TTsCompleted
ToastMessageShow("Events Fired",True)
End Sub
Sub TTsReady (Success As Boolean)
If (Success) Then
ToastMessageShow("TTS is Ready",False)
Else
ToastMessageShow("TTS is not Ready",False)
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_click 'Speak Right
TTS_HULP1
AT1.SetStereoVolume(AT1.GetMaxVolume * 0,AT1.GetMaxVolume * 1) 'RIGHT CHANNEL
End Sub
Sub Button2_click 'Speak Left
TTS_HULP1
AT1.SetStereoVolume(AT1.GetMaxVolume * 1,AT1.GetMaxVolume * 0) 'LEFT CHANNEL
End Sub
Sub TTS_HULP1
Dim Raf As RandomAccessFile
tts.Stop
tts.Speaks = SayText1
'This generates the WAV file, but does not speak:
Do While tts.IsSpeaking = False 'Start text with a comma to suppress short startup audio burst!
DoEvents
Loop
tts.stop
Raf.Initialize2(File.DirRootExternal,"wpta_tts.wav",True,True)
SampleRate=11025
ChannelConfig=AT1.Ch_Conf_Stereo
AudioFormat=AT1.Af_PCM_16
BufferSize=Raf.Size - 44 'RIFF header size is 44 bytes
Try
Dim Buffer(BufferSize) As Byte
AT1.Initialize(AT1.Stream_Music,SampleRate,ChannelConfig,AudioFormat,BufferSize,AT1.MODE_STATIC)
Catch
BufferSize=Raf.Size - 44 + 5622 'This work-around is needed because a (strange) buffersize error occurs when playing the same text a second time!
Dim Buffer(BufferSize) As Byte
AT1.Initialize(AT1.Stream_Music,SampleRate,ChannelConfig,AudioFormat,BufferSize,AT1.MODE_STATIC)
End Try
Raf.ReadBytes(Buffer, 0, BufferSize, 44)
AT1.WriteByte(Buffer, 0, BufferSize)
AT1.Play
Raf.Close
End Sub