【发布时间】:2018-08-03 12:47:58
【问题描述】:
第一次尝试在下面的代码中使用谷歌默认的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.);
或者也许我必须忘记所有这些代码并编写另一个?但是怎么做呢?
【问题讨论】:
-
引擎可能假定 SALAM 是首字母缩略词。试试小写。
-
@brandall:事实上我尝试了
سلام,我用英文写了这个例子来阐明我的意思 -
引擎不能将其解释为首字母缩写词吗?
-
@brandall:我不知道!当我在我的应用程序之外(在手机 TTS 设置或 RedZoc 应用程序内)尝试
سلام时,它工作正常,但在我的应用程序内它会显示字母!我想也许我必须更改我的代码中的某些内容? -
可能是unicode问题?(虽然我不知道真的是什么问题)
标签: android locale text-to-speech persian espeak