HMS ML Kit Text To Speech

Merve Nur TÜRK
Huawei Developers
Published in
3 min readDec 1, 2020
Photo by 수안 최 on Unsplash

This story explains how to use HMS ML Kit Text To Speech feature.

What is the Text To Speech ?

Text to speech (TTS) can convert text information into audio output in real time.

The use cases that we can implement to enrich our applications:

  • Selection of timbres for different language options.For now SDK supports 6 languages which are Chinese, English, French, Spanish, German and Italian.
  • Allowing the users to adjust speed and volume settings
  • Sentence tracking synchronized with speaker.
  • Obtaining audio output of Text to Speech service.

TTS is widely used in broadcasting, news, voice navigation, and audio reading. For example, TTS can convert a large amount text into speech output and highlight the content that is being played to free users’ eyes, bringing interests to users. Similarly, in voice navigation, TTS records a voice segment based on navigation data, and then synthesizes the voice segment into navigation voice, so that navigation is more personalized.

Before API development;

  • When you finish process of creating project, you need to get agconnect-services.json file for configurations from AppGallery Connect. Then, you have to add it into our application project level under the app folder.
  • After that, we need to add dependencies into project level gradle files.
  • Then, we need to add dependencies into app level gradle files.

Let’s learn text to speech sdk

This demo project aims to convert a text to speech. The project has a main screen(MainActivity.java) that you can input a text and click speech button.

Firstly we have to set api key:

Lets define layout file of this activity:

To perfom click we must set click listener:

In addition click listener we should add key actions to perform click:

We need to create MLTtsConfig to set properties of speech. In this method English language, female speaker and 1.0f speed and valume was setted. We need to create mlTtsengine with these configuration:

We need to create a callback to set engine. By this callback you can follow all acitons:

Set the engine tts callback:

The final method is click event to perform speech:

In this article, we made a demo project using HMS ML Kit Text To Speech SDK and learn its usage. Hope to see awesome projects from you. Stay with code :)

References

Official website of Huawei Developers for ML Kit Document Recognition

HMS Core overview

Huawei Developer Forum

HMS Core Stack Overflow

HMS Core sample code on GitHub

--

--