我正在使用以下代码。它的工作正常,除了我有一个文本列表转换为语音的问题。但它只是将最后一行转换为演讲。这是我的代码,我将数据放入listview并尝试将其转换为语音:
public class TextSpeech extends ListActivity implements
TextToSpeech.OnInitListener {
/** Called when the activity is first created. */
private TextToSpeech tts;
private TextView txtText;
private List<Message> mess;
List<String> titless;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.speach);
tts = new TextToSpeech(this, this);
BaseFeedParser parser = new BaseFeedParser();
mess = parser.parse();
titless = new ArrayList<String>(mess.size());
speakOut();
}
@SuppressLint("NewApi")
@Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
@SuppressLint("NewApi")
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
public void speakOut() {
for (Message msg : mess){
titless.add(msg.getTitle());
tts.speak(msg.getTitle(), TextToSpeech.QUEUE_FLUSH, null);
}
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, R.layout.row,titless);
this.setListAdapter(adapter);
}
}
答案 0 :(得分:1)
您使用过TextToSpeech.QUEUE_FLUSH,只需将其更改为TextToSpeech.QUEUE_ADD。根据您的要求,您希望TTS逐一阅读。