Developing applications with Google TTS
In order to avoid repeating the code in several places, and to be able to focus on the new parts as we progress to more complex applications, we have encapsulated the most frequently used TTS functionalities into a library named TTSLib
(see sandra.libs.tts
in the source code), which is employed in the different applications.
The TTS.java
class has been created following the Singleton design pattern. This means that there can only be a single instance of this class, and thus an app that employs the library uses a single TTS object with which all messages are synthesized. This has multiple advantages, such as optimizing resources and preventing developers from unwittingly creating multiple TextToSpeech
instances within the same application.
TTSWithLib app – Reading user input
The next figure shows the opening screen of this app, in which the user types a text, chooses a language, and then presses a button to make the device start or stop reading the text...