Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand Android TTS Technology

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to understand Android TTS technology, I believe that many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Android TTS technology, that is, Text-to-speech technology. TTS technology converts text files in real time, and the conversion time can be calculated in seconds. Under the action of its unique intelligent voice controller, the speech rhythm of the text output is smooth, which makes the listener feel natural when listening to the information, without the indifference and astringency of the machine voice output. TTS speech synthesis technology will soon cover the national standard I and II Chinese characters, with an English interface, automatic recognition of Chinese and English, and support for mixed reading of Chinese and English. All sounds are pronounced in human Putonghua, with a fast speech synthesis of 120-150 Chinese characters per second and a reading speed of 3-4 Chinese characters per second, so that users can hear clear and pleasant sound quality and coherent and smooth intonation.

Let's take a look at how this is achieved:

Step 1: check whether the TTS data is available:

Java Code:

/ / check whether TTS data is installed and available Intent checkIntent = new Intent (); checkIntent.setAction (TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); startActivityForResult (checkIntent, REQ_TTS_STATUS_CHECK) Protected void onActivityResult (int requestCode, int resultCode, Intent data) {if (requestCode = = REQ_TTS_STATUS_CHECK) {switch (resultCode) {case TextToSpeech.Engine.CHECK_VOICE_DATA_PASS: / / this returned result indicates that TTS Engine can use {mTts = new TextToSpeech (this, this); Log.v (TAG, "TTS Engine is installed!");} break Case TextToSpeech.Engine.CHECK_VOICE_DATA_BAD_DATA: / / the required voice data is corrupted case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_DATA: / / lack of voice data for language case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_VOLUME: / / lack of pronunciation data for language {/ / all three cases indicate that the data is wrong. Download and install the data Log.v (TAG) again. "Need language stuff:" + resultCode) Intent dataIntent = new Intent (); dataIntent.setAction (TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity (dataIntent);} break; case TextToSpeech.Engine.CHECK_VOICE_DATA_FAIL: / / check failed default: Log.v (TAG, "Got a failure. TTS apparently not available "); break;}} else {/ / results returned by other Intent}}

Next, initialize the TTS.

Java Code:

/ / implement TTS initialization interface @ Override public void onInit (int status) {/ / TODO Auto-generated method stub / / TTS Engine initialization completed if (status = = TextToSpeech.SUCCESS) {int result = mTts.setLanguage (Locale.US) / / set the pronunciation language if (result = = TextToSpeech.LANG_MISSING_DATA | | result = = TextToSpeech.LANG_NOT_SUPPORTED) / / determine whether the language is available {Log.v (TAG, "Language is not available"); speakBtn.setEnabled (false);} else {mTts.speak ("This is an example of speech synthesis.", TextToSpeech.QUEUE_ADD, null); speakBtn.setEnabled (true);}

Next, set the pronunciation language

Java Code:

Public void onItemSelected (AdapterView parent, View view, int position, long id) {/ / TODO Auto-generated method stub int pos = langSelect.getSelectedItemPosition (); int result =-1; switch (pos) {case 0: {inputText.setText ("I love you"); result = mTts.setLanguage (Locale.US);} break; case 1: {inputText.setText ("Je t'aime"); result = mTts.setLanguage (Locale.FRENCH);} break Case 2: {inputText.setText ("Ich liebe dich"); result = mTts.setLanguage (Locale.GERMAN);} break; case 3: {inputText.setText ("Ti amo"); result = mTts.setLanguage (Locale.ITALIAN);} break; case 4: {inputText.setText ("Te quiero"); result = mTts.setLanguage (new Locale ("spa", "ESP"));} break; default: break } / / set the pronunciation language if (result = = TextToSpeech.LANG_MISSING_DATA | | result = = TextToSpeech.LANG_NOT_SUPPORTED) / / determine whether the language is available {Log.v (TAG, "Language is not available"); speakBtn.setEnabled (false);} else {speakBtn.setEnabled (true);}}

Click the Button button to pronounce:

Java Code:

Public void onClick (View v) {/ / TODO Auto-generated method stub mTts.speak (inputText.getText (). ToString (), TextToSpeech.QUEUE_ADD, null); / / read the contents in the input box} after reading the above, have you mastered how to understand Android TTS technology? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report