Build a Watson-Powered Mobile Chatbot
Build a Watson-Powered Mobile Chatbot
Learn to build a Watson-powered speech synthesizer mobile chatbot using Mobile Services, Watson Conversation, and Text to Speech in IBM Bluemix.
Join the DZone community and get the full member experience.Join For Free
Before building the chatbot, let us first understand the technology that is powering this chatbot.
IBM Bluemix is a Platform As A Service cloud offering from IBM. It enables developers to quickly create, deploy, and manage applications on the cloud by abstracting other layers.
Watson is a cognitive system that can understand all forms of data, interact naturally with people, and learn and derive insights out of it, at scale. Watson is available as a set of open APIs and SaaS products.
Watson Conversation can help you create an application that can understand the intent behind natural language input and simulate a conversation between humans.
Text to Speech converts written text into natural sounding audio in a variety of languages and voices, which also has an expressive element that lets you indicate a speaking style of good news, apology, or bad news.
To build this chat bot, you will have to configure Watson Conversation Service and Text to Speech in IBM Bluemix and export starter code from IBM Bluemix to Android Studio.
Configure Watson Conversation Service
Log in to www.bluemix.net and click on "catalog" to create and configure Watson Conversation Service:
Enter a service name (or leave it as the default) and then click on "create." Please note that I have left it as "unbound." You can either leave it as "unbound" or bind it to an app that you have created on Bluemix.
Click on "Launch tool" to open the Watson Conversation Service Tool:
In Workspaces, click on "create" to create a new workspace:
Enter a name and click on "create."
Check the video below to create workspace, intents, entities, and dialogues:
Configure Text-to-Speech Service
Click on "catalog" to create and configure Text to Speech service:
Enter a service name (or leave it as default) and then click on "create."
Configure Mobile Services
Step 1: Go to this URL: https://console.ng.bluemix.net/developer/getting-started/ and click on "create project" to get starter code.
Step 2: Click on "mobile app" and click on "next."
Step 3: Filter by Android and then click on Watson Conversation and click on "next."
Step 4: Enter a Project Name and select platform as Android and click on "create."
Step 5: Click on "Get the Code."
Step 6: Click on "Generate Code."
Step 7: Download the generated code.
Step 8: Unzip the generated code and then Import it into Android Studio (any latest version of Android Studio).
Step 9: In the build.gradle(app), insert dependency:
Step 10: In res>values>watson_credentials.xml, enter the Watson Conversation password, Username, Workspace ID, and insert last the two lines with Text to Speech Username & Password. Go to Bluemix Dashboard and open Watson Conversation Service & Text to Speech Service to get the username and password! (as shown below)
<resources> <string name="watson_conversation_password">XXXXXXXXX</string> <string name="watson_conversation_username">XXXXXXXXXXXXXxxxxxxxxxxxxxxxx</string> <string name="watson_conversation_workspace_id">XXXXXXXXXXXXXXXXXXXXXXXXXXX</string> <string name="watson_tts_username"xxxxxxXXXXXXXXxxxXXXXXXXXXXXX</string> <string name="watson_tts_password">xxxxXXXXXXXXxxxxxxx</string> </resources>
Step 11: Copy and paste the entire code in MainActivity.java (Android Studio) from here (with Text to Speech Integration).
This is the code that will invoke Text to Speech API:
TextToSpeech tts = initTextToSpeechService(); StreamPlayer sp = new StreamPlayer(); sp.playStream(tts.synthesize(texttoSpeech, Voice.EN_MICHAEL).execute());
After completing all the steps, run the app in Android Studio to hear Watson speaking!
Published at DZone with permission of Riya Roy , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.