diff options
-rwxr-xr-x | core/java/android/speech/tts/ITts.aidl | 4 | ||||
-rwxr-xr-x | core/java/android/speech/tts/TextToSpeech.java | 46 | ||||
-rwxr-xr-x | packages/TtsService/src/android/tts/TtsService.java | 38 |
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. |