Expert: Integrating Text to Speech conversion in Xamarin(Android) Using Huawei ML Kit

Introduction

In this article, we will learn about converting Text to Speech (TTS) using Huawei ML kit. It provides both online and offline mode TTS. This service converts text into audio output TTS can be used in Voice Navigation, News and Books Application.

Let us start with the project configuration part:

Step 1: Create an app on App Gallery Connect.

Step 2: Enable the ML Kit in Manage APIs menu.

Step 3: Create new Xamarin (Android) project.

Step 4: Change your app package name same as AppGallery app’s package name.

a) Right click on your app in Solution Explorer and select properties.

b) Select Android Manifest on lest side menu.

c) Change your Package name as shown in below image.

Step 5: Generate SHA 256 key.

a) Select Build Type as Release.

b) Right click on your app in Solution Explorer and select Archive.

c) If Archive is successful, click on Distribute button as shown in below image.

d) Select Ad Hoc.

e) Click Add Icon.

f) Enter the details in Create Android Keystore and click on Create button.

g) Double click on your created keystore and you will get your SHA 256 key. Save it.

h) Add the SHA 256 key to App Gallery.

Step 6: Sign the .APK file using the keystore for both Release and Debug configuration.

a) Right-click on your app in Solution Explorer and select properties.

b) Select Android Packaging Signing and add the Keystore file path and enter details as shown in image.

Step 7: Enable the Service.

Step 8: Install Huawei ML NuGet Package.

Step 9: Install Huawei.Hms.MLComputerVoiceTts package using Step 8.

Step 10: Integrate HMS Core SDK.

Step 11: Add SDK Permissions.

Let us start with the implementation part:

Step 1: Create the xml design for online and offline text to speech (TTS).

Step 2: Create MainActivity.cs for implementing click listener for buttons.

Step 3: Create the layout for text to speech online mode.

Step 4: Create a TTS engine and callback to process the audio result for online text to speech mode.

Step 5: Create layout for offline text to speech.

Step 6: You need to download the model first for processing the offline mode text to speech.

Step 7: After model is downloaded, create TTS engine and callback for process the audio result.

Now Implementation part done.

Result

Tips and Tricks

Please add Huawei.Hms.MLComputerVoiceTts package using Step 8 of project configuration part.

Conclusion

In this article, we have learnt about converting text to speech on both online and offline mode. We can use this feature with any Book and Magazine reading application. We can also use this feature in Huawei Map Navigation.

Thanks for reading! If you enjoyed this story, please provide Likes and Comments.

Reference

Implementing Text to Speech

Github Link

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store