我正在Texttospeech接口上工作。其中我經過一些處理後添加了一些文本。根據谷歌Android開發人員,你必須寫一個常量在講方法TextToSpeech.QUEUE_ADD,但它不適合我,可以不能幫助我。texttospeak.QUEUE_ADD常量不起作用
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio_bus);
textView = (EditText) findViewById(R.id.ipEditText);
welcomeNote = (TextView) findViewById(R.id.welcomeTextView);
text = welcomeNote.getText().toString();
speakText= text.concat(" , Please wait we are retriving information");
System.out.println("1 "+ speakText);
IP = getIntent().getExtras().getString("IP");
tts = new TextToSpeech(this, new OnInitListener() {
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {
tts.setLanguage(Locale.ENGLISH);
//tts.setSpeechRate(1.1f);
speakOut(speakText);
//tts.speak(IP, TextToSpeech.QUEUE_ADD, null);
}
}
});
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://"+IP+"/checkingbusno.php");
List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("BusStopName", "thakur_complex"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
textView.setText(result);
//initialising once again tts value
tts.speak(result, TextToSpeech.QUEUE_ADD,null);
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void speakOut(String text) {
//String text = txtText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
@Override
public void onDestroy() {
// Don't forget to shutdown!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
}
你可以在你想要做的事上添加一些代碼嗎? –
我已更新那東西 – Ashishsingh