summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-06-29 17:26:32 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-06-29 17:26:32 -0700
commitaa4f1f9edc94851a5892ba94af94002018821ddc (patch)
tree350e400a5265a1e4e570fc34442f5614de8dc873
parent22e8cbc32bd642bcb3e9b6f161ec662bcf45ff70 (diff)
parentddb0a803fd353fbaf0139cc8804499bc9dce7403 (diff)
downloadframeworks_base-aa4f1f9edc94851a5892ba94af94002018821ddc.zip
frameworks_base-aa4f1f9edc94851a5892ba94af94002018821ddc.tar.gz
frameworks_base-aa4f1f9edc94851a5892ba94af94002018821ddc.tar.bz2
Merge change 5711 into donut
* changes: Adding in TTS service support for language query and level of support.
-rwxr-xr-xcore/java/android/speech/tts/ITts.aidl4
-rwxr-xr-xcore/java/android/speech/tts/TextToSpeech.java46
-rwxr-xr-xpackages/TtsService/src/android/tts/TtsService.java38
3 files changed, 82 insertions, 6 deletions
diff --git a/core/java/android/speech/tts/ITts.aidl b/core/java/android/speech/tts/ITts.aidl
index 47976e5..15f3876 100755
--- a/core/java/android/speech/tts/ITts.aidl
+++ b/core/java/android/speech/tts/ITts.aidl
@@ -43,6 +43,10 @@ interface ITts {
void addSpeechFile(in String text, in String filename);
+ String[] getLanguage();
+
+ int isLanguageAvailable(in String language, in String country, in String variant);
+
void setLanguage(in String language, in String country, in String variant);
boolean synthesizeToFile(in String text, in String[] params, in String outputDirectory);
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java
index f3b8963..b245713 100755
--- a/core/java/android/speech/tts/TextToSpeech.java
+++ b/core/java/android/speech/tts/TextToSpeech.java
@@ -657,17 +657,55 @@ public class TextToSpeech {
/**
- * Checks if the specified language as represented by the locale is available.
+ * Returns a Locale instance describing the language currently being used by the TTS engine.
+ * @return language, country (if any) and variant (if any) used by the engine stored in a Locale
+ * instance, or null is the TTS engine has failed.
+ */
+ public Locale getLanguage() {
+ synchronized (mStartLock) {
+ if (!mStarted) {
+ return null;
+ }
+ try {
+ String[] locStrings = mITts.getLanguage();
+ if (locStrings.length == 3) {
+ return new Locale(locStrings[0], locStrings[1], locStrings[2]);
+ } else {
+ return null;
+ }
+ } catch (RemoteException e) {
+ // TTS died; restart it.
+ mStarted = false;
+ initTts();
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Checks if the specified language as represented by the Locale is available.
*
* @param loc
- * The locale describing the language to be used.
+ * The Locale describing the language to be used.
*
* @return one of TTS_LANG_NOT_SUPPORTED, TTS_LANG_MISSING_DATA, TTS_LANG_AVAILABLE,
* TTS_LANG_COUNTRY_AVAILABLE, TTS_LANG_COUNTRY_VAR_AVAILABLE.
*/
public int isLanguageAvailable(Locale loc) {
- //TODO: Implement isLanguageAvailable
- return TTS_LANG_NOT_SUPPORTED;
+ synchronized (mStartLock) {
+ if (!mStarted) {
+ return TTS_LANG_NOT_SUPPORTED;
+ }
+ try {
+ return mITts.isLanguageAvailable(loc.getISO3Language(), loc.getISO3Country(),
+ loc.getVariant());
+ } catch (RemoteException e) {
+ // TTS died; restart it.
+ mStarted = false;
+ initTts();
+ }
+ return TTS_LANG_NOT_SUPPORTED;
+ }
}
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java
index c6b5bee..ff2254a 100755
--- a/packages/TtsService/src/android/tts/TtsService.java
+++ b/packages/TtsService/src/android/tts/TtsService.java
@@ -148,8 +148,7 @@ public class TtsService extends Service implements OnCompletionListener {
private void setDefaultSettings() {
- // TODO handle default language
- setLanguage("eng", "USA", "");
+ setLanguage(this.getDefaultLanguage(), getDefaultLanguage(), getDefaultLocVariant());
// speech rate
setSpeechRate(getDefaultRate());
@@ -218,6 +217,17 @@ public class TtsService extends Service implements OnCompletionListener {
}
+ private int isLanguageAvailable(String lang, String country, String variant) {
+ Log.v("TTS", "TtsService.isLanguageAvailable(" + lang + ", " + country + ", " +variant+")");
+ return nativeSynth.isLanguageAvailable(lang, country, variant);
+ }
+
+
+ private String[] getLanguage() {
+ return nativeSynth.getLanguage();
+ }
+
+
private void setLanguage(String lang, String country, String variant) {
Log.v("TTS", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")");
if (isDefaultEnforced()) {
@@ -893,6 +903,30 @@ public class TtsService extends Service implements OnCompletionListener {
}
/**
+ * Returns the level of support for the specified language.
+ *
+ * @param lang the three letter ISO language code.
+ * @param country the three letter ISO country code.
+ * @param variant the variant code associated with the country and language pair.
+ * @return one of TTS_LANG_NOT_SUPPORTED, TTS_LANG_MISSING_DATA, TTS_LANG_AVAILABLE,
+ * TTS_LANG_COUNTRY_AVAILABLE, TTS_LANG_COUNTRY_VAR_AVAILABLE as defined in
+ * android.speech.tts.TextToSpeech.
+ */
+ public int isLanguageAvailable(String lang, String country, String variant) {
+ return mSelf.isLanguageAvailable(lang, country, variant);
+ }
+
+ /**
+ * Returns the currently set language / country / variant strings representing the
+ * language used by the TTS engine.
+ * @return null is no language is set, or an array of 3 string containing respectively
+ * the language, country and variant.
+ */
+ public String[] getLanguage() {
+ return mSelf.getLanguage();
+ }
+
+ /**
* Sets the speech rate for the TTS, which affects the synthesized voice.
*
* @param lang the three letter ISO language code.