CONVA Search

Adding an accurate, multilingual Voice Search capability into your app

By now you must have configured and published your Assistant via the Slang Console and also maybe customized it as required. Congratulations! :) If you have not already done that, you can do so by following the instructions here.

Let's start coding!

For testing, we recommend using a physical device instead of an emulator because most emulators don't work well with microphones.

1. Configure the build system

The first step is to update the app's build system to include Slang's Retail Assistant SDK.

Add the Slang dependency to your Gradle files

Add the path to the Slang maven repository to your top-level Gradle file

# Add this to your top-level Gradle file

allprojects {  
    repositories {    

        maven { url "https://gitlab.com/api/v4/projects/25706948/packages/maven" }  
    }
}

Add the Slang Retails Assistant dependency to your app's Gradle file

# Add this to your app's Gradle file

dependencies {  

    implementation 'in.slanglabs.assistants:slang-retail-assistant:8.+'
}

2. Code integration

2.1 Initialization

The next step is to initialize the SDK with the keys you obtained after creating the Assistant in the Slang console.

The recommendation is to perform the initialization in the onCreate method of the main Activity where the search bar will be visible.

// Your main activity class 

protected void onCreate(Bundle savedInstance) {  
    ...
    AssistantConfiguration configuration = new AssistantConfiguration.Builder()    
        .setAPIKey(<API Key>)    
        .setAssistantId(<AssistantId>)
        .build();  
    SlangRetailAssistant.initialize(this, configuration);
}

2.2 Show Slang CONVA Trigger

Trigger refers to the UI element appearing on the screen, which the end user will click to bring up the Assistant.

The most common way to add Voice Search into apps, i.e. adding the trigger (which by default is a microphone icon) is either inside or next to the search bar.

Add the below XML element to your UI definition in the place where you want the trigger (the default image is a microphone icon) to appear (usually next to the search bar).

<in.slanglabs.assistants.retail.SlangConvaTrigger
  android:id="@+id/your_id"
  android:layout_width="45dp"
  android:layout_height="45dp"
/>

Once the app has integrated the trigger, the next step is to register a callback to handle the voice search commands from the end user. CONVA will process the utterance spoken by the end user and if it detects that the user is trying to do a valid search operation, it will invoke the registered callback with the search string. Note that the search string will always be in English irrespective of which language the end user spoke it in. CONVA will automatically translate other language inputs into English.

SlangRetailAssistant.setOnSearchListener(
    new OnSearchListener() {
        @Override
        public void onSearch(SearchInfo searchInfo, final SearchUserJourney searchUserJourney) {
            String searchString = searchInfo.getSearchString();
            // Fire the actual search using the searchString
        }
    }
);

Or, utilize the onSearch callback provided by the SlangConvaTriggerView component.

SlangConvaTrigger convaTrigger = findViewById(R.id.your_id);

convaTrigger.setOnSearchListener(
    new OnSearchListener() {
        @Override
        public void onSearch(SearchInfo searchInfo, final SearchUserJourney searchUserJourney) {
            String searchString = searchInfo.getSearchString();
            // Fire the actual search using the searchString
        }
    }
);

Last updated