Author: Joshua P7819
Jeff Overcash, TeamB member and the maintainer of the InterBase Express Components (IBX) for the past 13.5 years, has created a Delphi wrapper unit for Android text to speech functionality. Jeff has also created a simple demo example that allows you to input some text into a TMemo and hear the text spoken on your Android device. In a comment on the Delphi XE5 Android API Documentation forum, Jeff said he looked at the Java API source code to create the Delphi Text To Speech (TTS) unit. He also mentioned an Android text to speech tutorial article that helped him – http://www.androidhive.info/2012/01/android-text-to-speech-tutorial/.
Editor’s note: the site the writer originally linked to unfortunately appears to be defunct now. Here is an archived version of the article: https://web.archive.org/web/20171210142917/http://www.androidhive.info/2012/01/android-text-to-speech-tutorial/
The Delphi XE5 Android Text to Speech (TTS) API wrapper unit, Androidapi.JNI.TTS.pas, is included in the example uploaded to GitHub – https://github.com/jimmckeeth/FireMonkey-Android-Voice. The code that takes the text in the TMemo component and sends it to the Android TTS API is:
text := StringToJString(Memo1.Lines.Text);
tts.speak(text, TJTextToSpeech.JavaClass.QUEUE_FLUSH, nil);
Thank you Jeff for showing everyone how they can call Android API functionality from Dephi XE5. With Delphi XE5 you can always get to any OS APIs using the OCClass bridge (for iOS) and JavaClass bridge (for Android). The RTL contains a number of units that provide Delphi interfaces to iOS frameworks written in Objective-C. These units are scoped with iOSapi and are found in the /source/rtl/ios directory of your product installation. For Android, Delphi also includes a number of units for the interfaces to Android APIs with the unit name scope of Androidapi and are found int he /source/rtl/android directory of your installation.
Another simple example that shows you how to use the Objective-C bridge (OCClass) and Java Bridge (JavaClass) to call into the OS is the DeviceInfo mobile code snippet you can find as part of the install at C:UsersPublicDocumentsRAD Studio12.0SamplesMobileCodeSnippetsDeviceInfo.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Is it possible to download the code? (please) the link is broken
Hi Urbano – the code got moved to GitHub. I’ve updated the article to point to the new location – you can download it there. 🙂
Thank you very much engineer IAN, however this link is still broken: http://www.androidhive.info/2012/01/android-text-to-speech-tutorial/. could you update it? please
Ah I see. Sadly it looks like that particular site is no longer functioning. The article referenced is from January 2012, so it’s been a few years!
Luckily, we can use the Internet Archive to view a copy of how the page appeared back then: https://web.archive.org/web/20171210142917/http://www.androidhive.info/2012/01/android-text-to-speech-tutorial/
I hope this helps.