Android library
Documentation for the Flowstorm Android library
The Flowstorm Android library was created to allow easy creation of voice-enabled applications or adding support for the Flowstorm communication into custom applications. This page describes how to import and use the library.
Pre-requisites
First, you need to define the repositories for the dependencies. Put the definition in your project's settings.gradle
file:
The library is imported by inserting the following code into your app's build.gradle.kts
file:
Or if you use the build.gradle
file with the Java syntax:
The attribute isTransitive
is required because the library is distributed in the AAR format which does not include the dependencies the library requires. The excludes serve to avoid "duplicate classes" error.
If you encounter the error
try adding these dependencies:
Speech recognition
If you use the speech recognition function, you will need to obtain the user's permission to use the microphone. However, the library already includes the permission definition in its AndroidManifest
file and it asks the user at an appropriate time, before the ASR is needed.
Also, if the user has the "Google" application disabled on their phone, the ASR won't work.
Importing the library
Create an Application
file in your root package and make it extend the MainApplication
class.
The initializeApp()
function must be called before the super.onCreate()
function. If you switch them, the app could overwrite your custom preferences (described in the Configuring the client section).
Next, create an entry activity:
Define the application and the activity it in the AndroidManifest.xml
file with
Running an activity from the library
This example shows how to start a conversation activity in chat mode, with default settings. For more info about available activities, see the Library contents section. In your activity, simply add
Upon reaching this block of code, the conversation with Flowstorm will start. You can, for example, add it to your onCreate
function:
Configuring the client
The initializeApp()
function takes an argument customDefaults
of type FlowstormDefaults
. By creating your class which extends that one, you can configure the client for your needs. This is the structure of the class, along with the default parameters:
appKey (String) - The key to your conversational application. It can be obtained in the Flowstorm Studio
language (String) - The language which will be used in the speech recognition
coreHost (String) - The URL of the Flowstorm backend
personaListUrl (String) - The URL for your persona configuration. For the application to display a picture and a name of a persona it needs this configuration file where the mapping from voice to persona is defined. If you use custom voices, you can download the file from the default URL, extend it with your own personas, upload it elsewhere and link it here.
name (String) - this will be used in the
clientType
field during communicationpreferredInteractionModel (PreferredInteractionModel) - If the conversation is launched through MenuActivity, but the dialogue does not start with the
#modules
command, this will be the interaction mode used.autoStart (Boolean) - sets whether to start the conversation automatically by sending
#intro
inputclientVersion (String) - whether to communicate using socket (1) or using HTTP (2)
sentryForceLogging (Boolean) - if
true
, the Sentry module (if enabled) will log all events. If false, only 10% of events will be logged. More about Sentry in the Logging section.debugMode (Boolean) - Enables certain UI elements
enableAvatar (Boolean) - If
true
, starts the application with the 3D avatar stream enabledstreamHost (String) - The URL of the avatar stream
iceServerUri (String) - The URL of the STUN server
The most important/useful parameters are probably appKey
, language
and name
.
Library contents
The main features of the library are the two conversational and three other activities/screens. The activities are self-sufficient, the library contains everything to make them work - dependency definitions, user permission requests, layouts (and other resources), and imported classes.
Voice activity
The first conversation screen, voice activity implements the "voice mode". The layout is designed to resemble a phone call. The red button ends the conversation. The speaker button turns off and on audio output. The bubble button turns on and off subtitles, both for the persona and for the user. The microphone icon will flash green when the user is supposed to speak, the persona image will flash white when the persona speaks.
Chat activity
The other conversation screen chat activity implements the "chat mode". The layout is designed to resemble an instant messaging application. The messages from the persona will appear on the left. The user can type their message using the input field, then send them.
Menu activity
A screen that displays a selection of personas. Swiping the upper part changes between personas while swiping the lower part changes between topics the persona knows (if there is more than one). Clicking the phone receiver starts the voice mode, clicking the speech bubble starts the chat mode. The user can also make the persona introduce themselves by clicking the video. The buttons in the upper part of the screen lead to settings (left) and profile (right).
Profile activity and settings activity
The profile activity is a screen where the info about the user is displayed, in the settings, the user can configure the app.
Speech recognition
Each class of the library can of course be imported on its own. To name one example, the importing application can use the Android ASR in the class FlowstormSpeechRecognizer
. To initialize it, you need to pass a RecognitionListener
- for that, you can use the FlowstormRecognitionListener
, or extend it. After that, call the createSpeechRecognizer()
function. The function returns a boolean value which indicates whether the creation was successful. Afterwards, call startListening()
to begin the ASR. You can also interrupt it by calling stopListening()
.
Service
You can also make use only of the communication component, which is located in the Service
class. To instantiate it, you need a pass a UI callback object and a configuration object. You can use the Callback
class provided but for that, you will need a class that will implement the ClientUI
interface and will display the content received from the server on the screen. Alternatively, you can provide your class implementing ClientCallbackV1
. This is how you create the service:
Communication is started with
To send input from the user, add
Logging
The library supports two methods of logging: Firebase and Sentry.
Firebase
To make the library use Firebase, you need to enable the Firebase support in your application. That is described here. Then, you need to pass a FirebaseAnalytics
object to the initializeApp()
function.
You also need to provide your google-services.json
file.
Sentry
To enable Sentry logging, add the following lines to the AndroidManifest.xml
file under the <application>
tag:
Notifications
The library contains support for receiving Firebase notifications. First, add the dependency to your project-level build.gradle
file:
Then, add a plugin to your module-level build.gradle
file:
Lastly, add this snippet to your AndroidManifest.xml
file:
Similarly to the Firebase logging, you will need a google-services.json
file.
Styling
The library allows changing strings, themes, colors, images and even layouts. Any resource can be overwritten by a file or element of the same name in your application. For example, to change the default loading animation, you need to provide a drawable file named loading_spin_anim.xml
. You can check the original names in the library files.
Themes
The default theme for the library is called Theme.Flowstorm
. You can inherit from it and change certain colors.
Then, you need to replace the theme in your AndroidManifest.xml
file:
Colors
Strings
Layouts
In theory, you can change even the layouts of the activities, if you provide a file named e.g. voice_activity.xml
. However, your layout would need to contain elements with all ids which are present in the library layout, or else the application would crash after trying to access UI elements whose elements would be missing.
Custom settings options
Koin modules
The library uses the Koin library for module injection. Add the dependency to your build.gradle.kts
file using
Custom preferences
You can override the Preferences
object to add your config options:
They should be loaded into Koin as a module in your Application
's onCreate
function:
If you have your own Koin modules, you can also add them using the loadKoinModules
function. Also, you should load default values from your Preferences
to the Android SharedPreferences
:
Last updated