Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set turkish language for text to speech [duplicate]

Im working on text to speech app , i want to set turkish language to be as this:

tts.setLanguage(Locale.TR);

BUT this is not available in android , is it wrong to add this way or there is different way to add turkish language to text to speech .

any help and advice will be appreciated

text to speech code :

 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);}}
like image 850
androidqq6 Avatar asked Oct 04 '22 08:10

androidqq6


1 Answers

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)

like image 157
Yunus SIRIN Avatar answered Oct 13 '22 12:10

Yunus SIRIN