TextToSpeech를 사용하려고하는데 이상한 문제가 있습니다.TTS는 수신되었지만 소리가 나지 않음
내 응용 프로그램의 아키텍처를 간단하게 설명하겠습니다. 이 신청서는 버스 시간에 사용됩니다. 사용자는 알림에 버스를 추가 할 수 있습니다. 서버는 변경 사항이있는 경우 구독자에게 알립니다. 이 응용 프로그램과 함께 TTS를 사용하고 싶습니다.
Android GCM 및 알림 시스템을 구현했지만 문제는 TTS입니다.
이public static void generateNotification(Context context, String message) {
int icon = R.drawable.icon_small;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Bundle b = new Bundle();
b.putString(EXTRA_MESSAGE, message);
b.putString(READABLE_MESSAGE, message);
Intent notificationIntent = new Intent(context, BusAlerts.class);
notificationIntent.putExtra("CallType", CallType.NOTIFICATION);
notificationIntent.putExtra("MessageReceived", b);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;
long[] vibrate = { 1000 };
notification.vibrate = vibrate;
notificationManager.notify(0, notification);
}
이 코드가 성공적으로 알림을 생성합니다
GCMIntentService.onMessage
방법은 아래 generateNotification 메소드를 호출합니다.) 완벽한 사용자가 통지에서이 클래스를 열면
public class BusAlerts extends Activity implements OnInitListener {
private static TextToSpeech myTts;
@Override
public void onCreate(Bundle savedInstanceState) {
myTts = new TextToSpeech(this, null);
}
@Override
protected void onStart() {
super.onStart();
//readableMessage extracts from bundles
speak(readableMessage);
}
public void speak(String text)
{
myTts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if (myTts != null) {
myTts.shutdown();
myTts.stop();
myTts = null;
}
}
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = myTts.setLanguage(Locale.UK);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
}
else{
if (myTts.isLanguageAvailable(Locale.UK) == TextToSpeech.LANG_AVAILABLE || myTts.isLanguageAvailable(Locale.UK) == TextToSpeech.LANG_COUNTRY_AVAILABLE)
myTts.setLanguage(Locale.UK);
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
이 모든 것이 작동하지만 소리가 나오는 없습니다 여기 BusAlerts.codes (일부 트리밍)입니다. 내가 그것을 디버깅 할 때 나는 아래의 상황을 본다.
하지만 사용자가 홈 버튼을 눌러 응용 프로그램을 다시 열면 (동일한 작업이 다시 시작됨) 사용자가 소리를들을 수 있습니다. 상황은 이렇습니다.
mCachedParamters와 mITts가 다른 것으로 나타남에 따라; 그러나 나는 이유를 모른다. 나는 일주일 동안 갇혀 있었고 해결책을 찾지 못했습니다.
어떻게 보증 할 수 있습니까? 또한 볼 수 있듯이 어쨌든 나는 onInit 메서드를 호출하지 않습니다. 왜냐하면 나는이 매개 변수를 TextToSpeech 생성자에 전달하지 않기 때문입니다. –
이제 onStart 아래의 코드를 onCreate로 이동하고 알림에서 열거 나 돌아 오는 중 아무 것도 듣지 못합니다. –
당신은 그것을 호출하지 않지만 프레임 워크는 그것을 호출합니다. 그래서 당신은 말하기 (readableMessage)를 부릅니다. Oninit 성공 사례. 이 문제는 oncreate가 완료 될 때만 호출된다는 것입니다. 앱이 전경 이동 (foreground move) 될 때마다 이것을 호출하기를 원하면 myTts = new TextToSpeech (this, null); toOnResume – nandeesh