0

我正在开发应用程序以用英语显示一些详细信息,当我单击按钮时,它会用英语说出该消息,文本也包含数字。我想用泰卢固语讲那个文本,有什么办法吗?默认的 android tts 不支持泰卢固语,如何在 android 应用程序中使用外部 tts 引擎。请帮我解决这个问题,谢谢。

4

1 回答 1

0
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tts = new TextToSpeech(this, this);
    btnSpeak = (Button) findViewById(R.id.btnSpeak);
    txtText = (EditText) findViewById(R.id.txtText);
    // button on click event
    btnSpeak.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            speakOut();
        }
    });
}

// shutdown tts when activity destroy
@Override
public void onDestroy() {
    // Don't forget to shutdown!
    if (tts != null) {
        tts.stop();
        tts.shutdown();
    }
    super.onDestroy();
}

// It will called before TTS started
@Override
public void onInit(int status) {
    // TODO Auto-generated method stub
    // check status for TTS is initialized or not
    if (status == TextToSpeech.SUCCESS) {
        // if TTS initialized than set language
        result = tts.setLanguage(Locale.US);

        // tts.setPitch(5); // you can set pitch level
        // tts.setSpeechRate(); //you can set speech speed rate

        // check language is supported or not
        // check language data is available or not
        if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Toast.makeText(this, "Missing data", Toast.LENGTH_LONG).show();
            // disable button
            btnSpeak.setEnabled(false);
        } else {
            // if all is good than enable button convert text to speech
            btnSpeak.setEnabled(true);
        }
    } else {
        Log.e("TTS", "Initilization Failed");
    }
}

// call this method to speak text
private void speakOut() {
    String text = txtText.getText().toString();
    if (result != tts.setLanguage(Locale.US)) {
        Toast.makeText(getApplicationContext(), "Enter right Words...... ",
                Toast.LENGTH_LONG).show();
    } else {
        // speak given text
        tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
    }
}

您必须在说出方法中为此设置语言环境

注意:电话和日食应该支持您的语言环境

于 2015-02-24T12:29:40.123 回答