![]() This method is asynchronous and returns immediately while the text is spoken in the background. If the engine was already speaking some text, then the current speech will be terminated. To speak some text, just call the Speak method and supply the text to speak. Property OnSpeechFinished: TNotifyEvent read _GetOnSpeechFinished write _SetOnSpeechFinished Property OnSpeechStarted: TNotifyEvent read _GetOnSpeechStarted write _SetOnSpeechStarted Property OnAvailable: TNotifyEvent read _GetOnAvailable write _SetOnAvailable Property Available: Boolean read _GetAvailable The text-to-speech API is defined in an interface called IgoTextToSpeech (in the unit Grijjy.TextToSpeech):įunction Speak(const AText: String): Boolean ![]() ![]() For the text-to-speech library we use the “object interface” approach as discussed in that post. In our blog post about Cross Platform Abstraction we presented different ways to abstract platform-specific API differences. At the end of this post, you should be able to add other features yourself. To keep the size of this post somewhat manageable, we only support the most basic text-to-speech features: speaking some text (using the default voice and settings) and stopping it. On non-Android platforms, we just fire this event immediately after construction. This means that we have to add some sort of notification to the engine to let clients know that the engine has initialized. On Android though, you have to wait until the engine has fully initialized in the background before you can use it. For example, on all platforms except Android, you can start speaking immediately after you create the text-to-speech engine. Or you can have a combination of both.Īlso, there may be some features (or issues) on one platform that also affect the API for other platforms. Or you can choose to support more features which either do nothing on certain platforms or raise some kind of “not supported” exception. You can choose to go for the lowest common denominator approach and only expose those features that are supported on all platforms. Other platforms may not support some of these features, or only in an incompatible way. When it comes to text-to-speech, some platforms support choosing a voice, changing the pitch or speech rate, customize pronunciation with markup in the text to speak etc. A specific feature may be supported on one platform, but not on another. Choosing a feature setĪ common issue with abstracting platform differences is that you must decide on a feature set. If you are only interested in the end result, then you can stick to the first part of this post and bail when we get to the implementation details. You can find the source code on GitHub as part of the JustAddCode repository. It works on Windows, macOS, iOS and Android. In particular, we present a small Delphi library to add cross platform text-to-speech to your app. This post is a small exercise in designing a cross platform abstraction layer for platform-specific functionality.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |