Loading core/java/android/speech/tts/FileSynthesisCallback.java +27 −0 Original line number Diff line number Diff line Loading @@ -95,6 +95,22 @@ class FileSynthesisCallback extends AbstractSynthesisCallback { } } /** * Checks whether a given file exists, and deletes it if it does. */ private boolean maybeCleanupExistingFile(File file) { if (file.exists()) { Log.v(TAG, "File " + file + " exists, deleting."); if (!file.delete()) { Log.e(TAG, "Failed to delete " + file); return false; } } return true; } @Override public int getMaxBufferSize() { return MAX_AUDIO_BUFFER_SIZE; Loading @@ -120,6 +136,11 @@ class FileSynthesisCallback extends AbstractSynthesisCallback { cleanUp(); throw new IllegalArgumentException("FileSynthesisRequest.start() called twice"); } if (!maybeCleanupExistingFile(mFileName)) { return TextToSpeech.ERROR; } mSampleRateInHz = sampleRateInHz; mAudioFormat = audioFormat; mChannelCount = channelCount; Loading Loading @@ -166,6 +187,12 @@ class FileSynthesisCallback extends AbstractSynthesisCallback { public int done() { if (DBG) Log.d(TAG, "FileSynthesisRequest.done()"); synchronized (mStateLock) { if (mDone) { if (DBG) Log.d(TAG, "Duplicate call to done()"); // This preserves existing behaviour. Earlier, if done was called twice // we'd return ERROR because mFile == null and we'd add to logspam. return TextToSpeech.ERROR; } if (mStopped) { if (DBG) Log.d(TAG, "Request has been aborted."); return TextToSpeech.ERROR; Loading core/java/android/speech/tts/TextToSpeechService.java +1 −36 Original line number Diff line number Diff line Loading @@ -549,7 +549,7 @@ public abstract class TextToSpeechService extends Service { @Override public boolean isValid() { if (mText == null) { Log.wtf(TAG, "Got null text"); Log.e(TAG, "null synthesis text"); return false; } if (mText.length() >= MAX_SPEECH_ITEM_CHAR_LENGTH) { Loading Loading @@ -640,14 +640,6 @@ public abstract class TextToSpeechService extends Service { mFile = file; } @Override public boolean isValid() { if (!super.isValid()) { return false; } return checkFile(mFile); } @Override protected AbstractSynthesisCallback createSynthesisCallback() { return new FileSynthesisCallback(mFile); Loading @@ -664,33 +656,6 @@ public abstract class TextToSpeechService extends Service { } return status; } /** * Checks that the given file can be used for synthesis output. */ private boolean checkFile(File file) { try { if (file.exists()) { Log.v(TAG, "File " + file + " exists, deleting."); if (!file.delete()) { Log.e(TAG, "Failed to delete " + file); return false; } } if (!file.createNewFile()) { Log.e(TAG, "Can't create file " + file); return false; } if (!file.delete()) { Log.e(TAG, "Failed to delete " + file); return false; } return true; } catch (IOException e) { Log.e(TAG, "Can't use " + file + " due to exception " + e); return false; } } } private class AudioSpeechItem extends SpeechItem { Loading Loading
core/java/android/speech/tts/FileSynthesisCallback.java +27 −0 Original line number Diff line number Diff line Loading @@ -95,6 +95,22 @@ class FileSynthesisCallback extends AbstractSynthesisCallback { } } /** * Checks whether a given file exists, and deletes it if it does. */ private boolean maybeCleanupExistingFile(File file) { if (file.exists()) { Log.v(TAG, "File " + file + " exists, deleting."); if (!file.delete()) { Log.e(TAG, "Failed to delete " + file); return false; } } return true; } @Override public int getMaxBufferSize() { return MAX_AUDIO_BUFFER_SIZE; Loading @@ -120,6 +136,11 @@ class FileSynthesisCallback extends AbstractSynthesisCallback { cleanUp(); throw new IllegalArgumentException("FileSynthesisRequest.start() called twice"); } if (!maybeCleanupExistingFile(mFileName)) { return TextToSpeech.ERROR; } mSampleRateInHz = sampleRateInHz; mAudioFormat = audioFormat; mChannelCount = channelCount; Loading Loading @@ -166,6 +187,12 @@ class FileSynthesisCallback extends AbstractSynthesisCallback { public int done() { if (DBG) Log.d(TAG, "FileSynthesisRequest.done()"); synchronized (mStateLock) { if (mDone) { if (DBG) Log.d(TAG, "Duplicate call to done()"); // This preserves existing behaviour. Earlier, if done was called twice // we'd return ERROR because mFile == null and we'd add to logspam. return TextToSpeech.ERROR; } if (mStopped) { if (DBG) Log.d(TAG, "Request has been aborted."); return TextToSpeech.ERROR; Loading
core/java/android/speech/tts/TextToSpeechService.java +1 −36 Original line number Diff line number Diff line Loading @@ -549,7 +549,7 @@ public abstract class TextToSpeechService extends Service { @Override public boolean isValid() { if (mText == null) { Log.wtf(TAG, "Got null text"); Log.e(TAG, "null synthesis text"); return false; } if (mText.length() >= MAX_SPEECH_ITEM_CHAR_LENGTH) { Loading Loading @@ -640,14 +640,6 @@ public abstract class TextToSpeechService extends Service { mFile = file; } @Override public boolean isValid() { if (!super.isValid()) { return false; } return checkFile(mFile); } @Override protected AbstractSynthesisCallback createSynthesisCallback() { return new FileSynthesisCallback(mFile); Loading @@ -664,33 +656,6 @@ public abstract class TextToSpeechService extends Service { } return status; } /** * Checks that the given file can be used for synthesis output. */ private boolean checkFile(File file) { try { if (file.exists()) { Log.v(TAG, "File " + file + " exists, deleting."); if (!file.delete()) { Log.e(TAG, "Failed to delete " + file); return false; } } if (!file.createNewFile()) { Log.e(TAG, "Can't create file " + file); return false; } if (!file.delete()) { Log.e(TAG, "Failed to delete " + file); return false; } return true; } catch (IOException e) { Log.e(TAG, "Can't use " + file + " due to exception " + e); return false; } } } private class AudioSpeechItem extends SpeechItem { Loading