Search code examples
androidtext-to-speechgoogle-text-to-speech

Text to speech not working for other languages (except English)


I was trying to do a text to speech operation in my app. For English, it works properly. But, for other languages, it does not produce any audio. There is no error while debugging in device. I used the method in adapter for a listview.

Here is the code (adapter):

tts=new TextToSpeech(getContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if(status != TextToSpeech.ERROR) {
                tts.setLanguage(Locale.FRENCH);
            }
        }
    });

    holder.speakEnglish_words.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String textto=holder.txtTitle3.getText().toString();
            tts.speak(textto, TextToSpeech.QUEUE_FLUSH, null);
        }
    });

Here is the activity code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test_image_scrolling);

    btninfo=(Button)findViewById(R.id.infobtn);
    showimage=(ImageView) findViewById(R.id.test_imageview);
    categ_txtview=(TextView) findViewById(R.id.wordtitletxtview);

    showimage.setImageResource(R.drawable.accommodationforall);
    categ_txtview.setText(""+category);

    Test_Adapter_Bargaining_temporary adapter=new Test_Adapter_Bargaining_temporary(Accomudation_words.this,Englishwords,Arabicwords,Arabicsounds);
    ListView listView = (ListView) findViewById(R.id.test_listview);

    listView.setAdapter(adapter);

    btninfo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent=new Intent(Accomudation_words.this,InfoDialog_accommodation.class);
            startActivity(intent);
        }
    });

Solution

  • I found a solution.

    Just needed to turn on the Internet connection. The code is fine.