Example usage for android.speech.tts TextToSpeech QUEUE_FLUSH

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

Introduction

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

Prototype

int QUEUE_FLUSH

To view the source code for android.speech.tts TextToSpeech QUEUE_FLUSH.

Click Source Link

Document

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.

Usage

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

private void speak(JSONArray args, CallbackContext callbackContext) throws JSONException, NullPointerException {
    JSONObject params = args.getJSONObject(0);

    if (params == null) {
        callbackContext.error(ERR_INVALID_OPTIONS);
        return;/*ww w  .j  av  a2s  .c om*/
    }

    String text;
    String locale;
    double rate;

    if (params.isNull("text")) {
        callbackContext.error(ERR_INVALID_OPTIONS);
        return;
    } else {
        text = params.getString("text");
    }

    if (params.isNull("locale")) {
        locale = "en-US";
    } else {
        locale = params.getString("locale");
    }

    if (params.isNull("rate")) {
        rate = 1.0;
    } else {
        rate = params.getDouble("rate");
    }

    if (tts == null) {
        callbackContext.error(ERR_ERROR_INITIALIZING);
        return;
    }

    if (!ttsInitialized) {
        callbackContext.error(ERR_NOT_INITIALIZED);
        return;
    }

    HashMap<String, String> ttsParams = new HashMap<String, String>();
    ttsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackContext.getCallbackId());

    String[] localeArgs = locale.split("-");
    tts.setLanguage(new Locale(localeArgs[0], localeArgs[1]));
    tts.setSpeechRate((float) rate);

    tts.speak(text, TextToSpeech.QUEUE_FLUSH, ttsParams);
}

From source file:com.mobilevangelist.glass.helloworld.GetTheWeatherActivity.java

@Override
public void onDestroy() {
    _speech.speak("Goodbye", TextToSpeech.QUEUE_FLUSH, null);

    super.onDestroy();
}

From source file:baasi.hackathon.sja.TalkActivity.java

/**
 * ?? ???//from  w w  w . j a  va 2s  .  c om
 * @param word String
 */
private void startTalk(final String word) {
    speech = new TextToSpeech(getBaseContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                speech.setLanguage(Locale.UK);
                speech.speak(word, TextToSpeech.QUEUE_FLUSH, null);
            }
        }
    });
}

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

private void sayText(String text) {
    textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}

From source file:com.projecttango.examples.java.pointcloud.PointCloudActivity.java

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

    mPointCountTextView = (TextView) findViewById(R.id.point_count_textview);
    mAverageZTextView = (TextView) findViewById(R.id.average_z_textview);
    mSurfaceView = (RajawaliSurfaceView) findViewById(R.id.gl_surface_view);

    mPointCloudManager = new TangoPointCloudManager();
    mTangoUx = setupTangoUxAndLayout();/*ww  w.j  a va  2s . c  o  m*/
    mRenderer = new PointCloudRajawaliRenderer(this);
    setupRenderer();

    /* Setup tts */
    tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {
                tts.setLanguage(Locale.US);
                tts.speak("ICU helper initialized.", TextToSpeech.QUEUE_FLUSH, null);
            }
        }
    });

    DisplayManager displayManager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    if (displayManager != null) {
        displayManager.registerDisplayListener(new DisplayManager.DisplayListener() {
            @Override
            public void onDisplayAdded(int displayId) {

            }

            @Override
            public void onDisplayChanged(int displayId) {
                synchronized (this) {
                    setDisplayRotation();
                }
            }

            @Override
            public void onDisplayRemoved(int displayId) {
            }
        }, null);
    }
}

From source file:treehou.se.habit.gcm.GcmIntentService.java

private void sendNotification(final String msg, int notificationId) {
    if (mNotificationManager == null) {
        mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    }//w ww  . jav a 2s  . c  om

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction("org.openhab.notification.selected");
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("notificationId", notificationId);

    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(getApplicationContext(), 0,
            notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Check if notification should be spoken

    Log.d(TAG, "Message " + Constants.PREF_REGISTRATION_SERVER + notificationId);

    /*getSharedPreferences(Constants.PREF_REGISTRATION_SERVER + notificationId, MODE_PRIVATE);
    SharedPreferences preferences = getSharedPreferences(Constants.PREFERENCE_SERVER, Context.MODE_PRIVATE);
    long serverId = preferences.getLong(Constants.PREF_REGISTRATION_SERVER+notificationId,-1);
            
    if(serverId < 0){
    return;
    }
            
    Server server = Server.load(Server.class, serverId);*/

    NotificationSettingsDB notificationSettings = NotificationSettingsDB.loadGlobal(getApplicationContext());
    if (notificationSettings.notificationToSpeach()) {
        textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status != TextToSpeech.ERROR) {
                    textToSpeech.setLanguage(Locale.getDefault());
                    textToSpeech.speak(msg, TextToSpeech.QUEUE_FLUSH, null);
                }
            }
        });
    }

    /*NotificationDB notification = new NotificationDB(msg);
    notification.save();
    List<NotificationDB> notifications = new Select().all().from(NotificationDB.class).execute();*/
    //TODO create inbox style

    String replyLabel = getString(R.string.notification_title);
    RemoteInput remoteInput = new RemoteInput.Builder(VoiceActionService.EXTRA_VOICE_REPLY).setLabel(replyLabel)
            .build();

    Intent replyIntent = new Intent(this, VoiceActionService.class);
    PendingIntent replyPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0);

    // Create the reply action and add the remote input
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.action_voice_light,
            getString(R.string.voice_command), replyPendingIntent).addRemoteInput(remoteInput).build();

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification).setContentTitle(getString(R.string.notification_title))
            .setAutoCancel(true).setSound(alarmSound)
            .extend(new NotificationCompat.WearableExtender().addAction(action)).setContentText(msg);

    mBuilder.setContentIntent(pendingNotificationIntent);

    mNotificationManager.notify(notificationId, mBuilder.build());
}

From source file:com.altcanvas.twitspeak.TwitSpeakActivity.java

public void speak(Twit twit) {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "UTTID");
    mTts.speak(twit.getSpeech(), TextToSpeech.QUEUE_FLUSH, params);
    twitBox.setText("@" + twit.screenname + ": " + twit.text);
}

From source file:com.perchtech.humraz.blind.libraryact.java

private void speakOut(String text) {

    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}

From source file:in.codehex.arrow.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case Config.REQUEST_SPEECH_INPUT:
        if (resultCode == RESULT_OK && data != null) {
            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            if (result.get(0).equalsIgnoreCase("emergency")) {
                String phone = userPreferences.getString(Config.KEY_PREF_PHONE, null);
                String message = "Emergency!\n" + userPreferences.getString(Config.KEY_PREF_NAME, null)
                        + " is at http://maps.google.com/maps?q=" + lat + "," + lng;
                try {
                    SmsManager smsManager = SmsManager.getDefault();
                    smsManager.sendTextMessage(phone, null, message, null, null);
                    textToSpeech.speak("Emergency alert sent!", TextToSpeech.QUEUE_FLUSH, null, null);
                } catch (Exception e) {
                    textToSpeech.speak("Unable to send alert message!", TextToSpeech.QUEUE_FLUSH, null, null);
                }/*from   w ww.j a  v a  2s  .  c  o m*/
            } else if (isDestinationAvailable) {
                if (result.get(0).equalsIgnoreCase("yes")) {
                    processDirection();
                    isDestinationAvailable = false;
                } else {
                    textToSpeech.speak(getString(R.string.prompt_speech_input_initial),
                            TextToSpeech.QUEUE_FLUSH, null, Config.UTTERANCE_ID_INITIAL);
                    isDestinationAvailable = false;
                }
            } else {
                speakData(result.get(0));
            }
        }
        break;
    case Config.REQUEST_CHECK_TTS:
        if (resultCode != TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(intent);
        }
        break;
    }
}

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

public void tts(String words) {
    mSpeech.speak(words, TextToSpeech.QUEUE_FLUSH, null);
}