我创建了一个实现OnUtteranceCompleteListener的小型TTS应用程序,虽然事情似乎完全符合预期,但我在LogCat上注意到以下内容(每个完成的话语都有一个):
03-01 20:47:06.436: VERBOSE / TtsService(381):TTS回调: 派遣完成到1
同样,这似乎是良性的,但我不明白' 1 '的意思。所有这些话语的所有这些行都说“已完成 1 ”,即使对于大于1的话语ID也是如此。
此日志中“1”的含义是什么?
顺便说一句,这条消息不是由我的代码生成的,而是由TTS引擎(Pico)本身生成的。
答案 0 :(得分:1)
查看TTSService.java处提供的http://eyes-free.googlecode.com源代码,您可以找到函数 dispatchUtteranceCompletedCallback():
private void dispatchUtteranceCompletedCallback(String utteranceId, String packageName) {
/* Legacy support for TTS */
final int oldN = mCallbacksOld.beginBroadcast();
for (int i = 0; i < oldN; i++) {
try {
mCallbacksOld.getBroadcastItem(i).markReached("");
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing
// the dead object for us.
}
}
try {
mCallbacksOld.finishBroadcast();
} catch (IllegalStateException e) {
// May get an illegal state exception here if there is only
// one app running and it is trying to quit on completion.
// This is the exact scenario triggered by MakeBagel
return;
}
/* End of legacy support for TTS */
ITtsCallbackBeta cb = mCallbacksMap.get(packageName);
if (cb == null) {
return;
}
Log.v(SERVICE_TAG, "TTS callback: dispatch started");
// Broadcast to all clients the new value.
final int N = mCallbacks.beginBroadcast();
try {
cb.utteranceCompleted(utteranceId);
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing
// the dead object for us.
}
mCallbacks.finishBroadcast();
Log.v(SERVICE_TAG, "TTS callback: dispatch completed to " + N);
}
1是N的当前值,由 mCallbacks.beginBroadcast()的返回值初始化。
beginBroadcast()是类RemoteCallbackList的一种方法,其文档说明了它:
返回。中的回调数 广播,用于 getBroadcastItem(int)来确定 您可以提供的指数范围
这有帮助吗?