summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-06-30 14:08:30 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-06-30 14:08:30 -0700
commitf9eca3d43aed870774633a176aa691d3e530a12b (patch)
tree5f6b6c71ccb0c4c48b071694ec2a4a967f0544db
parent6e1647a212317f4ee8bcc23948b6621a59172954 (diff)
parentebb814bbaeacbdc04faa5683f25b12d40609548c (diff)
downloadframeworks_base-f9eca3d43aed870774633a176aa691d3e530a12b.zip
frameworks_base-f9eca3d43aed870774633a176aa691d3e530a12b.tar.gz
frameworks_base-f9eca3d43aed870774633a176aa691d3e530a12b.tar.bz2
Merge change 5807 into donut
* changes: Fixing synth to file to use the speech queue.
-rwxr-xr-xpackages/TtsService/src/android/tts/TtsService.java108
1 files changed, 81 insertions, 27 deletions
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java
index b1e6425..b5f5b37 100755
--- a/packages/TtsService/src/android/tts/TtsService.java
+++ b/packages/TtsService/src/android/tts/TtsService.java
@@ -51,10 +51,13 @@ public class TtsService extends Service implements OnCompletionListener {
public static final int IPA = 1;
public static final int EARCON = 2;
public static final int SILENCE = 3;
+ public static final int TEXT_TO_FILE = 5;
+ public static final int IPA_TO_FILE = 6;
public String mText = null;
public ArrayList<String> mParams = null;
public int mType = TEXT;
public long mDuration = 0;
+ public String mFilename = null;
public SpeechItem(String text, ArrayList<String> params, int itemType) {
mText = text;
@@ -65,6 +68,14 @@ public class TtsService extends Service implements OnCompletionListener {
public SpeechItem(long silenceTime) {
mDuration = silenceTime;
}
+
+ public SpeechItem(String text, ArrayList<String> params, int itemType, String filename) {
+ mText = text;
+ mParams = params;
+ mType = itemType;
+ mFilename = filename;
+ }
+
}
/**
@@ -464,6 +475,60 @@ public class TtsService extends Service implements OnCompletionListener {
synth.start();
}
+ private void synthToFileInternalOnly(final String text,
+ final ArrayList<String> params, final String filename) {
+ class SynthThread implements Runnable {
+ public void run() {
+ Log.i("TTS", "Synthesizing to " + filename);
+ boolean synthAvailable = false;
+ try {
+ synthAvailable = synthesizerLock.tryLock();
+ if (!synthAvailable) {
+ Thread.sleep(100);
+ Thread synth = (new Thread(new SynthThread()));
+ synth.setPriority(Thread.MIN_PRIORITY);
+ synth.start();
+ return;
+ }
+ if (params != null){
+ String language = "";
+ String country = "";
+ String variant = "";
+ for (int i = 0; i < params.size() - 1; i = i + 2){
+ String param = params.get(i);
+ if (param.equals(TextToSpeech.Engine.TTS_KEY_PARAM_RATE)){
+ setSpeechRate(Integer.parseInt(params.get(i+1)));
+ } else if (param.equals(TextToSpeech.Engine.TTS_KEY_PARAM_LANGUAGE)){
+ language = params.get(i+1);
+ } else if (param.equals(TextToSpeech.Engine.TTS_KEY_PARAM_COUNTRY)){
+ country = params.get(i+1);
+ } else if (param.equals(TextToSpeech.Engine.TTS_KEY_PARAM_VARIANT)){
+ variant = params.get(i+1);
+ }
+ }
+ if (language.length() > 0){
+ setLanguage(language, country, variant);
+ }
+ }
+ nativeSynth.synthesizeToFile(text, filename);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } finally {
+ // This check is needed because finally will always run;
+ // even if the
+ // method returns somewhere in the try block.
+ if (synthAvailable) {
+ synthesizerLock.unlock();
+ }
+ processSpeechQueue();
+ }
+ }
+ }
+ Thread synth = (new Thread(new SynthThread()));
+ synth.setPriority(Thread.MIN_PRIORITY);
+ synth.start();
+ }
+
private SoundResource getSoundResource(SpeechItem speechItem) {
SoundResource sr = null;
String text = speechItem.mText;
@@ -549,6 +614,9 @@ public class TtsService extends Service implements OnCompletionListener {
currentSpeechItem = splitCurrentTextIfNeeded(currentSpeechItem);
speakInternalOnly(currentSpeechItem.mText,
currentSpeechItem.mParams);
+ } else if (currentSpeechItem.mType == SpeechItem.TEXT_TO_FILE) {
+ synthToFileInternalOnly(currentSpeechItem.mText,
+ currentSpeechItem.mParams, currentSpeechItem.mFilename);
} else if (currentSpeechItem.mType == SpeechItem.IPA) {
// TODO Implement IPA support
} else {
@@ -629,34 +697,20 @@ public class TtsService extends Service implements OnCompletionListener {
* @return A boolean that indicates if the synthesis succeeded
*/
private boolean synthesizeToFile(String text, ArrayList<String> params,
- String filename, boolean calledFromApi) {
- // Only stop everything if this is a call made by an outside app trying
- // to
- // use the API. Do NOT stop if this is a call from within the service as
- // clearing the speech queue here would be a mistake.
- if (calledFromApi) {
- stop();
+ String filename) {
+ // Don't allow a filename that is too long
+ if (filename.length() > MAX_FILENAME_LENGTH) {
+ return false;
}
- Log.i("TTS", "Synthesizing to " + filename);
- boolean synthAvailable = false;
- try {
- synthAvailable = synthesizerLock.tryLock();
- if (!synthAvailable) {
- return false;
- }
- // Don't allow a filename that is too long
- if (filename.length() > MAX_FILENAME_LENGTH) {
- return false;
- }
- nativeSynth.synthesizeToFile(text, filename);
- } finally {
- // This check is needed because finally will always run; even if the
- // method returns somewhere in the try block.
- if (synthAvailable) {
- synthesizerLock.unlock();
- }
+ // Don't allow anything longer than the max text length; since this
+ // is synthing to a file, don't even bother splitting it.
+ if (text.length() >= MAX_SPEECH_ITEM_CHAR_LENGTH){
+ return false;
+ }
+ mSpeechQueue.add(new SpeechItem(text, params, SpeechItem.TEXT_TO_FILE, filename));
+ if (!mIsSpeaking) {
+ processSpeechQueue();
}
- Log.i("TTS", "Completed synthesis for " + filename);
return true;
}
@@ -957,7 +1011,7 @@ public class TtsService extends Service implements OnCompletionListener {
if (params != null) {
speakingParams = new ArrayList<String>(Arrays.asList(params));
}
- return mSelf.synthesizeToFile(text, speakingParams, filename, true);
+ return mSelf.synthesizeToFile(text, speakingParams, filename);
}
/**