Merge change 23338 into eclair

* changes:
  Clean TTS logs: use a common TAG in the TTS service, don't show an error when loading the native synth lib.
This commit is contained in:
Android (Google) Code Review
2009-08-31 15:39:07 -07:00
2 changed files with 27 additions and 26 deletions

View File

@@ -40,7 +40,7 @@ public class SynthProxy {
* Constructor; pass the location of the native TTS .so to use. * Constructor; pass the location of the native TTS .so to use.
*/ */
public SynthProxy(String nativeSoLib) { public SynthProxy(String nativeSoLib) {
Log.e("TTS is loading", nativeSoLib); Log.v(TtsService.SERVICE_TAG, "TTS is loading " + nativeSoLib);
native_setup(new WeakReference<SynthProxy>(this), nativeSoLib); native_setup(new WeakReference<SynthProxy>(this), nativeSoLib);
} }

View File

@@ -122,6 +122,7 @@ public class TtsService extends Service implements OnCompletionListener {
private static final String ACTION = "android.intent.action.START_TTS_SERVICE"; private static final String ACTION = "android.intent.action.START_TTS_SERVICE";
private static final String CATEGORY = "android.intent.category.TTS"; private static final String CATEGORY = "android.intent.category.TTS";
private static final String PKGNAME = "android.tts"; private static final String PKGNAME = "android.tts";
protected static final String SERVICE_TAG = "TtsService";
private final RemoteCallbackList<ITtsCallback> mCallbacks private final RemoteCallbackList<ITtsCallback> mCallbacks
= new RemoteCallbackList<ITtsCallback>(); = new RemoteCallbackList<ITtsCallback>();
@@ -189,7 +190,7 @@ public class TtsService extends Service implements OnCompletionListener {
// Unregister all callbacks. // Unregister all callbacks.
mCallbacks.kill(); mCallbacks.kill();
Log.v("TtsService", "onDestroy() completed"); Log.v(SERVICE_TAG, "onDestroy() completed");
} }
@@ -302,7 +303,7 @@ public class TtsService extends Service implements OnCompletionListener {
private int setLanguage(String callingApp, String lang, String country, String variant) { private int setLanguage(String callingApp, String lang, String country, String variant) {
Log.v("TtsService", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")"); Log.v(SERVICE_TAG, "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")");
int res = TextToSpeech.ERROR; int res = TextToSpeech.ERROR;
try { try {
if (isDefaultEnforced()) { if (isDefaultEnforced()) {
@@ -386,7 +387,7 @@ public class TtsService extends Service implements OnCompletionListener {
* engines. * engines.
*/ */
private int speak(String callingApp, String text, int queueMode, ArrayList<String> params) { private int speak(String callingApp, String text, int queueMode, ArrayList<String> params) {
Log.v("TtsService", "TTS service received " + text); Log.v(SERVICE_TAG, "TTS service received " + text);
if (queueMode == TextToSpeech.QUEUE_FLUSH) { if (queueMode == TextToSpeech.QUEUE_FLUSH) {
stop(callingApp); stop(callingApp);
} else if (queueMode == 2) { } else if (queueMode == 2) {
@@ -435,7 +436,7 @@ public class TtsService extends Service implements OnCompletionListener {
speechQueueAvailable = speechQueueAvailable =
speechQueueLock.tryLock(SPEECHQUEUELOCK_TIMEOUT, TimeUnit.MILLISECONDS); speechQueueLock.tryLock(SPEECHQUEUELOCK_TIMEOUT, TimeUnit.MILLISECONDS);
if (speechQueueAvailable) { if (speechQueueAvailable) {
Log.i("TtsService", "Stopping"); Log.i(SERVICE_TAG, "Stopping");
for (int i = mSpeechQueue.size() - 1; i > -1; i--){ for (int i = mSpeechQueue.size() - 1; i > -1; i--){
if (mSpeechQueue.get(i).mCallingApp.equals(callingApp)){ if (mSpeechQueue.get(i).mCallingApp.equals(callingApp)){
mSpeechQueue.remove(i); mSpeechQueue.remove(i);
@@ -462,13 +463,13 @@ public class TtsService extends Service implements OnCompletionListener {
} else { } else {
result = TextToSpeech.SUCCESS; result = TextToSpeech.SUCCESS;
} }
Log.i("TtsService", "Stopped"); Log.i(SERVICE_TAG, "Stopped");
} else { } else {
Log.e("TtsService", "TTS stop(): queue locked longer than expected"); Log.e(SERVICE_TAG, "TTS stop(): queue locked longer than expected");
result = TextToSpeech.ERROR; result = TextToSpeech.ERROR;
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.e("TtsService", "TTS stop: tryLock interrupted"); Log.e(SERVICE_TAG, "TTS stop: tryLock interrupted");
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
// This check is needed because finally will always run; even if the // This check is needed because finally will always run; even if the
@@ -508,12 +509,12 @@ public class TtsService extends Service implements OnCompletionListener {
// delete the file that was being written // delete the file that was being written
if (mCurrentSpeechItem.mFilename != null) { if (mCurrentSpeechItem.mFilename != null) {
File tempFile = new File(mCurrentSpeechItem.mFilename); File tempFile = new File(mCurrentSpeechItem.mFilename);
Log.v("TtsService", "Leaving behind " + mCurrentSpeechItem.mFilename); Log.v(SERVICE_TAG, "Leaving behind " + mCurrentSpeechItem.mFilename);
if (tempFile.exists()) { if (tempFile.exists()) {
Log.v("TtsService", "About to delete " Log.v(SERVICE_TAG, "About to delete "
+ mCurrentSpeechItem.mFilename); + mCurrentSpeechItem.mFilename);
if (tempFile.delete()) { if (tempFile.delete()) {
Log.v("TtsService", "file successfully deleted"); Log.v(SERVICE_TAG, "file successfully deleted");
} }
} }
} }
@@ -522,11 +523,11 @@ public class TtsService extends Service implements OnCompletionListener {
mCurrentSpeechItem = null; mCurrentSpeechItem = null;
} }
} else { } else {
Log.e("TtsService", "TTS killAllUtterances(): queue locked longer than expected"); Log.e(SERVICE_TAG, "TTS killAllUtterances(): queue locked longer than expected");
result = TextToSpeech.ERROR; result = TextToSpeech.ERROR;
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.e("TtsService", "TTS killAllUtterances(): tryLock interrupted"); Log.e(SERVICE_TAG, "TTS killAllUtterances(): tryLock interrupted");
result = TextToSpeech.ERROR; result = TextToSpeech.ERROR;
} finally { } finally {
// This check is needed because finally will always run, even if the // This check is needed because finally will always run, even if the
@@ -577,13 +578,13 @@ public class TtsService extends Service implements OnCompletionListener {
} else { } else {
result = TextToSpeech.SUCCESS; result = TextToSpeech.SUCCESS;
} }
Log.i("TtsService", "Stopped all"); Log.i(SERVICE_TAG, "Stopped all");
} else { } else {
Log.e("TtsService", "TTS stopAll(): queue locked longer than expected"); Log.e(SERVICE_TAG, "TTS stopAll(): queue locked longer than expected");
result = TextToSpeech.ERROR; result = TextToSpeech.ERROR;
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.e("TtsService", "TTS stopAll: tryLock interrupted"); Log.e(SERVICE_TAG, "TTS stopAll: tryLock interrupted");
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
// This check is needed because finally will always run; even if the // This check is needed because finally will always run; even if the
@@ -710,11 +711,11 @@ public class TtsService extends Service implements OnCompletionListener {
sNativeSynth.speak(speechItem.mText, streamType); sNativeSynth.speak(speechItem.mText, streamType);
} catch (NullPointerException e) { } catch (NullPointerException e) {
// synth will become null during onDestroy() // synth will become null during onDestroy()
Log.v("TtsService", " null synth, can't speak"); Log.v(SERVICE_TAG, " null synth, can't speak");
} }
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.e("TtsService", "TTS speakInternalOnly(): tryLock interrupted"); Log.e(SERVICE_TAG, "TTS speakInternalOnly(): tryLock interrupted");
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
// This check is needed because finally will always run; // This check is needed because finally will always run;
@@ -740,7 +741,7 @@ public class TtsService extends Service implements OnCompletionListener {
public void run() { public void run() {
boolean synthAvailable = false; boolean synthAvailable = false;
String utteranceId = ""; String utteranceId = "";
Log.i("TtsService", "Synthesizing to " + speechItem.mFilename); Log.i(SERVICE_TAG, "Synthesizing to " + speechItem.mFilename);
try { try {
synthAvailable = synthesizerLock.tryLock(); synthAvailable = synthesizerLock.tryLock();
if (!synthAvailable) { if (!synthAvailable) {
@@ -784,11 +785,11 @@ public class TtsService extends Service implements OnCompletionListener {
sNativeSynth.synthesizeToFile(speechItem.mText, speechItem.mFilename); sNativeSynth.synthesizeToFile(speechItem.mText, speechItem.mFilename);
} catch (NullPointerException e) { } catch (NullPointerException e) {
// synth will become null during onDestroy() // synth will become null during onDestroy()
Log.v("TtsService", " null synth, can't synthesize to file"); Log.v(SERVICE_TAG, " null synth, can't synthesize to file");
} }
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.e("TtsService", "TTS synthToFileInternalOnly(): tryLock interrupted"); Log.e(SERVICE_TAG, "TTS synthToFileInternalOnly(): tryLock interrupted");
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
// This check is needed because finally will always run; // This check is needed because finally will always run;
@@ -833,7 +834,7 @@ public class TtsService extends Service implements OnCompletionListener {
if (cb == null){ if (cb == null){
return; return;
} }
Log.v("TtsService", "TTS callback: dispatch started"); Log.v(SERVICE_TAG, "TTS callback: dispatch started");
// Broadcast to all clients the new value. // Broadcast to all clients the new value.
final int N = mCallbacks.beginBroadcast(); final int N = mCallbacks.beginBroadcast();
try { try {
@@ -843,7 +844,7 @@ public class TtsService extends Service implements OnCompletionListener {
// the dead object for us. // the dead object for us.
} }
mCallbacks.finishBroadcast(); mCallbacks.finishBroadcast();
Log.v("TtsService", "TTS callback: dispatch completed to " + N); Log.v(SERVICE_TAG, "TTS callback: dispatch completed to " + N);
} }
private SpeechItem splitCurrentTextIfNeeded(SpeechItem currentSpeechItem){ private SpeechItem splitCurrentTextIfNeeded(SpeechItem currentSpeechItem){
@@ -880,7 +881,7 @@ public class TtsService extends Service implements OnCompletionListener {
speechQueueAvailable = speechQueueAvailable =
speechQueueLock.tryLock(SPEECHQUEUELOCK_TIMEOUT, TimeUnit.MILLISECONDS); speechQueueLock.tryLock(SPEECHQUEUELOCK_TIMEOUT, TimeUnit.MILLISECONDS);
if (!speechQueueAvailable) { if (!speechQueueAvailable) {
Log.e("TtsService", "processSpeechQueue - Speech queue is unavailable."); Log.e(SERVICE_TAG, "processSpeechQueue - Speech queue is unavailable.");
return; return;
} }
if (mSpeechQueue.size() < 1) { if (mSpeechQueue.size() < 1) {
@@ -895,7 +896,7 @@ public class TtsService extends Service implements OnCompletionListener {
SoundResource sr = getSoundResource(mCurrentSpeechItem); SoundResource sr = getSoundResource(mCurrentSpeechItem);
// Synth speech as needed - synthesizer should call // Synth speech as needed - synthesizer should call
// processSpeechQueue to continue running the queue // processSpeechQueue to continue running the queue
Log.v("TtsService", "TTS processing: " + mCurrentSpeechItem.mText); Log.v(SERVICE_TAG, "TTS processing: " + mCurrentSpeechItem.mText);
if (sr == null) { if (sr == null) {
if (mCurrentSpeechItem.mType == SpeechItem.TEXT) { if (mCurrentSpeechItem.mType == SpeechItem.TEXT) {
mCurrentSpeechItem = splitCurrentTextIfNeeded(mCurrentSpeechItem); mCurrentSpeechItem = splitCurrentTextIfNeeded(mCurrentSpeechItem);
@@ -951,7 +952,7 @@ public class TtsService extends Service implements OnCompletionListener {
mSpeechQueue.remove(0); mSpeechQueue.remove(0);
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.e("TtsService", "TTS processSpeechQueue: tryLock interrupted"); Log.e(SERVICE_TAG, "TTS processSpeechQueue: tryLock interrupted");
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
// This check is needed because finally will always run; even if the // This check is needed because finally will always run; even if the