android.speech.tts.TextToSpeech.OnInitListener Java Examples

The following examples show how to use android.speech.tts.TextToSpeech.OnInitListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From dialogflow-java-client with Apache License 2.0 5 votes vote down vote up
private void initTTS() {
    ttsEngine = new TextToSpeech(this, new OnInitListener() {
        @Override
        public void onInit(int initStatus) {
            if (initStatus == TextToSpeech.SUCCESS) {
                ttsEngine.setLanguage(Locale.US);
                ttsReady = true;
            } else {
                Log.d(TAG, "Can't initialize TextToSpeech");
            }

        }
    });
}
 
Example #2
Source File: AnnouncementPeriodicTask.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
  if (tts == null) {
    tts = newTextToSpeech(context, new OnInitListener() {
        @Override
      public void onInit(int status) {
        initStatus = status;
      }
    });
  }
  speechAllowed = true;
  listenToPhoneState(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
 
Example #3
Source File: AnnouncementPeriodicTaskTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
public void testStart() {
  doStart();
  OnInitListener ttsInitListener = initListenerCapture.getValue();
  assertNotNull(ttsInitListener);

  AndroidMock.replay(tts);

  ttsInitListener.onInit(TextToSpeech.SUCCESS);

  AndroidMock.verify(mockTask, tts);
}
 
Example #4
Source File: AnnouncementPeriodicTaskTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
public void testStart_notReady() {
  doStart();
  OnInitListener ttsInitListener = initListenerCapture.getValue();
  assertNotNull(ttsInitListener);

  AndroidMock.replay(tts);

  ttsInitListener.onInit(TextToSpeech.ERROR);

  AndroidMock.verify(mockTask, tts);
}
 
Example #5
Source File: AnnouncementPeriodicTaskTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
private void startTask(int state) {
  AndroidMock.resetToNice(tts);
  AndroidMock.replay(tts);
  doStart();
  OnInitListener ttsInitListener = initListenerCapture.getValue();
  ttsInitListener.onInit(state);
  AndroidMock.resetToDefault(tts);
}
 
Example #6
Source File: NaviVoice.java    From PocketMaps with MIT License 5 votes vote down vote up
private OnInitListener createInitListener()
{
  OnInitListener initList = new OnInitListener()
  {
    @Override
    public void onInit(int result)
    {
      if (result==TextToSpeech.SUCCESS) { ttsReady = true; }
    }
  };
  return initList;
}
 
Example #7
Source File: TextToSpeechICS.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
static TextToSpeech construct(Context context, OnInitListener onInitListener,
        String engineName) {
    if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        if (engineName == null) {
            return new TextToSpeech(context, onInitListener);
        } else {
            Log.w(TAG, "Can't specify tts engine on this device");
            return new TextToSpeech(context, onInitListener);
        }
    } else {
        return new TextToSpeech(context, onInitListener, engineName);
    }
}
 
Example #8
Source File: TtsHelper.java    From coolreader with MIT License 5 votes vote down vote up
public TtsHelper(Context context, OnInitListener listener, OnCompleteListener onComplete) {
	tts = new TextToSpeech(context, this);
	this.listener = listener;
	this.onCompleteListener = onComplete;

	queue = new ArrayList<SpeakValue>();
	currentQueueIndex = 0;
}
 
Example #9
Source File: AnnouncementPeriodicTaskTest.java    From mytracks with Apache License 2.0 4 votes vote down vote up
public TextToSpeechDelegate(Context context, OnInitListener listener) {
  super(context, listener);
}
 
Example #10
Source File: AnnouncementPeriodicTaskTest.java    From mytracks with Apache License 2.0 4 votes vote down vote up
@UsesMocks({
  AnnouncementPeriodicTask.class,
  StringUtils.class,
})
@Override
protected void setUp() throws Exception {
  super.setUp();

  oldDefaultLocale = Locale.getDefault();
  Locale.setDefault(DEFAULT_LOCALE);

  // Eww, the effort required just to mock TextToSpeech is insane
  final AtomicBoolean listenerCalled = new AtomicBoolean();
  OnInitListener blockingListener = new OnInitListener() {
    @Override
    public void onInit(int status) {
      synchronized (this) {
        listenerCalled.set(true);
        notify();
      }
    }
  };

  ttsDelegate = new TextToSpeechDelegate(getContext(), blockingListener);

  // Wait for all async operations done in the constructor to finish.
  synchronized (blockingListener) {
    while (!listenerCalled.get()) {
      // Releases the synchronized lock until we're woken up.
      blockingListener.wait();
    }
  }

  // Phew, done, now we can start forwarding calls
  tts = AndroidMock.createMock(TextToSpeechInterface.class);

  initListenerCapture = new Capture<OnInitListener>();
  phoneListenerCapture = new Capture<PhoneStateListener>();

  // Create a partial forwarding mock
  mockTask = AndroidMock.createMock(AnnouncementPeriodicTask.class, getContext());
  task = new AnnouncementPeriodicTask(getContext()) {
    @Override
    protected TextToSpeech newTextToSpeech(Context ctx,
        OnInitListener onInitListener) {
      return mockTask.newTextToSpeech(ctx, onInitListener);
    }

    @Override
    protected String getAnnouncement(TripStatistics stats) {
      return mockTask.getAnnouncement(stats);
    }

    @Override
    protected void listenToPhoneState(
        PhoneStateListener listener, int events) {
      mockTask.listenToPhoneState(listener, events);
    }
  };
}
 
Example #11
Source File: TtsService.java    From coolreader with MIT License 4 votes vote down vote up
public void setOnInitListener(OnInitListener onInit) {
	this.onInitListener = onInit;
}
 
Example #12
Source File: AnnouncementPeriodicTask.java    From mytracks with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new {@link TextToSpeech}.
 * 
 * @param aContext a context
 * @param onInitListener an on init listener
 */
@VisibleForTesting
protected TextToSpeech newTextToSpeech(Context aContext, OnInitListener onInitListener) {
  return new TextToSpeech(aContext, onInitListener);
}