如何在android应用程序中集成telugu语言的文本到语音

时间:2015-02-24 11:48:11

标签: android google-text-to-speech

我正在开发应用程序以用英语显示一些细节,当我点击按钮时,它会用英语说出该消息,文本也包含数字。我想用泰卢固语发言,有没有办法做到这一点。默认的android不支持泰卢固语,如何在android应用程序中使用外部tts引擎。请帮帮我,谢谢。

1 个答案:

答案 0 :(得分: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);
    }
}

你必须为该方法设置语言环境

注意:手机和eclipse应支持您的区域设置