5

我正在开发文本到语音应用程序,我想将土耳其语设置为:

tts.setLanguage(Locale.TR);

但是这在 android 中不可用,以这种方式添加是错误的,还是有不同的方式将土耳其语添加到文本到语音。

任何帮助和建议将不胜感激

文字转语音代码:

 public class AndroidTextToSpeechActivity extends Activity implements
    TextToSpeech.OnInitListener {
/** Called when the activity is first created. */

private TextToSpeech tts;
private Button btnSpeak;
private EditText txtText;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.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();}  
                       });}
@Override
public void onDestroy() {
    // Don't forget to shutdown!
    if (tts != null) {
        tts.stop();
        tts.shutdown();}

    super.onDestroy();}

@Override
public void onInit(int status) {
    // TODO Auto-generated method stub

    if (status == TextToSpeech.SUCCESS) {

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

        // tts.setPitch(5); // set pitch level

        // tts.setSpeechRate(2); // set speech speed rate

        if (result == TextToSpeech.LANG_MISSING_DATA
            || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "Language is not supported");
        } else {
            btnSpeak.setEnabled(true);
            speakOut();}

       } else {
            Log.e("TTS", "Initilization Failed");}}

 private void speakOut() {

    String text = txtText.getText().toString();

    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);}}
4

2 回答 2

4

if your device is Turkish, use :

tts.setLanguage(Locale.getDefault());

instead of

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

Then EXTRA_LANGUAGE_MODEL value must be: "tr-TR".

I tried and succeeded.(But I also downloaded Turkish lang.pack from samsung market)

于 2014-12-10T13:53:54.127 回答
0

尝试其他语音库,例如http://dragonmobile.nuancemobiledeveloper.com/public/Help/DragonMobileSDKReference_Android/SpeechKit_Guide/Basics.html

于 2013-04-18T09:18:15.210 回答