Android Chat

The Teneo Android Chat app is an example Android chat app for Teneo. It uses the Teneo Android SDK and supports Google's Speech Recognition as well as Text to Speech. Conversations are displayed in a user-friendly chat interface.

Screenshot of app

The project demonstrates the following concepts:

  • Text input using Google Speech Recognition as well as manual text entry.
  • Spoken responses using Google Text to Speech (TTS).
  • A message adapter that handles tasks related to the Chat UI.
  • Usage of the TIE SDK to interact with the Teneo engine.

You can find the source code of this project on Github.

Prerequisites

  • You need to know the Teneo engine url of a published bot.
  • Android Studio 3.4 or later.
  • Android 6 Marshmallow (API 23) device, or better. (Recommended)

Installation

  • Clone the repository from Github.
  • Point the app at your bot's Teneo engine by setting the following variables in the ChatActivity.java class:
    • baseUrl, the base url of your engine, for example https://skynet-4fe77f.bots.teneo.ai
    • solutionEndpoint, the path or endpoint of your engine, like /longberry_baristas_0x383bjp5a8e6tscbjd9x03tvb

Project details

TIE SDK connectivity.

This dependency in the app/build.gradle file enables the app to use the TIE SDK and communicate with the Teneo engine:

implementation 'com.artificialsolutions.tie-sdk-android:tie-sdk-android:1.0.2'

The onCreate method of the app initializes, among other things, the TieApiService

Within this app, a text can be sent to Teneo Engine anytime, with this helper method:

sendInputToTiE(String text, HashMap<String, String> params)

This project follows TIE SDK connectivity guidelines which are fully detailed in tie-api-example-android example.

Speech Recognition

This project implements Google's Android native Speech Recognizer, RecognizerIntent. The method launchGoogleVoice initializes RecognizerIntent with parameters such as Language, number of results, confidence scores, and is called from the microphone button's XML code in activity_chat.xml It also stops any Text to Speech playback before launching the Speech Recognizer.

Final Speech Recognition results are received at the onActivity callback, sent to Engine as text with consumeASRresults(int resultCode, Intent data).

The speech recognition language is customizable. In this project, the recognition language is set to UK English with asrIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en_GB").

Text to Speech

Text to Speech (TTS) is implemented with Android's native TTS. The object googleTextToSpeech within the project is the center of voice synthesis, and is initialized, launched and released throughout the lifecycle.

In this project, the method saySomething(String text) speaks out loud the bot responses received from Teneo Engine. Localized TTS language is customizable. In this project, for example, TTS language is set to UK English with googleTextToSpeech.setLanguage(Locale.UK).

Chat UI

Chat UI is implemented in the MesageAdapter class. You may customize message bubble color, avatar, and sender in that class, if you wish.

In the project, user input from the ASR or the keyboard are posted into the chat window with addMessageToChatWindow(String messageText, String color, boolean isUser). Likewise, messages incoming from engine are also posted to the Chat Window.

Was this page helpful?