Merge change 5711 into donut

* changes:
  Adding in TTS service support for language query and level of support.
This commit is contained in:
Android (Google) Code Review
2009-06-29 17:26:32 -07:00
3 changed files with 82 additions and 6 deletions

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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()) {
@@ -892,6 +902,30 @@ public class TtsService extends Service implements OnCompletionListener {
mSelf.setPitch(pitch);
}
/**
* 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.
*