Loading packages/TtsService/src/android/tts/TtsService.java +30 −5 Original line number Original line Diff line number Diff line Loading @@ -89,6 +89,8 @@ public class TtsService extends Service implements OnCompletionListener { } } } } private static final int MAX_SPEECH_ITEM_CHAR_LENGTH = 4000; private static final String ACTION = "android.intent.action.USE_TTS"; private static final String ACTION = "android.intent.action.USE_TTS"; 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"; Loading @@ -108,7 +110,6 @@ public class TtsService extends Service implements OnCompletionListener { private final ReentrantLock synthesizerLock = new ReentrantLock(); private final ReentrantLock synthesizerLock = new ReentrantLock(); private SynthProxy nativeSynth; private SynthProxy nativeSynth; @Override @Override public void onCreate() { public void onCreate() { super.onCreate(); super.onCreate(); Loading Loading @@ -145,13 +146,11 @@ public class TtsService extends Service implements OnCompletionListener { private void setDefaultSettings() { private void setDefaultSettings() { // TODO handle default language // TODO handle default language setLanguage("eng", "USA", ""); setLanguage("eng", "USA", ""); // speech rate // speech rate setSpeechRate(getDefaultRate()); setSpeechRate(getDefaultRate()); } } Loading Loading @@ -445,6 +444,33 @@ public class TtsService extends Service implements OnCompletionListener { Log.i("TTS callback", "dispatch completed to " + N); Log.i("TTS callback", "dispatch completed to " + N); } } private SpeechItem splitCurrentTextIfNeeded(SpeechItem currentSpeechItem){ if (currentSpeechItem.mText.length() < MAX_SPEECH_ITEM_CHAR_LENGTH){ return currentSpeechItem; } else { ArrayList<SpeechItem> splitItems = new ArrayList<SpeechItem>(); int start = 0; int end = start + MAX_SPEECH_ITEM_CHAR_LENGTH - 1; String splitText; SpeechItem splitItem; while (end < currentSpeechItem.mText.length()){ splitText = currentSpeechItem.mText.substring(start, end); splitItem = new SpeechItem(splitText, null, SpeechItem.SPEECH); splitItems.add(splitItem); start = end; end = start + MAX_SPEECH_ITEM_CHAR_LENGTH - 1; } splitText = currentSpeechItem.mText.substring(start); splitItem = new SpeechItem(splitText, null, SpeechItem.SPEECH); splitItems.add(splitItem); mSpeechQueue.remove(0); for (int i = splitItems.size() - 1; i >= 0; i--){ mSpeechQueue.add(0, splitItems.get(i)); } return mSpeechQueue.get(0); } } private void processSpeechQueue() { private void processSpeechQueue() { boolean speechQueueAvailable = false; boolean speechQueueAvailable = false; try { try { Loading @@ -466,8 +492,7 @@ public class TtsService extends Service implements OnCompletionListener { Log.i("TTS processing: ", currentSpeechItem.mText); Log.i("TTS processing: ", currentSpeechItem.mText); if (sr == null) { if (sr == null) { if (currentSpeechItem.mType == SpeechItem.SPEECH) { if (currentSpeechItem.mType == SpeechItem.SPEECH) { // TODO: Split text up into smaller chunks before accepting currentSpeechItem = splitCurrentTextIfNeeded(currentSpeechItem); // them for processing. speakInternalOnly(currentSpeechItem.mText, speakInternalOnly(currentSpeechItem.mText, currentSpeechItem.mParams); currentSpeechItem.mParams); } else { } else { Loading Loading
packages/TtsService/src/android/tts/TtsService.java +30 −5 Original line number Original line Diff line number Diff line Loading @@ -89,6 +89,8 @@ public class TtsService extends Service implements OnCompletionListener { } } } } private static final int MAX_SPEECH_ITEM_CHAR_LENGTH = 4000; private static final String ACTION = "android.intent.action.USE_TTS"; private static final String ACTION = "android.intent.action.USE_TTS"; 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"; Loading @@ -108,7 +110,6 @@ public class TtsService extends Service implements OnCompletionListener { private final ReentrantLock synthesizerLock = new ReentrantLock(); private final ReentrantLock synthesizerLock = new ReentrantLock(); private SynthProxy nativeSynth; private SynthProxy nativeSynth; @Override @Override public void onCreate() { public void onCreate() { super.onCreate(); super.onCreate(); Loading Loading @@ -145,13 +146,11 @@ public class TtsService extends Service implements OnCompletionListener { private void setDefaultSettings() { private void setDefaultSettings() { // TODO handle default language // TODO handle default language setLanguage("eng", "USA", ""); setLanguage("eng", "USA", ""); // speech rate // speech rate setSpeechRate(getDefaultRate()); setSpeechRate(getDefaultRate()); } } Loading Loading @@ -445,6 +444,33 @@ public class TtsService extends Service implements OnCompletionListener { Log.i("TTS callback", "dispatch completed to " + N); Log.i("TTS callback", "dispatch completed to " + N); } } private SpeechItem splitCurrentTextIfNeeded(SpeechItem currentSpeechItem){ if (currentSpeechItem.mText.length() < MAX_SPEECH_ITEM_CHAR_LENGTH){ return currentSpeechItem; } else { ArrayList<SpeechItem> splitItems = new ArrayList<SpeechItem>(); int start = 0; int end = start + MAX_SPEECH_ITEM_CHAR_LENGTH - 1; String splitText; SpeechItem splitItem; while (end < currentSpeechItem.mText.length()){ splitText = currentSpeechItem.mText.substring(start, end); splitItem = new SpeechItem(splitText, null, SpeechItem.SPEECH); splitItems.add(splitItem); start = end; end = start + MAX_SPEECH_ITEM_CHAR_LENGTH - 1; } splitText = currentSpeechItem.mText.substring(start); splitItem = new SpeechItem(splitText, null, SpeechItem.SPEECH); splitItems.add(splitItem); mSpeechQueue.remove(0); for (int i = splitItems.size() - 1; i >= 0; i--){ mSpeechQueue.add(0, splitItems.get(i)); } return mSpeechQueue.get(0); } } private void processSpeechQueue() { private void processSpeechQueue() { boolean speechQueueAvailable = false; boolean speechQueueAvailable = false; try { try { Loading @@ -466,8 +492,7 @@ public class TtsService extends Service implements OnCompletionListener { Log.i("TTS processing: ", currentSpeechItem.mText); Log.i("TTS processing: ", currentSpeechItem.mText); if (sr == null) { if (sr == null) { if (currentSpeechItem.mType == SpeechItem.SPEECH) { if (currentSpeechItem.mType == SpeechItem.SPEECH) { // TODO: Split text up into smaller chunks before accepting currentSpeechItem = splitCurrentTextIfNeeded(currentSpeechItem); // them for processing. speakInternalOnly(currentSpeechItem.mText, speakInternalOnly(currentSpeechItem.mText, currentSpeechItem.mParams); currentSpeechItem.mParams); } else { } else { Loading