Example usage for android.speech.tts TextToSpeech TextToSpeech

List of usage examples for android.speech.tts TextToSpeech TextToSpeech

Introduction

In this page you can find the example usage for android.speech.tts TextToSpeech TextToSpeech.

Prototype

public TextToSpeech(Context context, OnInitListener listener) 

Source Link

Document

The constructor for the TextToSpeech class, using the default TTS engine.

Usage

From source file:com.wordsbaking.cordova.tts.TTS.java

@Override
public void initialize(CordovaInterface cordova, final CordovaWebView webView) {
    tts = new TextToSpeech(cordova.getActivity().getApplicationContext(), this);
    tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
        @Override//w  w  w  .jav a 2 s . co m
        public void onStart(String s) {
            // do nothing
        }

        @Override
        public void onDone(String callbackId) {
            if (!callbackId.equals("")) {
                CallbackContext context = new CallbackContext(callbackId, webView);
                context.success();
            }
        }

        @Override
        public void onError(String callbackId) {
            if (!callbackId.equals("")) {
                CallbackContext context = new CallbackContext(callbackId, webView);
                context.error(ERR_UNKNOWN);
            }
        }
    });
}

From source file:com.rsamadhan.DomainListFragment.java

@Override
public void onResume() {
    super.onResume();
    if (tts == null) {
        tts = new TextToSpeech(getActivity(), this);
    } else {/*  w ww . ja  va  2  s. co m*/
        if (isTTSSuccess) {
            speakOut();
        }
    }
}

From source file:com.vaporwarecorp.mirror.feature.texttospeech.TextToSpeechManagerImpl.java

@Override
public void onFeatureResume() {
    mTextToSpeech = new TextToSpeech(mAppManager.getAppContext(), status -> {
        if (status == TextToSpeech.SUCCESS) {
            mTextToSpeech.setLanguage(Locale.US);
        } else {/*from w  w  w .j a v  a 2  s  . c o  m*/
            mTextToSpeech = null;
        }
    });
}

From source file:info.jmfavreau.bifrostgears.BifrostGears.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FuzzyColorRules.load(this);
    SemanticColorRules.load(this, "standard");
    setContentView(R.layout.activity_bifrostgears);

    Button button = (Button) findViewById(R.id.speech_button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override//from w w  w. j a v  a 2 s  . c om
        public void onClick(View v) {
            DoIt(v);
        }
    });

    textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                textToSpeech.setLanguage(Locale.getDefault());
            }
        }
    });

}

From source file:com.rstar.mobile.simpledemos.InvisibleFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mMessage = getArguments().getString(EXTRA_message);

    mTextToSpeech = new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override/*from   w w  w .  ja v a  2  s. com*/
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                mTextToSpeech.setLanguage(Locale.ENGLISH);
                // When the fragment is just created, wait for TTS to set up before speaking.
                startSpeaking();
            }
        }
    });
    setRetainInstance(true);
}

From source file:com.annuletconsulting.homecommand.node.AsyncSend.java

public AsyncSend(Activity activity, ViewFragment viewFragment, String ipAddr, int port, String sharedKey,
        boolean encryptCmd, String cmd, Runnable finishListener) {
    tts = new TextToSpeech(activity, null);
    this.viewFragment = viewFragment;
    this.activity = activity;
    this.ipAddr = ipAddr;
    command = cmd;//from w  w w. ja  v a 2  s  . c o  m
    this.port = port;
    this.encryptCmd = encryptCmd;
    AsyncSend.sharedKey = sharedKey;
    this.finishListener = finishListener;
}

From source file:com.mcongrove.glass.chucknorris.JokeService.java

@Override
public void onCreate() {
    Log.d(LIVE_CARD_ID, "onCreate");

    super.onCreate();

    mTimelineManager = TimelineManager.from(this);

    mJokeDrawer = new JokeDrawer(this);

    mSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
        @Override/*from   w w  w .  ja v a2  s.c o  m*/
        public void onInit(int status) {
            Log.d(LIVE_CARD_ID, "TextToSpeech:onInit");
        }
    });
}

From source file:com.ct.speech.TTS.java

@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    try {// ww w  . j  av  a  2  s. co  m
        if (action.equals("speak")) {
            String text = args.getString(0);
            if (isReady()) {
                mTts.speak(text, TextToSpeech.QUEUE_ADD, null);
                return new PluginResult(status, result);
            } else {
                JSONObject error = new JSONObject();
                error.put("message", "TTS service is still initialzing.");
                error.put("code", TTS.INITIALIZING);
                return new PluginResult(PluginResult.Status.ERROR, error);
            }
        } else if (action.equals("silence")) {
            if (isReady()) {
                mTts.playSilence(args.getLong(0), TextToSpeech.QUEUE_ADD, null);
                return new PluginResult(status, result);
            } else {
                JSONObject error = new JSONObject();
                error.put("message", "TTS service is still initialzing.");
                error.put("code", TTS.INITIALIZING);
                return new PluginResult(PluginResult.Status.ERROR, error);
            }
        } else if (action.equals("startup")) {
            if (mTts == null) {
                this.startupCallbackId = callbackId;
                state = TTS.INITIALIZING;
                mTts = new TextToSpeech((Context) ctx, this);
                //mTts.setLanguage(Locale.US);         
            }
            PluginResult pluginResult = new PluginResult(status, TTS.INITIALIZING);
            pluginResult.setKeepCallback(true);
            return pluginResult;
        } else if (action.equals("shutdown")) {
            if (mTts != null) {
                mTts.shutdown();
            }
            return new PluginResult(status, result);
        } else if (action.equals("stop")) {
            if (mTts != null) {
                mTts.stop();
            }
            return new PluginResult(status, result);
        } else if (action.equals("getLanguage")) {
            if (mTts != null) {
                result = mTts.getLanguage().toString();
                return new PluginResult(status, result);
            }
        } else if (action.equals("isLanguageAvailable")) {
            if (mTts != null) {
                Locale loc = new Locale(args.getString(0));
                int available = mTts.isLanguageAvailable(loc);
                result = (available < 0) ? "false" : "true";
                return new PluginResult(status, result);
            }
        } else if (action.equals("setLanguage")) {
            if (mTts != null) {
                Locale loc = new Locale(args.getString(0));
                int available = mTts.setLanguage(loc);
                result = (available < 0) ? "false" : "true";
                return new PluginResult(status, result);
            }
        }
        return new PluginResult(status, result);
    } catch (JSONException e) {
        e.printStackTrace();
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }
}

From source file:com.ibm.mobilefirst.mobileedge.recordapp.TestingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_testing);

    detectedGesture = (TextView) findViewById(R.id.detectedGesture);
    score = (TextView) findViewById(R.id.scoring);

    detectedLayout = findViewById(R.id.detectedLayout);
    sensingLayout = findViewById(R.id.sensingLayout);

    getSupportActionBar().setTitle(R.string.testing_title);

    RecordApplication application = (RecordApplication) getApplication();
    controller = application.controller;

    textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override/*from ww  w.  java  2 s . co m*/
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                textToSpeech.setLanguage(Locale.US);
            }
        }
    });
}

From source file:org.openpilot_nonag.androidgcs.fragments.ObjectManagerFragment.java

/** Called when the activity is first created. */
@Override/* www.  j  a v  a 2 s. c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (DEBUG)
        Log.d(TAG, "Created an ObjectManagerFragment");
    // For an activity this registers against the telemetry service intents.  Fragments must be notified by their
    // parent activity

    // TextToSpeech
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);

    tts = new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() {
        private int mCallCount = 0; // trying to investigate potential infinite loops

        @Override
        public void onInit(int status) {
            if ((mCallCount % 100) == 1) {
                // report this
            }
            mCallCount++;
        }
    });

    tts.setLanguage(Locale.US);

}