B4A Library ICOSTextToSpeech

ICOSTextToSpeech v1.90.

the zip include:

1 - Demo.
2 - Library.
3 - license.


ICOSTextToSpeech
Author:
Giuseppe Salvi
Version: 1.9
  • ICOSTextToSpeech
    Events:
    • Ready (Success As Boolean)
    Methods:
    • ChangeDefaultLanguage (title As String, title1 As String)
      Programmatically change the default language of your phone with that choice yourself.
    • InitializeTTs (EventName As String, lang As String)
      Initialize the object
    • IsSpeaking As Boolean
      Return true if tts is Speaking
    • LanguageSettings
      Go into the language settings.
    • Pause
      Pauses playback.
    • ReadAndSpeakSMS (title As String, title1 As String, title2 As String, title3 As String, title4 As String)
      Read And Speak SMS
    • Resume
      resumes playback.
    • SetLanguageToSpeak (title As String, title1 As String)
      Sets the text-to-speech language.
    • ShutDown
      Release the Engine
    • ShutUp
      Reinitialize the Object
    • Start
      Starts playback from the beginning.
    • Stop
      Stops playback.
    • WriteAndSpeakText (title As String, title1 As String, title2 As String, title3 As String, title4 As String)
      Write and speak some text.
    Properties:
    • DefaultEngine As String [read only]
      Gets the package name of the default speech synthesis engine.
    • EngineByPackageName As String [write only]
      This method was deprecated in API level 14. This doesn't inform callers when the TTS engine has been initialized.
      can be used with the appropriate engine name.
      Also, there is no guarantee that the engine specified will be loaded.
      If it isn't installed or disabled, the user / system wide defaults will apply.
    • PitchToSpeak As Float [write only]
      Sets the speech pitch for the TextToSpeech engine.
    • RateToSpeak As Float [write only]
      Sets the speech rate.
    • Speaks As String [write only]
      Synthesizes the given text to a file using the specified parameters.
    • Version As String [read only]
      Author and Version of the library
 

Attachments

  • ICOSTextToSpeech.zip
    62.8 KB · Views: 515
  • ICOSTextToSpeech v1.80.zip
    77.7 KB · Views: 309
  • ICOSTextToSpeech v1.90.zip
    78.1 KB · Views: 524
Last edited:

RadCoder

Member
Licensed User
Longtime User
thanks but

in the dox it says copyright v1.3. What is the copyright on this lib?
 

rbsoft

Active Member
Licensed User
Longtime User
I just tried you TextToSpeech library. Ecellent.
Thank your very much for it.

Rolf
 

lonleystar

Well-Known Member
Licensed User
Longtime User
1. Is it maybe possible to add a "pause speaking" and "resume speaking" feature to your nice ICOS TTS library?
2. Ditto, to add an event that reports back which word (or sentence) currently is being spoken?
Thank you very much.

Hi, sorry if answer to late, yes I'll do it. Tanks to U.
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Hello Lonelystar
I appreciate very much that you intend to add the requested features to ICOS TTS. I do hope you will succeed!
Do you have any idea when it will be ready?
Hi Rick, I testing it till tomorrow I'll upload. Give me just this evening to test.

Tanks in advance.
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi guys, the ICOSTextToSpeech is update to v1.80 what's new:

the zip include:

1 - Demo.
2 - Library.
3 - license.

***********************New********************************

Start - Starts playback from the beginning.

Stop - Stops playback to be again heard it from the beginning with Start.

Pause - Pause playback.

Resume - Resume playback exactly from where playback has been stopped.

ShoutDown - Release the Engine. - updated.

ShoutUp - Reinitialize the Engine.

*********************Changed******************************

Speaks instead of Speaking - Synthesizes the text to a file and play it.

EngineByPackageName intead of SetEngineByPackageName.

DefaultEngine instead of GetEngineByPackageName.

ChangeDefaultLanguage

WriteAndSpeakText

ReadAndSpeakSMS

SetLanguageToSpeak

they have changed to:

tts.Speaks = "Hi this is a text message"

tts.ChangeDefaultLanguage("Change Default Phone Language","Exit")

tts.WriteAndSpeakText("A Simple Write and Speak","Speak","Clear","Stop","Exit")

tts.ReadAndSpeakSMS("A Simple Sms Reader and Speak","Read All Sms","Update Sms","Stop Speaking","Exit")

tts.SetLanguageToSpeak("Language Selector","Exit")


I hope that this new version, it's to your liking.
 

lonleystar

Well-Known Member
Licensed User
Longtime User
:) Hello Lonelystar. This is very good news! I have tried it a moment ago. The pause and resume that I requested work excellent. However, the short 2-line demonstration text in your sample project on average takes more than 12 seconds to load! This is far too long. The standard B4A TTS module takes a fraction of a second. What can be done about that?

Furthermore I cannot set the TTS to Dutch language with the "SetLanguageToSpeak button (crucial for my app).

Also I did not read anything about an event that reports back which word or phrase the TTS is reading at any moment. Are you still planning to make that? Please, please do so.
I'll make a donation then.


Hi Rick, there is no way to pause and resume whit the TTs engine but the new TTs is based on MediaPlayer it Synthesizes the text to a file and play it. that's why take a moment to speak.


P.S.
With the old library if U use PlaySilence between the words U get pause but there is no way to resume.

Let me know.
 

lonleystar

Well-Known Member
Licensed User
Longtime User
OK, thanks for the info. I now understand how your library works. Unfortunately this solution is not quite the right way forward for me. My app has to speak any text within less than half a second (which it currently does, even if the length of the text is close to the 4000 character limit). I will now have to solve the pause/resume plus progress reporting problem by breaking up long texts into separate lines (based on full stops and/or comma's in the actual text) with on average about 30 words per line. Hopefully the TTS ready event will fire reliable enough on most devices in order to trigger the TTS to speak the next line.

I might try a compromise solution whereby the first line of a long text is spoken by the regular B4A TTS library and in the mean time your library is activated to create audio files for all subsequent lines. Please tell me in which directory your library stores these audio files and whether it are mp3 or wav files. It would be nice if I could chose this folder and file name(s) myself. How fast are these files created/recorded? I guess about twice as fast as while playing them back. I am worried that synthesizing a long text will still take far too long.

I do like the fact that your library can record speech to audio files. Well done!

Finally I strongly recommend to retain the original TTS functions in your library such that a developer can chose between directly sythesized speech or your new method of first recording the speech and then playing it. Dropping your original method in favour of what you have made now is not a step forward to my opinion. You can expect many developers to complain about the very slow response due to the time that is needed to first buffer the audio.

If you can make a reliable TTS-ready event (for the synthesized case) that would be great.


Hi Rick, the audio file is wav and is stored in the sdcard.

P.S.

As I say in the post above there is no way to pause or resume with the original TTs.
Anyway I'll implements again the old functions in the new library and also the event TTs-ready.


In wich city U living,
I lived a year in Ijmuiden, and I worked at Corus ex Hoogovens. I love that city and the locals have made me feel like I was at my house.
 
Last edited:

lonleystar

Well-Known Member
Licensed User
Longtime User
I live near The Hague. Indeed IJmuiden is a very nice town. The view towards Corus (now called "Tata steel" due to its new Indian owner) accross the Noordzee kanaal is spectacular, especially at night (with all the lights, steam and fire plumes).
About your TTS: Can you please make a reliable (!) TTS_ready event that fires after a text has been spoken?
Hi Rick, yes I'll add it.
 

AlpVir

Well-Known Member
Licensed User
Longtime User

lonleystar

Well-Known Member
Licensed User
Longtime User
I have found the WAV file that the ICOS TTS generates: Apparently it is called "wpta_tts.wav" and is located in the root on the SD-Card. Can you please add a feature whereby the volume of the left and right audio channel can be set separately?! This should be possible because you stated that your library uses a built-in mediaplayer.
I need it for a GPS navigator for blind people that gives separate spoken information in the left and right ear of the user. Thank you in advance.

As a work-around I am currently using this code:
B4X:
tts.Speaks = ", Hello how are you"
Do While tts.IsSpeaking = False
  DoEvents
Loop
tts.stop

This generates the aforementioned WAV file but does not speak the text. The comma is needed to suppress a short burst of audio that occurs when your library attempts to start to speak. Playing the WAV file either via the left or the right audio channel is achieved with the audiotrack library. Here is my full working project:
B4X:
#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

I tried to an alternative solution by playing the WAV with the mediaplayer library but for some (unexplainable) reason setting the left and right volumes differently does not work.



Hi Rich, Sonday I fix my computer I had problems with the computer reseller.

Anyway I'm back and I'll fix all plugins.

Sorry for the inconvenience.
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi Lonelystar,

Good to hear from you! Can you please include a mode in your library to make ICOS-TTS speak in either the left or right audio channel. My solution in #21 works, but I think it will work faster if you integrate something like this into your source code. By the way: how do you intercept the TTS audio output and store it in a WAV file? You somehow have managed to make a bridge between the TTS audio output and the audiorecorder, which some people have claimed not to be possible (in other threads). Erel stated that it is only somehow possible via the microphone, but your solution results in excellent audio quality.

Other question: do you know of a way to play a WAV file (or TTS output) via het phone audio channel? I want to make a phone answering machine. You seem to know a lot about how to route or intercept audio.


Hi Harris, sorry for my absence. Let me give a look for this solution sound nice your idea.

P.S.
Remember if you don't see any update.
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi @lonleystar , thanks for the wonderful library.

1. I kindly request you please add an option in your library to speak the text without synthesizing it to a file first.
2. Please also add functionality to save the wav file using a name of your own specifications in your own directory.
3. Willing to donate $10 for that!


Hi my work takes me long time away with shifts anyway I will.
 

SMOOTSARA

Active Member
Licensed User
Longtime User
HI lonleystar
thank you
This is the most complete library, but it just has a problem
The new version of Android requires read and write messages and a memory card
Is it possible to remove this access?
 
Top