Android Open Source - callerid-for-android Text To Speech Helper






From Project

Back to project page callerid-for-android.

License

The source code is released under:

GNU General Public License

If you think the Android project callerid-for-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.integralblue.callerid.inject;
/*w ww  .  jav a2  s  .  c  o m*/
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;

import com.google.inject.Inject;

import android.app.Application;
import android.speech.tts.TextToSpeech;

public class TextToSpeechHelper {
  
  @Inject Application application;
  
  private class QueuedSpeak implements Runnable {
    final String text;
    final int queueMode;
    final HashMap<String, String> params;
    
    public QueuedSpeak(final String text, final int queueMode,
        final HashMap<String, String> params) {
      this.text = text;
      this.queueMode = queueMode;
      this.params = params;
    }

    public void run() {
      textToSpeech.speak(text, queueMode, params);
    }
    
  }
  
  TextToSpeech textToSpeech;
  final Object startedLock = new Object();
  boolean started = false;
  final Queue<QueuedSpeak> queuedSpeaks = new LinkedList<TextToSpeechHelper.QueuedSpeak>();
  
  public void speak(String text, int queueMode, HashMap<String, String> params){
    synchronized (startedLock) {
      if(started){
        textToSpeech.speak(text, queueMode, params);
      }else{
        queuedSpeaks.add(new QueuedSpeak(text, queueMode, params));
        if(textToSpeech==null){
          textToSpeech = new TextToSpeech(application,new TextToSpeech.OnInitListener() {
            public void onInit(int status) {
              synchronized (startedLock) {
                started = true;
                for (QueuedSpeak queuedSpeak; (queuedSpeak = queuedSpeaks.poll()) != null;){
                  queuedSpeak.run();
                }
              }
            }
          });
        }
      }
    }
  }

  public void stop(){
    synchronized (startedLock) {
      if(started){
        textToSpeech.stop();
      }
      queuedSpeaks.clear();
    }
  }
  
  public void shutdown(){
    synchronized (startedLock) {
      if(started){
        started = false;
        textToSpeech.shutdown();
      }
      textToSpeech = null;
      queuedSpeaks.clear();
    }
  }
}




Java Source Code List

com.blundell.tut.LoaderImageView.java
com.integralblue.callerid.CallerIDApplication.java
com.integralblue.callerid.CallerIDBroadcastReceiver.java
com.integralblue.callerid.CallerIDLookup.java
com.integralblue.callerid.CallerIDResult.java
com.integralblue.callerid.CallerIDService.java
com.integralblue.callerid.GeocoderAsyncTask.java
com.integralblue.callerid.HttpCallerIDLookup.java
com.integralblue.callerid.LookupAsyncTask.java
com.integralblue.callerid.LookupFragment.java
com.integralblue.callerid.MainActivity.java
com.integralblue.callerid.PreferencesActivity.java
com.integralblue.callerid.RecentCallsFragment.java
com.integralblue.callerid.SpecialPhoneNumbers.java
com.integralblue.callerid.TabsAdapter.java
com.integralblue.callerid.contacts.ContactsHelper.java
com.integralblue.callerid.contacts.NewContactsHelper.java
com.integralblue.callerid.contacts.OldContactsHelper.java
com.integralblue.callerid.geocoder.AndroidGeocoder.java
com.integralblue.callerid.geocoder.Geocoder.java
com.integralblue.callerid.geocoder.NominatimGeocoder.java
com.integralblue.callerid.inject.CallerIDModule.java
com.integralblue.callerid.inject.ContactsHelperProvider.java
com.integralblue.callerid.inject.CountryDetector.java
com.integralblue.callerid.inject.GeocoderHelperProvider.java
com.integralblue.callerid.inject.PreferencesNameProvider.java
com.integralblue.callerid.inject.RestTemplateProvider.java
com.integralblue.callerid.inject.TextToSpeechHelper.java
com.integralblue.callerid.inject.VersionInformationHelper.java
com.integralblue.callerid.widget.DontPressWithParentImageView.java
com.squareup.okhttp.OkHttpURLStreamHandlerFactory.java
com.squareup.okhttp.internal.OkHttpClientHandler.java