[Huawei Developers] Freemind R:
Article Introduction

In this article we will show how to integrate Huawei ASR ML Kit and Site Kit to search and show all the nearby restaurants on the map using Huawei Map Kit.

1. Huawei ML Kit (ASR)

Automatic speech recognition (ASR) service can convert speech (no more than 60 seconds) into text in real time. Currently, Mandarin Chinese (including Chinese-English bilingual speech), English, French, German, Spanish, and Italian are supported. This service is widely used in social networking, conferencing, and shopping apps. For example, when it is inconvenient for users to manually enter text to search for information, they can speak a keyword for search, to further improve search efficiency.

2. Huawei Site Kit

With Site Kit, your app can provide users with convenient and secure access to diverse, place-related services, and therefore acquire more users. Site Kit provides the following core capabilities for you to quickly build apps with which your users can explore the world around them:

Article Introduction

3. Huawei Map Kit

Map Kit is an SDK for map development. It covers map data of more than 200 countries and regions, and supports hundreds of languages. With this SDK, you can easily integrate map-based functions into your apps. Map Kit uses the WGS 84 GPS coordinate system, which meets most map development requirements outside China, including:

Map display: Displays buildings, roads, water systems, and Points of Interest (POIs).

Map interaction: Controls the interaction gestures and buttons on the map.

Map drawing: Adds location markers, map layers, overlays, and various shapes.

Pre-Requisites

Before we jump into the development, we have to integrate HMS Core in our project. Please follow the HMS Core Integration link mentioned in the References section of this article to integrate HMS Core. After integrating HMS Core, make sure you enabled Site Kit, Map Kit and ML Kit in the AGConnect Console and added the agconnet-service.json file in the app level directory.

Step 1: Add Dependencies & Permissions

1.1: Add the following dependencies in the app level build.gradle file:

dependencies {

// ... Below all the previously added dependencies

// Huawei Automatic speech recognition ML Kit
implementation 'com.huawei.hms:ml-computer-voice-asr:2.0.3.300'
implementation 'com.huawei.hms:ml-computer-voice-asr-plugin:2.0.3.300'

// Huawei Scan Kit
implementation 'com.huawei.hms:site:5.0.3.302'

// Huawei Map Kit
implementation 'com.huawei.hms:maps:5.0.3.302'

// Custom Runtime Permissions lib
implementation 'com.nabinbhandari.android:permissions:3.8'

}

1.2: Add the following permissions in the AndroidManifest.xml:

<!-- General Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Required permission for ASR ML Kit -->
<!--Write permission-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--Read permission-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!--Record permission-->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!--Network status obtaining permission-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--Wi-Fi status obtaining permission-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<permission
android:name="com.huawei.mlkit.asr.permission"
android:label="ASR" />

Step 2: Add Layout Files

2.1: Add the following view_search.xml layout file in the layout folder of the res. This is the layout view of Custom Search bar which is used as Action Bar in the application, contains two views i-e searchCloseView and searchOpenView.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/colorAccent">

<RelativeLayout
android:id="@+id/searchClosedView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/colorPrimary">

<TextView
android:id="@+id/txtView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@android:color/white"
android:layout_toStartOf="@id/btnOpenSearch"
android:text="@string/app_name" />

<Button
android:id="@+id/btnOpenSearch"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:background="@drawable/ic_search" />

</RelativeLayout>

<RelativeLayout
android:id="@+id/searchOpenedView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="4dp"
android:background="@drawable/rounded_corner_background"
android:visibility="invisible">

<Button
android:id="@+id/btnCloseSearch"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:background="@drawable/ic_close" />

<EditText
android:id="@+id/editTextSearch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:textSize="13sp"
android:maxLines="1"
android:inputType="text"
android:imeOptions="actionDone"
android:hint="@string/search_hint"
android:layout_toStartOf="@id/btnVoiceSearch"
android:layout_toEndOf="@id/btnCloseSearch" />

<Button
android:id="@+id/btnVoiceSearch"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/btnSendSearch"
android:layout_marginEnd="16dp"
android:background="@drawable/ic_microphone" />

<Button
android:id="@+id/btnSendSearch"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="16dp"
android:background="@drawable/ic_send" />

</RelativeLayout>

</FrameLayout>

More details, you can visit https://forums.developer.huawei.com/forumPortal/en/topic/0203409993972490187