diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2010-03-09 10:31:30 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-03-09 10:31:30 -0800 |
commit | f4743a869d8ee74b55a5f6335a554b011cfa33ab (patch) | |
tree | 56f8dd9aae03714fbf95b26a665577d3996f99f4 /packages/TtsService | |
parent | 6509662adb12a506f3d584630f78d0edc9a62922 (diff) | |
parent | b21651c10ca833e073337ae6a0ee55fcc39c32f1 (diff) | |
download | frameworks_base-f4743a869d8ee74b55a5f6335a554b011cfa33ab.zip frameworks_base-f4743a869d8ee74b55a5f6335a554b011cfa33ab.tar.gz frameworks_base-f4743a869d8ee74b55a5f6335a554b011cfa33ab.tar.bz2 |
Merge "Fix bug 2481825 When TTS is synthesizing to a file, return an error if the file cannot be created."
Diffstat (limited to 'packages/TtsService')
-rwxr-xr-x | packages/TtsService/src/android/tts/TtsService.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java index 7f76425..6b7ab3f 100755 --- a/packages/TtsService/src/android/tts/TtsService.java +++ b/packages/TtsService/src/android/tts/TtsService.java @@ -38,6 +38,7 @@ import android.speech.tts.TextToSpeech; import android.util.Log; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -1112,7 +1113,7 @@ public class TtsService extends Service implements OnCompletionListener { * @param filename * The string that gives the full output filename; it should be * something like "/sdcard/myappsounds/mysound.wav". - * @return A boolean that indicates if the synthesis succeeded + * @return A boolean that indicates if the synthesis can be started */ private boolean synthesizeToFile(String callingApp, String text, ArrayList<String> params, String filename) { @@ -1125,6 +1126,22 @@ public class TtsService extends Service implements OnCompletionListener { if (text.length() >= MAX_SPEECH_ITEM_CHAR_LENGTH){ return false; } + // Check that the output file can be created + try { + File tempFile = new File(filename); + if (tempFile.exists()) { + Log.v("TtsService", "File " + filename + " exists, deleting."); + tempFile.delete(); + } + if (!tempFile.createNewFile()) { + Log.e("TtsService", "Unable to synthesize to file: can't create " + filename); + return false; + } + tempFile.delete(); + } catch (IOException e) { + Log.e("TtsService", "Can't create " + filename + " due to exception " + e); + return false; + } mSpeechQueue.add(new SpeechItem(callingApp, text, params, SpeechItem.TEXT_TO_FILE, filename)); if (!mIsSpeaking) { processSpeechQueue(); |