第一次尝试在下面的代码中使用谷歌默认的TTS引擎,但是发现不支持波斯语!
因此,我下载并安装espeak RedZoc TTS engine在手机上,并将默认 TTS 语言更改为波斯语。当我在手机设置或 RedZoc 应用程序中检查它时,它运行良好。
但是当我在手机中运行我的代码时,它会单独读取字母,而不是读取完整的单词!(例如它应该说SALAM但它说Arabic Sin Lam Alef Mim)
主要活动:
package com.m.ttsapp;
import android.content.Intent;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;
public class MainActivity extends AppCompatActivity
{
String text;
EditText et;
TextToSpeech tts;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et=findViewById(R.id.editText1);
btn = findViewById(R.id.button1);
tts=new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status)
{
if(status == TextToSpeech.SUCCESS)
{
int result=tts.setLanguage(Locale.);
if(result==TextToSpeech.LANG_MISSING_DATA || result==TextToSpeech.LANG_NOT_SUPPORTED)
{
Log.e("error", "This Language is not supported");
}
else{
ConvertTextToSpeech();
}
}
else
Log.e("error", "Initilization Failed!");
}
});
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ConvertTextToSpeech();
}
});
}
@Override
protected void onPause()
{
if(tts != null)
{
tts.stop();
tts.shutdown();
}
super.onPause();
}
private void ConvertTextToSpeech()
{
text = et.getText().toString();
if(text == null || "".equals(text))
{
text = "Content not available";
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}else
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
我知道也许我必须更改这行代码但不知道将其更改为什么?int result=tts.setLanguage(Locale.);
或者也许我必须忘记所有这些代码并编写另一个?但是怎么做?