tts文字转语音_Android文字转语音(TTS)

tts文字转语音

In this tutorial, we’ll be discussing and implementing the Text To Speech in our Android application.
We will create an android application which speaks the text entered in the EditText. Android Text To Speech is also referred to as Android TTS.

在本教程中,我们将在Android应用程序中讨论和实现“文字转语音”。
我们将创建一个Android应用程序,说出在EditText中输入的文本。 Android文字转语音也称为Android TTS。

Android文字转语音 (Android Text To Speech)

TextToSpeech as the name suggests is used to synthesize speech from the text string.

顾名思义,TextToSpeech用于从文本字符串合成语音。

You can set the language of your choice. You can set the pitch, speed as well your own speech from a custom file.

您可以设置自己选择的语言。 您可以从自定义文件中设置音高,速度以及自己的语音。

TextToSpeech needs to be initialized first. For this, you need to implement the TextToSpeech.OnInitListener interface and override the method: onInit.
Example:

首先需要初始化TextToSpeech。 为此,您需要实现TextToSpeech.OnInitListener接口并覆盖方法: onInit
例:

TextToSpeech tts = new TextToSpeech(this, this);

Once this is done the onInit gets triggered.

一旦完成此操作,就会触发onInit。

In this method, we check whether the feature is available on our device or not.

通过这种方法,我们检查功能是否在我们的设备上可用。

@Override
    public void onInit(int status) {

        if (status == TextToSpeech.SUCCESS) {

            int result = tts.setLanguage(Locale.US);

            if (result == TextToSpeech.LANG_MISSING_DATA
                    || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Toast.makeText(getApplicationContext(), "Language not supported", Toast.LENGTH_SHORT).show();
            } else {
                 //Disable the button if any.
            }

        } else {
            Toast.makeText(getApplicationContext(), "Init failed", Toast.LENGTH_SHORT).show();
        }
    }

How to speak the text?

文字怎么说?

tts.speak(text, TextTo

你可能感兴趣的:(字符串,java,android,语音识别,ios)