Android Open Source - RavenChat T T S Service






From Project

Back to project page RavenChat.

License

The source code is released under:

Copyright (c) 2014 Sumit Gouthaman. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Softwar...

If you think the Android project RavenChat 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.sumitgouthaman.raven.services;
/*from   w  w w  .  j  av  a2s  . c om*/
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.util.Log;

import java.util.HashMap;
import java.util.Locale;

/**
 * Created by sumit on 30/5/14.
 */

/**
 * Service that invokes Text to Speech to speak out a message
 */
public class TTSService extends Service implements TextToSpeech.OnInitListener {

    private static final String TAG = "TTSService";
    private String str;
    private TextToSpeech mTts;

    @Override
    public void onCreate() {
        super.onCreate();
    }


    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        if (mTts != null) {
            mTts.stop();
            mTts.shutdown();
        }
        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        mTts = new TextToSpeech(this, this);
        str = intent.getStringExtra("text");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {
            int result = mTts.setLanguage(Locale.US);
            if (result == TextToSpeech.LANG_MISSING_DATA ||
                    result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Log.v(TAG, "Language is not available.");
                stopSelf();
            } else {
                sayHello(str);

            }
        } else {
            Log.v(TAG, "Could not initialize TextToSpeech.");
            stopSelf();
        }
    }

    @SuppressLint("NewApi")
    private void sayHello(String str) {
        mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
            @Override
            public void onStart(String s) {
            }

            @Override
            public void onDone(String s) {
                stopSelf();
            }

            @Override
            public void onError(String s) {
                stopSelf();
            }
        });
        HashMap<String, String> map = new HashMap<String, String>();
        map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "messageID");
        mTts.speak(str, TextToSpeech.QUEUE_FLUSH, map);
    }
}




Java Source Code List

com.sumitgouthaman.raven.AddContactActivity.java
com.sumitgouthaman.raven.ChatThreadActivity.java
com.sumitgouthaman.raven.DebugActivity.java
com.sumitgouthaman.raven.DispatchGCMMessage.java
com.sumitgouthaman.raven.GCMBroadcastReceiver.java
com.sumitgouthaman.raven.MessageListActivity.java
com.sumitgouthaman.raven.NFCPairing.java
com.sumitgouthaman.raven.SelfDestructingMessageCompose.java
com.sumitgouthaman.raven.SelfDestructingMessageDisplay.java
com.sumitgouthaman.raven.SettingsActivity.java
com.sumitgouthaman.raven.ShareViaRaven.java
com.sumitgouthaman.raven.IntentHelpers.IntentCreator.java
com.sumitgouthaman.raven.listadapters.ChatThreadAdapter.java
com.sumitgouthaman.raven.listadapters.MessageListAdapter.java
com.sumitgouthaman.raven.models.Contact.java
com.sumitgouthaman.raven.models.MessageListItem.java
com.sumitgouthaman.raven.models.MessageTypes.java
com.sumitgouthaman.raven.models.Message.java
com.sumitgouthaman.raven.persistence.Persistence.java
com.sumitgouthaman.raven.services.DispatchMessageIntentService.java
com.sumitgouthaman.raven.services.DispatchNameUpdateMessageIntentService.java
com.sumitgouthaman.raven.services.DispatchRegUpdateMessageIntentService.java
com.sumitgouthaman.raven.services.DispatchRejectionMessageIntentService.java
com.sumitgouthaman.raven.services.TTSService.java
com.sumitgouthaman.raven.utils.CheckPlayServices.java
com.sumitgouthaman.raven.utils.MessageDispatcher.java
com.sumitgouthaman.raven.utils.RandomStrings.java
com.sumitgouthaman.raven.utils.SimpleNotificationMaker.java
com.sumitgouthaman.raven.utils.SimpleSoundNotificationMaker.java
com.sumitgouthaman.raven.utils.StringToQRBitmap.java
com.sumitgouthaman.raven.utils.TimestampFormatter.java
com.sumitgouthaman.raven.utils.crypto.Base64Utils.java
com.sumitgouthaman.raven.utils.crypto.EncryptionUtils.java
com.sumitgouthaman.raven.utils.crypto.KeyGeneratorUtils.java