diff options
| author | Jean-Michel Trivi <jmtrivi@google.com> | 2009-06-16 15:36:28 -0700 | 
|---|---|---|
| committer | Jean-Michel Trivi <jmtrivi@google.com> | 2009-06-17 10:16:17 -0700 | 
| commit | 679d728f09eeab2f8b882e42f6e081db1ac74996 (patch) | |
| tree | 3b9301c16f53e0e09a9c3c0b372ae7105f6f6f7b /core/java/android/speech | |
| parent | f1170fb5386ea86d704480d321ee9d1ee4858244 (diff) | |
| download | frameworks_base-679d728f09eeab2f8b882e42f6e081db1ac74996.zip frameworks_base-679d728f09eeab2f8b882e42f6e081db1ac74996.tar.gz frameworks_base-679d728f09eeab2f8b882e42f6e081db1ac74996.tar.bz2 | |
Using Locale to specify language and country for a TTS language to load,
rather than a String.
Cleanup in doc for TextToSpeech, and addition of queue mode constants.
Diffstat (limited to 'core/java/android/speech')
| -rwxr-xr-x | core/java/android/speech/tts/ITts.aidl | 2 | ||||
| -rwxr-xr-x | core/java/android/speech/tts/TextToSpeech.java | 72 | 
2 files changed, 38 insertions, 36 deletions
| diff --git a/core/java/android/speech/tts/ITts.aidl b/core/java/android/speech/tts/ITts.aidl index 739a8e4..02211fd 100755 --- a/core/java/android/speech/tts/ITts.aidl +++ b/core/java/android/speech/tts/ITts.aidl @@ -39,7 +39,7 @@ interface ITts {      void addSpeechFile(in String text, in String filename);
 -    void setLanguage(in String language);
 +    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 2c0c09e..8f58194 100755 --- a/core/java/android/speech/tts/TextToSpeech.java +++ b/core/java/android/speech/tts/TextToSpeech.java @@ -22,13 +22,12 @@ import android.content.ComponentName;  import android.content.Context;  import android.content.Intent;  import android.content.ServiceConnection; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo;  import android.os.IBinder;  import android.os.RemoteException;  import android.util.Log;  import java.util.HashMap; +import java.util.Locale;  /**   * @@ -36,7 +35,7 @@ import java.util.HashMap;   *   * {@hide}   */ -//TODO #TTS# review + complete javadoc +//TODO #TTS# review + complete javadoc + add links to constants  public class TextToSpeech {      /** @@ -52,9 +51,18 @@ public class TextToSpeech {       */      public static final int TTS_ERROR_MISSING_RESOURCE = -2; +    /** +     * Queue mode where all entries in the playback queue (media to be played +     * and text to be synthesized) are dropped and replaced by the new entry. +     */ +    public static final int TTS_QUEUE_FLUSH = 0; +    /** +     * Queue mode where the new entry is added at the end of the playback queue. +     */ +    public static final int TTS_QUEUE_ADD = 1;      /** -     * Called when the TTS has initialized +     * Called when the TTS has initialized.       *       * The InitListener must implement the onInit function. onInit is passed a       * status code indicating the result of the TTS initialization. @@ -73,9 +81,9 @@ public class TextToSpeech {      }      /** -     * Connection needed for the TTS +     * Connection needed for the TTS.       */ -    private ServiceConnection serviceConnection; +    private ServiceConnection mServiceConnection;      private ITts mITts = null;      private Context mContext = null; @@ -104,8 +112,7 @@ public class TextToSpeech {      } -    public void setOnSpeechCompletedListener( -            final OnSpeechCompletedListener listener) { +    public void setOnSpeechCompletedListener(final OnSpeechCompletedListener listener) {          synchronized(mSpeechCompListenerLock) {              mSpeechCompListener = listener;          } @@ -126,7 +133,7 @@ public class TextToSpeech {          mStarted = false;          // Initialize the TTS, run the callback after the binding is successful -        serviceConnection = new ServiceConnection() { +        mServiceConnection = new ServiceConnection() {              public void onServiceConnected(ComponentName name, IBinder service) {                  synchronized(mStartLock) {                      mITts = ITts.Stub.asInterface(service); @@ -176,7 +183,7 @@ public class TextToSpeech {          Intent intent = new Intent("android.intent.action.USE_TTS");          intent.addCategory("android.intent.category.TTS"); -        mContext.bindService(intent, serviceConnection, +        mContext.bindService(intent, mServiceConnection,                  Context.BIND_AUTO_CREATE);          // TODO handle case where the binding works (should always work) but          //      the plugin fails @@ -190,7 +197,7 @@ public class TextToSpeech {       */      public void shutdown() {          try { -            mContext.unbindService(serviceConnection); +            mContext.unbindService(mServiceConnection);          } catch (IllegalArgumentException e) {              // Do nothing and fail silently since an error here indicates that              // binding never succeeded in the first place. @@ -291,8 +298,8 @@ public class TextToSpeech {       * @param text       *            The string of text to be spoken.       * @param queueMode -     *            The queuing strategy to use. Use 0 for no queuing, and 1 for -     *            queuing. +     *            The queuing strategy to use. +     *            See TTS_QUEUE_ADD and TTS_QUEUE_FLUSH.       * @param params       *            The hashmap of speech parameters to be used.       */ @@ -329,12 +336,11 @@ public class TextToSpeech {       * @param earcon       *            The earcon that should be played       * @param queueMode -     *            0 for no queue (interrupts all previous utterances), 1 for -     *            queued +     *            See TTS_QUEUE_ADD and TTS_QUEUE_FLUSH.       * @param params       *            The hashmap of parameters to be used.       */ -    public void playEarcon(String earcon, int queueMode,  +    public void playEarcon(String earcon, int queueMode,              HashMap<String,String> params) {          synchronized (mStartLock) {              if (!mStarted) { @@ -358,8 +364,8 @@ public class TextToSpeech {              }          }      } -     -     + +      public void playSilence(long durationInMs, int queueMode) {          // TODO implement, already present in TTS service      } @@ -429,20 +435,22 @@ public class TextToSpeech {       * Note that the speech rate is not universally supported by all engines and       * will be treated as a hint. The TTS library will try to use the specified       * speech rate, but there is no guarantee. -     * -     * Currently, this will change the speech rate for the espeak engine, but it -     * has no effect on any pre-recorded speech. +     * This has no effect on any pre-recorded speech.       *       * @param speechRate -     *            The speech rate for the TTS engine. +     *            The speech rate for the TTS engine. 1 is the normal speed, +     *            lower values slow down the speech (0.5 is half the normal speech rate), +     *            greater values accelerate it (2 is twice the normal speech rate).       */ -    public void setSpeechRate(int speechRate) { +    public void setSpeechRate(float speechRate) {          synchronized (mStartLock) {              if (!mStarted) {                  return;              }              try { -                mITts.setSpeechRate(speechRate); +                if (speechRate > 0) { +                    mITts.setSpeechRate((int)(speechRate*100)); +                }              } catch (RemoteException e) {                  // TTS died; restart it.                  mStarted = false; @@ -457,24 +465,18 @@ public class TextToSpeech {       *       * Note that the language is not universally supported by all engines and       * will be treated as a hint. The TTS library will try to use the specified -     * language, but there is no guarantee. -     * -     * Currently, this will change the language for the espeak engine, but it -     * has no effect on any pre-recorded speech. +     * language as represented by the Locale, but there is no guarantee.       * -     * @param language -     *            The language to be used. The languages are specified by their -     *            IETF language tags as defined by BCP 47. This is the same -     *            standard used for the lang attribute in HTML. See: -     *            http://en.wikipedia.org/wiki/IETF_language_tag +     * @param loc +     *            The locale describing the language to be used.       */ -    public void setLanguage(String language) { +    public void setLanguage(Locale loc) {          synchronized (mStartLock) {              if (!mStarted) {                  return;              }              try { -                mITts.setLanguage(language); +                mITts.setLanguage(loc.getISO3Language(), loc.getISO3Country(), loc.getVariant());              } catch (RemoteException e) {                  // TTS died; restart it.                  mStarted = false; | 
