preface

To be honest, xiaobian, as a hunan native, is often said that Mandarin is not standard enough, not only N/L, sometimes also can not be divided out of rhotic sound, often joke, leading to xiaobian is very distressed. Sometimes watching TV host fluent mouth broadcast, and complete standard tongue twister envy, often fantasizing about their own one day can also say a fluent tongue twister. Tongue Twister is a game that integrates HUAWEI’S HMS ML Kit with real-time voice service. How does this game work?

Application scenarios

Tongue Twister is a small Tongue Twister game integrated with huawei HMS ML Kit real-time voice recognition service. There are 5 levels in the game, and each level is a Tongue Twister. The secret is that with powerful real-time voice recognition, the real-time voice recognition service covers many fields in daily life and work. And deeply optimized the recognition ability in shopping search, film and television search, music search and navigation scenes, recognition accuracy is high, can easily detect the pronunciation of the entry, if the pronunciation is clear standard can pass.

Let’s take a look at the correct way to open this game.

So, is not enchanted, then come together to try their own custom belongs to your tongue twister big pass!

Development steps

  1. Set the authentication information for your application by referring to the Cloud Authentication Information Practical Instructions.

In: developer.huawei.com/consumer/cn… English: developer.huawei.com/consumer/en…

  1. The user invokes the interface to create a speech recognizer.
MLAsrRecognizer = MLAsrRecognizer.(context);
Copy the code
  1. Create the speech recognition result listener callback.
SpeechRecognitionListener MLAsrListener {
     @Override
     onStartListening() {
         }
 
     @Override
     onStartingOfSpeech() {
         }
 
     @Override
     onVoiceDataReceived([] data, energy, Bundle bundle) {
         
     }
 
     @Override
     onRecognizingResults(Bundle partialResults) {
         
     }
 
     @Override
     onResults(Bundle results) {
         
         }
     }
 
     @Override
     onError(error, String errorMessage) {
         
     }
 
     @Override
     onState(state, Bundle params) {
         
     }
 }
Copy the code
  1. Bind the newly created result listener callback to the speech recognizer
.setAsrListener(SpeechRecognitionListener());
Copy the code
  1. Configure the recognition parameters and call to enable voice recognition
Intent = Intent(MLAsrConstants.);
 .putExtra(MLAsrConstants., language)
         .putExtra(MLAsrConstants., MLAsrConstants.);
mSpeechRecognizer.startRecognizing(mSpeechRecognizerIntent);
Copy the code
  1. When the identification is complete, the resource is released
(! = ) { .destroy(); =; } maven address buildscript {repositories {maven {url}}} allprojects {repositories {maven {url}}}Copy the code

The introduction of the SDK

dependencies {implementation implementation implementation }
Copy the code

The manifest file

<... < / a >... RequestCameraPermission () {String[] permissions = String[]{manifest.permission.}; (! ActivityCompat.(, Manifest.permission.)) { ActivityCompat.(, permissions, TongueTwisterActivity.); ; }}Copy the code

conclusion

In addition to its application in games, real-time voice recognition services can identify the product name or feature described by voice as text to find the target product when searching for products using shopping apps. Similarly, when using a music App, the user can search for a song by recognizing the song title or artist entered by voice as text. In addition, when it is not convenient for drivers to input text while driving, they can convert the input voice into text and search the destination, making driving safer.

GitHub Demo Code

For more details, please refer to:

Huawei developer alliance website: developer.huawei.com/consumer/cn…

To obtain development guidance document: developer.huawei.com/consumer/en…

Participate in developer discussion please to Reddit community: www.reddit.com/r/HuaweiDev…

Download the demo and sample code at Github: github.com/HMS-Core

Solve the integration problem please to Stack Overflow: stackoverflow.com/questions/t…