Ultra-Simple Integration With ML Kit to Implement Word Broadcasting
Learn how to use the general text recognition and speech synthesis functions of ML Kit to implement an automatic voice broadcast app
Join the DZone community and get the full member experience.Join For Free
I believe that we all start to learn a language when we start to speak it. When primary school students learn a language, an important part of their homework work is dictating the text of the new words. Many parents know this experience.
On one hand, the pronunciation is relatively simple. On the other hand, parents' time is very precious. Now, there are many dictation voices in the market. These broadcasters record the dictation words in the language teaching materials after class for parents to download. However, this kind of recording is not flexible enough. If the teacher leaves a few extra words that are not part of the after-school problem set, the recordings won't meet the needs of parents and children.
This article describes how to use the general text recognition and speech synthesis functions of ML Kit to implement an automatic voice broadcast app. You only need to take photos of dictation words or texts, and then the text in the photos can be automatically played. The tone of the voice can be adjusted.
Open the project-level build.gradle file:
Choose allprojects > repositories and configure the Maven repository address of HMS SDK:
Configure the Maven repository address of HMS SDK in buildscript->repositories:
Choose buildscript > dependencies and configure the AGC plug-in:
Adding Compilation Dependencies
Open the application levelbuild.gradle file:
Add the ACG plug-in to the file header:
Specify permissions and features: Declare them in AndroidManifest.xml.
Key Development Steps
There are two main functions. One is to identify the operation text, and the other is to read the operation. The OCR+TTS mode is used to read the operation. After taking a photo, click the play button to read the operation.
1. Dynamic permission application:
2. Start the reading interface:
3. Invoke createLocalTextAnalyzer() in the onCreate() method to create a device-side text recognizer:
4. Invoke createLocalTextAnalyzer() in the onCreate() method to create a device-side text recognizer:
5. Set the buttons for reading photos, taking photos, and reading aloud.
6. Start TextAnalyzer() during the callback of photographing and reading photos:
7. After the recognition is successful, click the play button to start the playback:
Opinions expressed by DZone contributors are their own.