>我正在遵循这个问题以使tts工作
安卓TTS不会说话
但是在他给出的答案中说(游戏结束,真(,说(行,假(,说(definition_string,假(
请谁能帮我说出这些术语是什么。
这是我的代码
public class SecondActivity extends AppCompatActivity implements OnInitListener {
TextToSpeech t1;
// private final int REQ_CODE_SPEECH_INPUT = 100;
String emailid;
@Override
protected void onCreate(Bundle savedInstanceState) {
emailid="Hi,say your email id";
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.US);
}
}
});
Toast.makeText(getApplicationContext(), emailid,Toast.LENGTH_SHORT).show();
t1.speak(emailid, TextToSpeech.QUEUE_FLUSH, null);
}
public void onPause(){
if(t1 !=null){
t1.stop();
t1.shutdown();
}
super.onPause();
}
}
试试这个,看看它是否有效:
public class TextToSpeechController implements TextToSpeech.OnInitListener{
private Context mContext;
private TextToSpeech tts;
public TextToSpeechController(Context context) {
mContext = context;
tts = new TextToSpeech(context, this);
}
@Override
public void onInit(int status) {
Log.e("INIT TTS", "INIT");
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.ENGLISH);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Toast.makeText(mContext, "This Language is not supported", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(mContext, "Ready to Speak", Toast.LENGTH_LONG).show();
speakTheText("Welcome to the App");
}
}
else {
Toast.makeText(mContext, "Can Not Speak", Toast.LENGTH_LONG).show();
}
}
public void stopTTS(){
tts.stop();
tts.shutdown();
}
public void speakTheText(String str){
tts.speak(str, TextToSpeech.QUEUE_FLUSH, null);
}