文字转语音不适用于其他语言(英语除外)

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

我试图在我的应用程序中执行文本到语音操作。对于英语,它可以正常工作。但是,对于其他语言,它不会产生任何音频。在设备中调试时没有错误。我在列表视图中使用适配器中的方法。

这是代码(适配器):

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);
        }
    });

这里是 activity 代码:

@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);
        }
    });

我认为您需要使用此处描述的方法查看 phone 上是否有法语文本到语音引擎:

此处描述的语言还有一个设备设置:

https://tunesgo.wondershare.com/android/text-to-speech.html

我找到了解决方案。

只需要打开互联网连接。代码没问题。