November 3, 2016 | Written by: Marek Sadowski
Categorized: How-tos | Watson
Share this post:
This post describes how you can add Watson’s cognitive service to an Android app in under 10 minutes. The voice user interface is a great way to enhance the user interface of IoT devices, robots, or a voice-controlled vehicle. IBM Watson Text-To-Speech service is available from the IBM Bluemix catalog.
Note: If you haven’t done so already, please skim my prior post “Connect native Android app to Watson Sentiment Analysis in under 10 minutes” since it covers steps in more detail than in this post.
Overview of steps
Below is an overview of the steps:
- Create a typical Android application in Java
- Add the Watson lib: Watson-Developer-Cloud SDK for Java
- Instantiate the Bluemix Watson service and get the key token to it
- Add some code in your Android app to invoke the cognitive service
- Quick test of the app.
You’ll build a simple application with a submit button, an editable text field, and an output field. The video below shows the steps:
The results from the emulator:
Run the test to see if the fields work as planned and you see the debug
println in the console as well as in the ViewText field.
The entire code for the UI is shown below:
The following video covers the steps for connecting the UI with the Watson Text to Speech service:
Below is the code from the video:
And a quick screenshot of the editor upon completion:
The section of code invoking the Text to Speed service is excerpted below for easy reference:
TextToSpeech textToSpeech = initTextToSpeechService();
streamPlayer = new StreamPlayer();
That’s it! You are ready to run and hear the voice of IBM Watson!
Sign up for Bluemix. It’s free!
Please follow me on Twitter: @blumareks, and check my blog on blumareks.blogspot.com