List of usage examples for android.speech.tts UtteranceProgressListener UtteranceProgressListener
UtteranceProgressListener
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/*from www . jav a2 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:org.digitalcampus.oppia.activity.CourseActivity.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) @SuppressLint("NewApi") public void onInit(int status) { // check for successful instantiation if (status == TextToSpeech.SUCCESS) { ttsRunning = true;//from ww w.ja va2 s .c o m ((WidgetFactory) apAdapter.getItem(currentActivityNo)).setReadAloud(true); supportInvalidateOptionsMenu(); HashMap<String, String> params = new HashMap<String, String>(); params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, TAG); myTTS.speak(((WidgetFactory) apAdapter.getItem(currentActivityNo)).getContentToRead(), TextToSpeech.QUEUE_FLUSH, params); myTTS.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onDone(String utteranceId) { Log.d(TAG, "Finished reading"); CourseActivity.this.ttsRunning = false; myTTS = null; } @Override public void onError(String utteranceId) { } @Override public void onStart(String utteranceId) { } }); } else { // TTS not installed so show message Toast.makeText(this, this.getString(R.string.error_tts_start), Toast.LENGTH_LONG).show(); } }
From source file:in.codehex.arrow.MainActivity.java
/** * Implement and manipulate the objects/* w ww . j av a2s . c om*/ */ private void prepareObjects() { if (loginCheck()) { name = userPreferences.getString(Config.KEY_PREF_NAME, Config.PREF_DEFAULT_NAME); checkTts(); textToSpeech = new TextToSpeech(this, this); textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onStart(String utteranceId) { } @Override public void onDone(String utteranceId) { switch (utteranceId) { case Config.UTTERANCE_ID_INITIAL: promptSpeechInput(); break; case Config.UTTERANCE_ID_CONFIRMATION: promptSpeechInput(); break; } } @Override public void onError(String utteranceId) { } }); mainLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { textToSpeech.speak(getString(R.string.prompt_speech_input_initial), TextToSpeech.QUEUE_FLUSH, null, Config.UTTERANCE_ID_INITIAL); } }); if (checkPlayServices()) buildGoogleApiClient(); createLocationRequest(); if (!isGPSEnabled(getApplicationContext())) showAlertGPS(); } }
From source file:atlc.granadaaccessibilityranking.VoiceActivity.java
/** * Starts the TTS engine. It is work-around to avoid implementing the UtteranceProgressListener abstract class. * * @author Method by Greg Milette (comments incorporated by us). Source: https://github.com/gast-lib/gast-lib/blob/master/library/src/root/gast/speech/voiceaction/VoiceActionExecutor.java * @see See the problem here: http://stackoverflow.com/questions/11703653/why-is-utteranceprogresslistener-not-an-interface *//*from w ww. j ava 2 s . c o m*/ @SuppressLint("NewApi") @SuppressWarnings("deprecation") public void setTTS() { myTTS = new TextToSpeech(ctx, (OnInitListener) this); /* * The listener for the TTS events varies depending on the Android version used: * the most updated one is UtteranceProgressListener, but in SKD versions * 15 or earlier, it is necessary to use the deprecated OnUtteranceCompletedListener */ if (Build.VERSION.SDK_INT >= 15) { myTTS.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onDone(String utteranceId) //TTS finished synthesizing { onTTSDone(utteranceId); } @Override public void onError(String utteranceId) //TTS encountered an error while synthesizing { onTTSError(utteranceId); } @Override public void onStart(String utteranceId) //TTS has started synthesizing { onTTSStart(utteranceId); } }); } else { myTTS.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() { @Override public void onUtteranceCompleted(final String utteranceId) { onTTSDone(utteranceId); //Earlier SDKs only consider the onTTSDone event } }); } }
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();/*from w w w . j ava2s . c om*/ } // 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();// ww w . j a va 2 s. 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) { 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(); } }