我試圖讓Android的TTS在服務中運行,但我不知道爲什麼它不工作,它編譯,不會崩潰,但它不起作用。在服務中運行Android TTS
Toast通知雖然可以工作。
package alarm.test;
import android.app.Service;
import com.google.tts.TextToSpeechBeta;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyAlarmService extends Service {
private TextToSpeechBeta myTts;
private TextToSpeechBeta.OnInitListener ttsInitListener = new TextToSpeechBeta.OnInitListener() {
public void onInit(int arg0, int arg1) {
myTts.speak("", 0, null);
}
};
@Override
public void onCreate() {
// TODO Auto-generated method stub
myTts = new TextToSpeechBeta(this,
ttsInitListener);
Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG).show();
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
myTts.speak("something is working", TextToSpeechBeta.QUEUE_FLUSH, null);
Toast.makeText(this, "MyAlarmService.onBind()", Toast.LENGTH_LONG).show();
return null;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG).show();
}
@Override
public boolean onUnbind(Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(this, "MyAlarmService.onUnbind()", Toast.LENGTH_LONG).show();
return super.onUnbind(intent);
}
}
請更詳細地描述你的意思是「不工作」。你在LogCat上看到什麼? – 2011-03-07 12:16:39
DEBUG/TextToSpeechBeta(512):TextToSpeechBeta不instled - dfauing基本平臺文字轉語音的說話 VERBOSE/TtsSice(418):TTS服務接收 INFO/TtsService(418):回採 INFO/TtsService(418):停止 VERBOSE/TtsService(418):TTS處理: VERBOSE/TtsService(418):TtsService.setLanguage(eng,USA) INFO/SVOX Pico引擎(418):語言已加載(en-US == en-US) DEBUG/dalvikvm(68):GC_CONCURRENT釋放719K,48%空閒4093K/7751K,外部2041K/2378K,暫停21ms + 27ms DEBUG/SntpClient(68):請求時間失敗:java.net.SocketException:地址族不受支持協議 – 2011-03-07 19:35:27