Integrating Automatic Speech Recognition without Pickup UI in B4A Platform - Huawei Developers

Introduction
Automatic speech recognition (ASR) can recognize speech not longer than 60 Seconds and convert the input speech into text in real time. This service uses industry-leading deep learning technologies to achieve a recognition accuracy of over 95%. Currently, Mandarin Chinese (including Chinese-English bilingual speech), English, French, German, Spanish, and Italian can be recognized
Real-time result output
Available options: with and without speech pickup UI
Endpoint detection: Start and end points can be accurately located.
Silence detection: No voice packet is sent for silent part.
Intelligent conversion to digital formats: For example, the year 2020 can be recognized from voice input.
Follow all the steps mentioned in Basic Setup to start HMS integration on B4A Platform.
Refer to
https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201286424114350051&fid=0101246461018590361
Enable ML Kit in App gallery connect.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Creating Wrapper Class
1. Downloading the AAR Packages and JSON File
Sign in to HUAWEI Developer and download the AAR packages required.
2. Open AAR packages with rar tool and rename the class.jar and AndroidManifest.xml files. And save those jar file inside libs folder (It is recommended that the two files can be renamed consistently with the AAR package names.)
3. Copy required permissions in the <manifest> section in B4A IDE.
4. Copy all configurations in the <application> section.
5. Change ${applicationId} to $PACKAGE$.
6. Download the configuration file(agconnect-services.json) from App Gallery Connect
And Add the JSON File to the assets Folder of the AAR file as shown below.
B4A will automatically incorporate files in the assets folder of an AAR package to the assets folder of your main project.
Encapsulating Java Files Using SLC
1. Create Library as parent and then create bin, libs and src as subfolder in the project directory.
2. Develop java project inside the following path:
Choose Library Folder > src > b4x > asr > demo
3. Import the following two lines of code to each Java file.
Code:
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;
import anywheresoftware.b4a.IOnActivityResult;
4. Add necessary annotations to the ASR Java files.
Code:
@Version(1.0f)@ShortName("Asr")@DependsOn(values={"agconnect-core-1.0.1.300.aar",
"tasks-1.3.1.302.aar",
"network-common-4.0.2.300.aar",
"network-grs-4.0.2.300.aar",
"okhttp-3.12.0.jar",
"okio-1.15.0.jar",
"ml-computer-agc-inner-2.0.1.300.aar",
"ml-computer-cloud-base-inner-2.0.1.300.aar",
"ml-computer-commonutils-inner-2.0.1.300.aar",
"ml-computer-ha-inner-2.0.1.300.aar",
"ml-computer-grs-inner-2.0.1.300.aar",
"ml-computer-net-2.0.1.300.aar",
"ml-computer-voice-asr-plugin-2.0.1.300.aar",
"ml-computer-vision-cloud-2.0.1.300.aar",
"ml-computer-voice-asr-2.0.1.300.aar"
})
@Permissions(values={"android.permission.INTERNET",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.ACCESS_NETWORK_STATE",
"android.permission.RECORD_AUDIO",
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.CHANGE_WIFI_STATE",
"android.permission.ACCESS_WIFI_STATE",
"android.permission.CHANGE_CONFIGURATION",
"android.permission.WAKE_LOCK"})
More details, you can click https://forums.developer.huawei.com/forumPortal/en/topic/0203394430060880031

Very clear. Do you have a Repo with the code?

Related

Basic steps to follow to integrate HMS capabilities in B4A

More articles like this, you can visit HUAWEI Developer Forum​
Downloading the AAR Packages and JSON File
o Sign in to HUAWEI Developer and download the AAR packages required.
o AAR packages related to HMS Push kit is displayed as below
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Refer below link for the steps.
https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#0
Figure 1-2 Configuring app information in App Gallery Connect
Open AAR packages with rar tool and rename the class.jar and AndroidManifest.xml files. (It is recommended that the two files be renamed consistently with the AAR package names.)
Figure 1-3 Renaming files
Copy required permissions in the <manifest> section in B4A IDE
Figure 1-4 Permissions in the <manifest> section
Copy all configurations in the <application> section
Figure 1-5 All configurations in the <application> section
Change ${applicationId} to $PACKAGE$.
${applicationId} is the field for automatically obtaining the package name in Android Studio. Its counterpart on B4A is $PACKAGE$
Download the latest configuration file(agconnect-services.json) from App Gallery Connect
Figure 1-6 Downloading the JSON file
Adding the JSON File to the assets Folder
Figure 1-7 Adding the JSON file
B4A will automatically incorporate files in the assets folder of an AAR package to the assets folder of your main project.
Encapsulating Java Files Using SLC
Configure the Java project.
SLC wraps Java project and adds it to the B4A library. For demonstration purposes, we have created a Java project.
It is recommended that you name the first folder b4x in src. Otherwise, the library generated with SLC may not function properly.
Figure 1-8 Java project
Develop the Java project.
Name the Java files based on the src path.
Figure 1-9 Naming the files based on the src path
Import the following two lines of code to each Java file
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;
Add necessary annotations to the Java files
Figure 1-10 Example annotations
Modify the context.
B4A does not recognize the Context class. Therefore, when parsing a class that contains the @version(1.0f) annotation, it will report an error if a method of the class has referenced Context. In this case, you need to change Context to the B4A object BA
Figure 1-11 Context example
The following describes the @Events annotation.
This annotation is used to report specific events in the Java method to the listener registered on B4A.
The code on B4A is also required to implement this function.
Take the getPushToken method in PushWork as an example. If you want to pass the push token in the Java method to a listener on B4A, do as follows:  
Set a listening event on B4A.
Figure 1-12 Setting a listening event
Add the @event annotation to the Java files. The code is shown in the following figure.
The value of NewToken in the red box must be the same as xxxx of Listener_xxxx in the listening event name added to B4A in the previous step.
Call the ba. raiseEventFromUI method in the method that needs to report the push token. The code is shown in the following figure.
Event reporting
Select the project folder, define the library name, and click Compile
Figure 1-14 Compilation successful
Select the Addition folder and add AAR packages to it.
Figure 1-15 Tools-Configure Paths
Go to Project > Build Configurations and change the B4A project package name to the project package name configured in App Gallery Connect
Figure 1-16 Changing the B4A project package name
Go to Tools > Private Sign Key and select the SHA256 signature file specified in AppGallery Connect as the B4A project signature file
Figure 1-17 Configuring the signature file
Declare MainApplication in the Manifest file.
The path of MainApplication must also be the path to the src folder where MainApplication is located.
Add the #AdditionalJar field to Project Attributes to reference the AAR packages
The value of #AdditionalJar is the name of the AAR package (with a file name extension) in the Addition folder

HUAWEI Drive Kit Development Process (Part*2)

More information like this, you can visit HUAWEI Developer Forum
​
SDK Description
To integrate HUAWEI Drive Kit into your app, you will need to integrate both the HMS SDK and the Drive SDK. The HMS SDK provides sign-in and authentication information, while the Drive SDK provides the capability of managing users' files in Drive.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Integrating the Drive SDK and HMS SDK
If you are using Android Studio, you can integrate your Drive SDK and HMS SDK by using the Maven repository. Before you start developing an app, integrate both the Drive SDK and HMS SDK into your Android Studio first.
1. Add the AppGallery Connect configuration file of the app to your Android Studio.
a. Sign in to AppGallery Connect and select My projects.
b. Find your project from the project list and click the app on the project card.
c. On the Project Setting page, click agconnect-services.json to download the configuration file.
d. Copy the agconnect-services.json file to the app root directory.
2. Configure the Maven repository address for the HMS SDK.
a. Open the build.gradle file in the root directory of your Android Studio project.
3. Add build dependencies.
a. Open the build.gradle file in the app directory.
5. Define multi-language settings.
By default, your app supports all languages provided by the HMS SDK.If your app uses all these languages, skip the operation procedure in this section.
If your app uses only some of these languages, follow the operation procedure in this section to complete the required configuration.
Open the build.gradle file in the app directory of your project.
Go to android > defaultConfig and add the resConfigs configuration. en (English) and zh-rCN (Simplified Chinese) are mandatory languages. If your app only supports English and Simplified Chinese, the configuration is as follows:

HMS AGC CloudStorage Kit Integration in B4A Platform

Overview
Cloud Storage Service allows you to store high volumes of data such as images, audios, and videos generated by your users securely and economically with direct device access. The service is stable, secure, efficient, and easy-to-use, and can free you from development, deployment, O&M, and capacity expansion of storage servers.
In this article, we can learn the following:
Create an app and configure its information in AppGallery Connect.
Use B4A IDE to integrate the HUAWEI HMS Cloud Storage SDK into your app and develop storage-related functions.
Build and demonstrate a demo app.
Manage files on the Cloud Storage page in AppGallery Connect.
For details, refer to
Free IDE for B4X Native Android Development | B4A
B4A includes all the features needed to quickly develop any type of Android app. B4A is used by tens of thousands of developers from all over the world, including companies such as NASA, HP, IBM and others.
www.b4x.com
Creating Wrapper Class
1. Download the following AAR package inside addition folder in your project directory.
HMSSDK AGConnect:
https://developer.huawei.com/repo/c...t-auth/1.4.1.300/agconnect-auth-1.4.1.300.aar
https://developer.huawei.com/repo/c...t-core/1.4.0.300/agconnect-core-1.4.0.300.aar
https://developer.huawei.com/repo/c...age/1.3.0.300/agconnect-storage-1.3.0.300.aar
https://developer.huawei.com/repo/c...e-core/1.4.1.300/datastore-core-1.4.1.300.aar
https://developer.huawei.com/repo/c.../1.4.1.300/datastore-annotation-1.4.1.300.jar
https://developer.huawei.com/repo/c...https/1.4.1.300/agconnect-https-1.4.1.300.aar
https://developer.huawei.com/repo/c.../1.4.1.300/agconnect-credential-1.4.1.300.aar
HMSSDK Base:
https://developer.huawei.com/repo/com/huawei/hms/base/5.0.0.301/base-5.0.0.301.aar
HMSSDK Update:
https://developer.huawei.com/repo/c...pdate/5.0.0.301/availableupdate-5.0.0.301.aar
https://developer.huawei.com/repo/com/huawei/hms/update/2.0.6.302/update-2.0.6.302.aar
HMSSDK Device:
https://developer.huawei.com/repo/com/huawei/hms/device/5.0.0.301/device-5.0.0.301.aar
HMSSDK DynamicAPI:
https://developer.huawei.com/repo/com/huawei/hms/dynamic-api/1.0.13.303/dynamic-api-1.0.13.303.aar
HMSSDK Log:
https://developer.huawei.com/repo/com/huawei/hms/log/5.0.0.301/log-5.0.0.301.aar
HMSSDK Network:
https://developer.huawei.com/repo/c...common/4.0.2.300/network-common-4.0.2.300.aar
https://developer.huawei.com/repo/com/huawei/hms/network-grs/4.0.2.300/network-grs-4.0.2.300.aar
HMSSDK Stats:
https://developer.huawei.com/repo/com/huawei/hms/stats/5.0.0.301/stats-5.0.0.301.aar
HMSSDK Tasks:
https://developer.huawei.com/repo/com/huawei/hmf/tasks/1.4.1.300/tasks-1.4.1.300.aar
HMSSDK UI:
https://developer.huawei.com/repo/com/huawei/hms/ui/5.0.0.301/ui-5.0.0.301.aar
Squareup Libraries:
https://repo1.maven.org/maven2/com/squareup/okhttp3/okhttp/3.11.0/okhttp-3.11.0.jar
https://repo1.maven.org/maven2/com/squareup/okio/okio/1.14.0/okio-1.14.0.jar
Note: After download of the above AAR files, create addition folder inside Project and keep all AAR packages in it.
2. Open each of the AAR package with RAR tool and rename the class.jar and AndroidManifest.xml files. And save those jar files inside libs folder (It is recommended that the two files be renamed consistently with the AAR package names.)
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
1. Create Library as parent and then create bin, libs and src as subfolder in the project directory.
2. Develop java project inside the following path:
Choose Library Folder > src > b4x > hms > cloudstorage
a. Import the following two lines of code to each Java file.
Code:
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;
b. Add necessary annotations to the Java files.
Code:
@Version(1.0f)
@ShortName("CloudStorageFuncs")
@DependsOn(values={
"agconnect-auth-1.4.1.300.aar",
"agconnect-core-1.4.0.300.aar",
"agconnect-storage-1.3.0.300.aar",
"availableupdate-5.0.0.301.aar",
"base-5.0.0.301.aar",
"device-5.0.0.301.aar",
"dynamic-api-1.0.13.303.aar",
"log-5.0.0.301.aar",
"network-common-4.0.2.300.aar",
"network-grs-4.0.2.300.aar",
"stats-5.0.0.301.aar",
"tasks-1.4.1.300.aar",
"ui-5.0.0.301.aar",
"update-2.0.6.302.aar",
"okhttp-3.11.0.jar",
"datastore-core-1.4.1.300.aar",
"datastore-annotation-1.4.1.300.jar",
"agconnect-https-1.4.1.300.aar",
"agconnect-credential-1.4.1.300.aar",
"okio-1.14.0.jar"
})
More details, you can visit https://forums.developer.huawei.com/forumPortal/en/topic/0203411651765670210
Very interesting.

How Can I Integrate Remote Configuration of AppGallery Connect in Cordova?

Recently, it is found that AppGallery Connect Remote Configuration starts to support Cordova. The integration is rather simple, let’s have a try.If you want to quickly experience this service, see the demo on GitHub.
Integration Procedure
1. Create a project directory on your computer, run the following npm command to install Cordova.
npm install -g cordova
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2. Create a project and enable Remote Configuration.
a) Create an Android app in AppGallery, add it to a project, enable Remote Configuration, and add a parameter.
b) Run the following command to create a Cordova project. In this example, name the project RemoteConfig.
cordova create RemoteDemo com.huawei.cordova.remoteconfig RemoteConfig Creating a new cordova project.
c) Add an app platform to the project.
In the project directory, run cordova platform add android to add the Android platform.
Run cordova platform -l to view the supported platforms.
d) Go to Project settings in AppGallery Connect, download the agconnect-services.json file, and add the file to the android/app directory of your project.
e) Install the AppGallery Connect plug-in.
cordova plugin add @Cordova-plugin-agconnect/remoteconfig --save
After the plug-in is installed, you can view it in the plugins directory.
Add the AppGallery Connect plug-in address to app/build.gradle.
3. Use the Remote Configuration service.
1. Fetch data from the cloud. The data takes effect this time.
Call the fetch API to fetch parameter values from the cloud, and call the apply API to make them take effect.
You can view the fetched parameter values on the cloud in log information.
The other values displayed in log information are local ones.
2. Fetch the cloud data and make the parameter values fetched last time take effect.
Replace the fetch API with applyLastFetch to fetch data that is fetched from the cloud last time.
3. Clear the data.
Call the clearAll API to clear the cached data that is fetched earlier.
4. Fetch the value of a key from the cloud.
Call getValue to fetch related data from the cloud.
4. Compile and install an app package.
Run the cordova build android command to compile the project.
Find the APK package in the build folder in the android directory.
For more details, please check:
Cordova documentation:
https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html
Remote Configuration API Reference:
https://github.com/AppGalleryConnect/agc-demos/tree/main/Cordova/agc-remoteconfig-cordova
Remote Configuration Demo:
https://github.com/AppGalleryConnect/agc-demos/tree/main/Cordova/agc-remoteconfig-cordova

Three Steps to Rectify Failure in Creating Cloud DB Object Types

Relevant Logs​You may encounter a failure to create object types when integrating Cloud DB. Typical logs are as follows:
1. The ObjectType quantity is invalid.
XML:
NaturalBase: GenerateDiffSchemas: remove ObjectType is not supported. count of ObjectType is less than current
2. The object types failed to be negotiated.
XML:
E/NaturalBase: OpenNaturalStore: negotiate failed.
W/AGConnectCloudDB: openCloudDBZone: failed to create or open a cloudDBZone.
3. The scheme is not synchronized.
XML:
[NaturalCloudSyncModule][OnConnected]: negotiate schema.
[PushMessageAndNotifyStoreCv] Schema is UnSynced
4. The version of object types been changed but object types themselves are not changed.
XML:
E/NaturalBase: CreateObjectType: ObjectType version has changed, but ObjectType has not changed.
E/AGConnectCloudDB: createObjectType: failed to create ObjectType into the AGCConnectCloudDB.
Cause Analysis​The main cause is that the file matching the object type version in your Android project is inconsistent with the object types set on the AppGallery Connect server.
You can check the object types in AppGallery Connect as follows.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
To check information relevant to object types in your Android project, check the class in ObjectTypeInfoHelper.
Three Steps to Solve the Problem​1. Exporting Object Types from AppGallery Connect​Since the object types in your Android project are inconsistent with those in AppGallery Connect, you need to export the object types from AppGallery Connect for synchronization.
The export procedure in AppGallery Connect is as follows: Sign in to AppGallery Connect, click My projects, click your project, go to Build > Cloud DB > ObjectTypes, select the specific version, and click Export.
During the export, select JAVA for the file format and android for the file type of Java, and enter a package name.
Decompress the exported ZIP package in your project directory.
2. Checking Versions​You should pay attention to two versions in the object type file, which correspond to the following two fields in the ObjectTypeInfoHelper file:
1. FORMAT_VERSION: The value should match the SDK version.
If the value of FORMAT_VERSION in the exported file is 1, integrate the Cloud DB SDK of a version earlier than 1.2.2. Version 1.2.1.301 is recommended.
If the value of FORMAT_VERSION in the exported file is 2, integrate the Cloud DB SDK of a later version. Version 1.2.3.301 is recommended.
2. OBJECT_TYPE_VERSION
This version is that selected when you export object type information from AppGallery Connect. Generally, you do not need to change it.
3. Uninstalling Your App from Your Device and Installing It Again​If you have encountered the object type problem on your device, the incorrect information will still exist in the cache if you install your app again directly, and object type creation will still fail.
The correct method for performing the app re-installation is as follows:
1. Package your app again.
2. Uninstall the app already installed on your device manually.
3. Install the newly packaged app on your device for debugging.
The correct method for performing the app re-installation is as follows:
https://developer.huawei.com/consum...ect-Guides/agc-clouddb-agcconsole-objecttypes

Categories

Resources