How to use Huawei ML kit-Sound Detection feature?
In this article, I am going to give you information about Huawei ML kit’s Sound Detection service and how to use the service in native android applications. Let’s get started :)
Integrating Applications to HMS Core
To start developing an app with Huawei mobile services, you need to integrate your application to the HMS core. Check the link below to integrate your application, also don’t forget to enable the ML kit from AppGallery Connect.
Service Introduction
The sound detection service can detect sound events in online (real-time recording) mode. The detected sound events can help you perform subsequent actions. Currently, the following types of sound events are supported: laughter, a child crying, snoring, sneezing, shouting, mew, barking, running water (such as water taps, streams, and ocean waves), car horns, doorbell, knocking, fire alarm sounds (such as fire alarm and smoke alarm), and other alarm sounds (such as fire truck alarm, ambulance alarm, police car alarm, and air defense alarm).
Use Cases
This service is widely used in daily life. For example, in a case in which hearing is impaired, it is difficult to receive a sound event such as an alarm, a train whistle, or a doorbell. The function may be used to assist in receiving a surrounding sound signal, so as to remind a user to make a timely response when an emergency occurs. In addition, if a user is not accompanied by a baby, the user may not be able to learn about the baby’s status in a timely manner. This function enables the user to detect the key sounds of the baby, such as crying, to learn about the baby’s abnormalities as soon as possible.
Precautions
Currently, the detection result of only one sound event can be returned. Mixed scenarios (multiple sound events occur at the same time) are not supported. The interval between two different sound events must be at least 2 seconds.
Sound Types
These instances represent the type of sounds. As you can see currently 13 types of sounds can be detected by the Sound Detection Service. We will use these integer values while coding. The First 4 instances represent the errors. Let’s continue with the preparations for our Demo application.
Preparations for the Code
Service can work only with base SDK but for precise results, it is recommended to use both dependencies. The total size of both dependencies is around 6 MB.
If you are using model package dependency and have a published application, updating the model is important.
Note: For using this service, also Record Audio permission is required and applied by the user on runtime before service is started.
Java Code of the Sound Detection
This is the simple code for detecting baby cry, laughter, and knocking sounds. You can check the Sound type section to detect more sounds.
In line 43 and line 44 code for stopping and destroying the detector can be found.
After the detection is successful, many functionalities can be triggered (pushing notifications, etc. ) according to the app’s need.
Take care of yourself until next time …