List of usage examples for android.speech.tts TextToSpeech QUEUE_FLUSH
int QUEUE_FLUSH
To view the source code for android.speech.tts TextToSpeech QUEUE_FLUSH.
Click Source Link
From source file:usbong.android.likha_collection_1.UsbongDecisionTreeEngineActivity.java
public void processSpeak(StringBuffer sb) { if (mTts.isSpeaking()) { //commented out by Mike, 24 Sept. 2015 mTts.stop();/* w w w . ja v a 2s . c o m*/ } // Log.d(">>>>currScreen",currScreen+""); switch (currScreen) { //edit later, Mike, Sept. 26, 2013 case UsbongConstants.SIMPLE_ENCRYPT_SCREEN: break; //edit later, Mike, May 23, 2013 case UsbongConstants.DCAT_SUMMARY_SCREEN: break; case UsbongConstants.LINK_SCREEN: case UsbongConstants.MULTIPLE_RADIO_BUTTONS_SCREEN: case UsbongConstants.MULTIPLE_RADIO_BUTTONS_WITH_ANSWER_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalRadioButtonsInContainer = radioButtonsContainer.size(); for (int i = 0; i < totalRadioButtonsInContainer; i++) { sb.append(((RadioButton) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new RadioButton(this), UsbongUtils.IS_RADIOBUTTON, radioButtonsContainer.elementAt(i))) .getText().toString() + ". "); } break; case UsbongConstants.MULTIPLE_CHECKBOXES_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalCheckBoxesInContainer = checkBoxesContainer.size(); for (int i = 0; i < totalCheckBoxesInContainer; i++) { sb.append(((CheckBox) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new CheckBox(this), UsbongUtils.IS_CHECKBOX, checkBoxesContainer.elementAt(i))).getText() .toString() + ". "); } break; case UsbongConstants.AUDIO_RECORD_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button recordButton = (Button) findViewById(R.id.record_button); Button stopButton = (Button) findViewById(R.id.stop_button); Button playButton = (Button) findViewById(R.id.play_button); sb.append(recordButton.getText() + ". "); sb.append(stopButton.getText() + ". "); sb.append(playButton.getText() + ". "); break; case UsbongConstants.PAINT_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button paintButton = (Button) findViewById(R.id.paint_button); sb.append(paintButton.getText() + ". "); break; case UsbongConstants.PHOTO_CAPTURE_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button photoCaptureButton = (Button) findViewById(R.id.photo_capture_button); sb.append(photoCaptureButton.getText() + ". "); break; case UsbongConstants.TEXTFIELD_SCREEN: case UsbongConstants.TEXTFIELD_WITH_ANSWER_SCREEN: case UsbongConstants.TEXTFIELD_WITH_UNIT_SCREEN: case UsbongConstants.TEXTFIELD_NUMERICAL_SCREEN: case UsbongConstants.TEXTAREA_SCREEN: case UsbongConstants.TEXTAREA_WITH_ANSWER_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); break; case UsbongConstants.CLASSIFICATION_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalClassificationsInContainer = classificationContainer.size(); for (int i = 0; i < totalClassificationsInContainer; i++) { sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, classificationContainer.elementAt(i))) .getText().toString() + ". "); } break; case UsbongConstants.DATE_SCREEN: case UsbongConstants.TEXT_DISPLAY_SCREEN: case UsbongConstants.TEXT_IMAGE_DISPLAY_SCREEN: case UsbongConstants.IMAGE_TEXT_DISPLAY_SCREEN: case UsbongConstants.CLICKABLE_IMAGE_TEXT_DISPLAY_SCREEN: case UsbongConstants.TEXT_CLICKABLE_IMAGE_DISPLAY_SCREEN: case UsbongConstants.GPS_LOCATION_SCREEN: case UsbongConstants.QR_CODE_READER_SCREEN: case UsbongConstants.TIMESTAMP_DISPLAY_SCREEN: case UsbongConstants.VIDEO_FROM_FILE_WITH_TEXT_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); // Log.d(">>>>sb",sb.toString()); break; case UsbongConstants.CLICKABLE_IMAGE_DISPLAY_SCREEN: case UsbongConstants.IMAGE_DISPLAY_SCREEN: case UsbongConstants.VIDEO_FROM_FILE_SCREEN: break; case UsbongConstants.YES_NO_DECISION_SCREEN: case UsbongConstants.SEND_TO_WEBSERVER_SCREEN: case UsbongConstants.SEND_TO_CLOUD_BASED_SERVICE_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); sb.append(yesStringValue + ". "); sb.append(noStringValue + ". "); break; /* case UsbongConstants.PAINT_SCREEN: if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_FILIPINO) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewFILIPINO)); } else if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_JAPANESE) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewJAPANESE)); } else { //if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_ENGLISH) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewENGLISH)); } break; */ /* //commented out by Mike, 20160213 case UsbongConstants.END_STATE_SCREEN: if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_FILIPINO) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewFILIPINO)); } else if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_JAPANESE) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewJAPANESE)); } else { //if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_ENGLISH) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewENGLISH)); } break; */ } //edited by Mike, 21 July 2015 try { currUsbongAudioString = UsbongUtils.getAudioFilePathForThisScreenIfAvailable(currUsbongNode); Log.d(">>>>currUsbongAudioString: ", "" + currUsbongAudioString); Log.d(">>>>currLanguageBeingUsed: ", UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); //added by Mike, 2 Oct. 2015 //exception for Mandarin //make simplified and traditional refer to the same audio folder if ((currLanguageBeingUsed == UsbongUtils.LANGUAGE_MANDARIN_SIMPLIFIED) || (currLanguageBeingUsed == UsbongUtils.LANGUAGE_MANDARIN_TRADITIONAL)) { currLanguageBeingUsed = UsbongUtils.LANGUAGE_MANDARIN; } String filePath = UsbongUtils.getAudioFilePathFromUTree(currUsbongAudioString, UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); // Log.d(">>>>filePath: ",filePath); if (filePath != null) { Log.d(">>>>", "inside filePath!=null"); Log.d(">>>>filePath: ", filePath); if (myMediaPlayer.isPlaying()) { myMediaPlayer.stop(); } myMediaPlayer.reset(); //edited by Mike, 20151201 // myMediaPlayer.setDataSource(filePath); FileInputStream fis = new FileInputStream(new File(filePath)); myMediaPlayer.setDataSource(fis.getFD()); fis.close(); myMediaPlayer.prepare(); // myMediaPlayer.setVolume(1.0f, 1.0f); myMediaPlayer.start(); // myMediaPlayer.seekTo(0); //added by Mike, 20160417 myMediaPlayer.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { if ((UsbongUtils.IS_IN_AUTO_PLAY_MODE) && (UsbongUtils.isAnAutoPlayException(instance))) { processNextButtonPressed(); } } }); } else { //it's either com.svox.pico (default) or com.svox.classic (Japanese, etc) //commented out by Mike, 11 Oct. 2015 // mTts.setEngineByPackageName("com.svox.pico"); //note: this method is already deprecated //20160417 mTtsParams = new HashMap<String, String>(); mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UsbongConstants.MY_UTTERANCE_ID); switch (currLanguageBeingUsed) { case UsbongUtils.LANGUAGE_FILIPINO: mTts.setLanguage(new Locale("spa", "ESP")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(UsbongUtils.convertFilipinoToSpanishAccentFriendlyText(sb.toString()), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(UsbongUtils.convertFilipinoToSpanishAccentFriendlyText(sb.toString()), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; case UsbongUtils.LANGUAGE_JAPANESE: // commented out by Mike, 11 Oct. 2015 // mTts.setEngineByPackageName("com.svox.classic"); //note: this method is already deprecated mTts.setLanguage(new Locale("ja", "JP")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; case UsbongUtils.LANGUAGE_ENGLISH: mTts.setLanguage(new Locale("en", "US")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; default: mTts.setLanguage(new Locale("en", "US")); mTts.speak(sb.toString(), TextToSpeech.QUEUE_ADD, null); //QUEUE_FLUSH break; } //added by Mike, 20160417 mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onDone(String utteranceId) { if (utteranceId.equals(UsbongConstants.MY_UTTERANCE_ID)) { //added by Mike, 20160608 if ((UsbongUtils.IS_IN_AUTO_PLAY_MODE) && (UsbongUtils.isAnAutoPlayException(instance))) { instance.runOnUiThread(new Runnable() { @Override public void run() { processNextButtonPressed(); } }); } } } @Override @Deprecated public void onError(String utteranceId) { // TODO Auto-generated method stub } @Override public void onStart(String utteranceId) { // TODO Auto-generated method stub } }); } } catch (Exception e) { e.printStackTrace(); } }
From source file:usbong.android.retrocc.UsbongDecisionTreeEngineActivity.java
public void processSpeak(StringBuffer sb) { if (mTts.isSpeaking()) { //commented out by Mike, 24 Sept. 2015 mTts.stop();//w w w . j a v a 2 s. co m } // Log.d(">>>>currScreen",currScreen+""); switch (currScreen) { //edit later, Mike, Sept. 26, 2013 case UsbongConstants.SIMPLE_ENCRYPT_SCREEN: break; //edit later, Mike, May 23, 2013 case UsbongConstants.DCAT_SUMMARY_SCREEN: break; case UsbongConstants.LINK_SCREEN: case UsbongConstants.MULTIPLE_RADIO_BUTTONS_SCREEN: case UsbongConstants.MULTIPLE_RADIO_BUTTONS_WITH_ANSWER_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalRadioButtonsInContainer = radioButtonsContainer.size(); for (int i = 0; i < totalRadioButtonsInContainer; i++) { sb.append(((RadioButton) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new RadioButton(this), UsbongUtils.IS_RADIOBUTTON, radioButtonsContainer.elementAt(i))) .getText().toString() + ". "); } break; case UsbongConstants.MULTIPLE_CHECKBOXES_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalCheckBoxesInContainer = checkBoxesContainer.size(); for (int i = 0; i < totalCheckBoxesInContainer; i++) { sb.append(((CheckBox) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new CheckBox(this), UsbongUtils.IS_CHECKBOX, checkBoxesContainer.elementAt(i))).getText() .toString() + ". "); } break; case UsbongConstants.AUDIO_RECORD_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button recordButton = (Button) findViewById(R.id.record_button); Button stopButton = (Button) findViewById(R.id.stop_button); Button playButton = (Button) findViewById(R.id.play_button); sb.append(recordButton.getText() + ". "); sb.append(stopButton.getText() + ". "); sb.append(playButton.getText() + ". "); break; case UsbongConstants.PAINT_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button paintButton = (Button) findViewById(R.id.paint_button); sb.append(paintButton.getText() + ". "); break; case UsbongConstants.PHOTO_CAPTURE_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button photoCaptureButton = (Button) findViewById(R.id.photo_capture_button); sb.append(photoCaptureButton.getText() + ". "); break; case UsbongConstants.TEXTFIELD_SCREEN: case UsbongConstants.TEXTFIELD_WITH_ANSWER_SCREEN: case UsbongConstants.TEXTFIELD_WITH_UNIT_SCREEN: case UsbongConstants.TEXTFIELD_NUMERICAL_SCREEN: case UsbongConstants.TEXTAREA_SCREEN: case UsbongConstants.TEXTAREA_WITH_ANSWER_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); break; case UsbongConstants.CLASSIFICATION_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalClassificationsInContainer = classificationContainer.size(); for (int i = 0; i < totalClassificationsInContainer; i++) { sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, classificationContainer.elementAt(i))) .getText().toString() + ". "); } break; case UsbongConstants.DATE_SCREEN: case UsbongConstants.TEXT_DISPLAY_SCREEN: case UsbongConstants.TEXT_IMAGE_DISPLAY_SCREEN: case UsbongConstants.IMAGE_TEXT_DISPLAY_SCREEN: case UsbongConstants.CLICKABLE_IMAGE_TEXT_DISPLAY_SCREEN: case UsbongConstants.TEXT_CLICKABLE_IMAGE_DISPLAY_SCREEN: case UsbongConstants.GPS_LOCATION_SCREEN: case UsbongConstants.QR_CODE_READER_SCREEN: case UsbongConstants.TIMESTAMP_DISPLAY_SCREEN: case UsbongConstants.VIDEO_FROM_FILE_WITH_TEXT_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); // Log.d(">>>>sb",sb.toString()); break; case UsbongConstants.CLICKABLE_IMAGE_DISPLAY_SCREEN: case UsbongConstants.IMAGE_DISPLAY_SCREEN: case UsbongConstants.VIDEO_FROM_FILE_SCREEN: break; case UsbongConstants.YES_NO_DECISION_SCREEN: case UsbongConstants.SEND_TO_WEBSERVER_SCREEN: case UsbongConstants.SEND_TO_CLOUD_BASED_SERVICE_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); sb.append(yesStringValue + ". "); sb.append(noStringValue + ". "); break; /* case UsbongConstants.PAINT_SCREEN: if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_FILIPINO) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewFILIPINO)); } else if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_JAPANESE) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewJAPANESE)); } else { //if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_ENGLISH) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewENGLISH)); } break; */ /* //commented out by Mike, 20160213 case UsbongConstants.END_STATE_SCREEN: if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_FILIPINO) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewFILIPINO)); } else if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_JAPANESE) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewJAPANESE)); } else { //if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_ENGLISH) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewENGLISH)); } break; */ } //edited by Mike, 21 July 2015 try { currUsbongAudioString = UsbongUtils.getAudioFilePathForThisScreenIfAvailable(currUsbongNode); Log.d(">>>>currUsbongAudioString: ", "" + currUsbongAudioString); Log.d(">>>>currLanguageBeingUsed: ", UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); //added by Mike, 2 Oct. 2015 //exception for Mandarin //make simplified and traditional refer to the same audio folder if ((currLanguageBeingUsed == UsbongUtils.LANGUAGE_MANDARIN_SIMPLIFIED) || (currLanguageBeingUsed == UsbongUtils.LANGUAGE_MANDARIN_TRADITIONAL)) { currLanguageBeingUsed = UsbongUtils.LANGUAGE_MANDARIN; } String filePath = UsbongUtils.getAudioFilePathFromUTree(currUsbongAudioString, UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); // Log.d(">>>>filePath: ",filePath); if (filePath != null) { Log.d(">>>>", "inside filePath!=null"); Log.d(">>>>filePath: ", filePath); if (myMediaPlayer.isPlaying()) { myMediaPlayer.stop(); } myMediaPlayer.reset(); //edited by Mike, 20151201 // myMediaPlayer.setDataSource(filePath); FileInputStream fis = new FileInputStream(new File(filePath)); myMediaPlayer.setDataSource(fis.getFD()); fis.close(); myMediaPlayer.prepare(); // myMediaPlayer.setVolume(1.0f, 1.0f); myMediaPlayer.start(); // myMediaPlayer.seekTo(0); //added by Mike, 20160417 myMediaPlayer.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { if (UsbongUtils.IS_IN_AUTO_PLAY_MODE) { processNextButtonPressed(); } } }); } else { //it's either com.svox.pico (default) or com.svox.classic (Japanese, etc) //commented out by Mike, 11 Oct. 2015 // mTts.setEngineByPackageName("com.svox.pico"); //note: this method is already deprecated //20160417 mTtsParams = new HashMap<String, String>(); mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UsbongConstants.MY_UTTERANCE_ID); switch (currLanguageBeingUsed) { case UsbongUtils.LANGUAGE_FILIPINO: mTts.setLanguage(new Locale("spa", "ESP")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(UsbongUtils.convertFilipinoToSpanishAccentFriendlyText(sb.toString()), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(UsbongUtils.convertFilipinoToSpanishAccentFriendlyText(sb.toString()), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; case UsbongUtils.LANGUAGE_JAPANESE: // commented out by Mike, 11 Oct. 2015 // mTts.setEngineByPackageName("com.svox.classic"); //note: this method is already deprecated mTts.setLanguage(new Locale("ja", "JP")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; case UsbongUtils.LANGUAGE_ENGLISH: mTts.setLanguage(new Locale("en", "US")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; default: mTts.setLanguage(new Locale("en", "US")); mTts.speak(sb.toString(), TextToSpeech.QUEUE_ADD, null); //QUEUE_FLUSH break; } //added by Mike, 20160417 mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onDone(String utteranceId) { if (utteranceId.equals(UsbongConstants.MY_UTTERANCE_ID)) { if (UsbongUtils.IS_IN_AUTO_PLAY_MODE) { instance.runOnUiThread(new Runnable() { @Override public void run() { processNextButtonPressed(); } }); } } } @Override @Deprecated public void onError(String utteranceId) { // TODO Auto-generated method stub } @Override public void onStart(String utteranceId) { // TODO Auto-generated method stub } }); } } catch (Exception e) { e.printStackTrace(); } }
From source file:finalproject.ece558.edu.pdx.ece.brailleblackjack.PlayBlackJackGameFragment.java
/** * Speak-out a given string/* w ww .ja v a 2s. c o m*/ * @param text String of text to speak-out */ private void convertTextToSpeech(String text) { CharSequence t = text; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { textToSpeech.speak(t, TextToSpeech.QUEUE_FLUSH, null, null); } else { textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null); } }
From source file:com.updetector.MainActivity.java
public void onDetectionConfirmed(int eventCode, long eventDetectionTimestamp, Location eventlocation, String eventAddress, long detectionDelayInSecs) { MotionState lastOnFootOrInVehicleState = mPastGoogleActivtiesUnModified.lastOnFootOrInVehicleState(); if (lastOnFootOrInVehicleState != null && lastOnFootOrInVehicleState.timeInHMS.equals(timeOfLastGoogleOnFootorInVehicleState)) { return;/* ww w .ja v a 2s . c o m*/ } timeOfLastGoogleOnFootorInVehicleState = lastOnFootOrInVehicleState.timeInHMS; @SuppressWarnings("unused") int resID; String prefix; float markerColor; String voiceNotificationMsg; if (eventCode == Constants.OUTCOME_PARKING) { resID = R.raw.vehicle_parked; prefix = Constants.PARKING_NOTIFICATION; markerColor = BitmapDescriptorFactory.HUE_AZURE; voiceNotificationMsg = "Vehicle Parked "; } else {//unparking resID = R.raw.vehicle_deparked; prefix = Constants.UNPARKING_NOTIFICATION; markerColor = BitmapDescriptorFactory.HUE_RED; voiceNotificationMsg = "Vehicle Departured "; } //String curTimeString=CommonUtils.formatTimestamp(new Date(),formatTemplate); long curTimestamp = System.currentTimeMillis(); String curTimeString = CommonUtils.formatTimestamp(new Date(curTimestamp), "HH:mm:ss"); Log.e(LOG_TAG, curTimeString + " \n" + eventlocation.toString()); /* * actions */ //1. send the text notification String notificationMsg = prefix + " " + curTimeString; if (eventAddress != null) notificationMsg += eventAddress; mDetectionNotificationManager.sendTextNotification(notificationMsg); //2. play the sound //2.1 announce the type //mDetectionNotificationManager.playVoiceNotification(resID); //2.2 announce the time mTextToSpeech.speak(voiceNotificationMsg, TextToSpeech.QUEUE_FLUSH, null); //3. log the address of event String logMsg = prefix + CommonUtils.formatTimestamp(new Date(eventDetectionTimestamp), "HH:mm:ss ") + "\nNotification generation time:" + curTimeString + "\nDetection timestamp: " + CommonUtils.formatTimestamp(new Date(eventDetectionTimestamp), "HH:mm:ss ") + "\nDetection delay: " + detectionDelayInSecs + " secs" + "\nlocation:" + eventlocation.toString() + "\n"; if (eventAddress != null) logMsg += eventAddress + "\n"; else logMsg += "address is not available. \n"; logMsg += pastEnvironments.toString() + "\n" + mPastClassifiedMotionStates.toString() + "\n" + mPastGoogleActivities.toString() + "\n" + mPastGoogleActivtiesUnModified.toString() + "\n" + "timeOfLastGoogleOnFootorInVehicleState=" + timeOfLastGoogleOnFootorInVehicleState + "\n"; boolean logDetection = getSharedPreferences(Constants.SHARED_PREFERENCES, 0) .getBoolean(Constants.LOGGING_DETECTION_SWITCH, false); if (logDetection) mLogManager.log(logMsg, Constants.LOG_FILE_TYPE[Constants.LOG_TYPE_DETECTION_REPORT]); //4. show on the map mMap.clear(); mDetectionNotificationManager.addMarkersToMap(mMap, curTimeString, prefix, eventlocation.getLatitude(), eventlocation.getLongitude(), eventlocation.getAltitude(), markerColor); //center and zoom in the map CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(eventlocation.getLatitude(), eventlocation.getLongitude())) // Sets the center of the map to Mountain View .zoom(17) // Sets the zoom //.bearing(90) // Sets the orientation of the camera to east //.tilt(30) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); //add a marker on the map Log.e(LOG_TAG, "operations on map completed"); //5. update availability display //updateAvailabilityDisplay(eventCode, location); //add a marker on the map Log.e(LOG_TAG, "operations on map completed"); updateAvailabilityDisplay(eventCode, eventlocation); }
From source file:org.thecongers.mcluster.MainActivity.java
public void speakString(String speech) { HashMap<String, String> myHashAlarm = new HashMap(); myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM)); text2speech.speak(speech, TextToSpeech.QUEUE_FLUSH, myHashAlarm); }