Example usage for android.speech.tts TextToSpeech QUEUE_ADD

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

Introduction

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

Prototype

int QUEUE_ADD

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

Click Source Link

Document

Queue mode where the new entry is added at the end of the playback queue.

Usage

From source file:com.jtxdriggers.android.ventriloid.VentriloidService.java

@SuppressWarnings("deprecation")
public boolean disconnect() {
    disconnect = true;/*from ww  w .j a v a2 s .  co  m*/
    connected = false;

    if (ttsActive && !muted && prefs.getBoolean("tts_disconnect", true)) {
        HashMap<String, String> params = new HashMap<String, String>();
        if (am.isBluetoothScoOn())
            params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));
        params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "Disconnected");
        tts.speak("Disconnected.", TextToSpeech.QUEUE_ADD, params);
        tts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {
            @Override
            public void onUtteranceCompleted(String utteranceId) {
                if (utteranceId.equals("Disconnected")) {
                    tts.shutdown();

                    stopForeground(true);
                    stopSelf();
                }
            }
        });
    } else if (ringtoneActive && !muted) {
        ringtone = RingtoneManager.getRingtone(VentriloidService.this,
                Uri.parse(prefs.getString("disconnect_notification",
                        RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString())));
        ringtone.play();

        stopForeground(true);
        stopSelf();
    } else {
        stopForeground(true);
        stopSelf();
    }

    return true;
}

From source file:org.de.jmg.learn._MainActivity.java

public void speak(String t, Locale l, String ID, boolean blnFlush) {
    try {/*from ww w.  j a  v  a2  s.com*/
        if (!_main.blnTextToSpeech || l.toString().equalsIgnoreCase("_off"))
            return;
        String ts[] = (" " + t + " ").split(getString(R.string.cloze));
        if (!t.equalsIgnoreCase(getString(R.string.cloze)) && ts.length > 1) {
            for (int i = 0; i < ts.length; i++) {
                String s = ts[i];
                speak(s, l, ID, (i == 0) ? blnFlush : false);
                if (i < ts.length - 1) {
                    if (Build.VERSION.SDK_INT < 21) {
                        HashMap<String, String> h = new HashMap<>();
                        h.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "cloze");
                        //noinspection deprecation
                        _main.tts.playSilence(2500, TextToSpeech.QUEUE_ADD, h);
                    } else {
                        _main.tts.playSilentUtterance(2500, TextToSpeech.QUEUE_ADD, "cloze");
                    }
                    //speak(getString(R.string.cloze), Locale.getDefault(), ID, false);
                }
            }
        } else {
            int res = _main.tts.setLanguage(l);
            if (res < 0) {
                if (_main.tts.setLanguage(Locale.US) < 0)
                    return;
            }
            int flags;
            if (blnFlush) {
                flags = TextToSpeech.QUEUE_FLUSH;
            } else {
                flags = TextToSpeech.QUEUE_ADD;
            }
            if (Build.VERSION.SDK_INT < 21) {
                HashMap<String, String> h = new HashMap<>();
                h.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, ID);

                //noinspection deprecation
                _main.tts.speak(t, flags, h);
            } else {
                _main.tts.speak(t, flags, null, ID);
            }
        }
    } catch (Exception ex) {
        lib.setgstatus("speak: " + t + " " + l.toString());
        lib.ShowException(_main, ex);
    }
}

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 a v a  2  s.com*/
    }

    //      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();//from  w  ww  .j ava 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) {
                        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:de.rosche.spectraTelemetry.SpectraTelemetry.java

private void doSpeakAlarm(String alert_text, boolean speak_alert) {
    if (initialized == true && mSpeak_on == true && speak_alert == true) {
        tts.speak(alert_text, TextToSpeech.QUEUE_ADD, null);
        tts.playSilence(500, TextToSpeech.QUEUE_ADD, null);
    }//from w ww.  j  a  v  a2 s  .c om
}

From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java

public static void doSpeak() {
    if (initialized == true) {
        String text = "";
        if (voltage != null) {
            text = voltage.getText().toString();
            if (text != null && text.length() > 0 && voltage_speech_ack == true) {
                text = voltage_speech_label + " " + text + " " + voltage_speech_unit;
                tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                tts.playSilence(500, TextToSpeech.QUEUE_ADD, null);
            }/*from w  ww .ja va 2s .c om*/
        }
        if (alt != null) {
            text = alt.getText().toString();
            if (text != null && text.length() > 0 && height_speech_ack == true) {
                text = height_speech_label + " " + text + " " + height_speech_unit;
                tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                tts.playSilence(500, TextToSpeech.QUEUE_ADD, null);
            }
        }
        if (current != null) {
            text = current.getText().toString();
            if (text != null && text.length() > 0 && current_speech_ack == true) {
                text = current_speech_label + " " + text + " " + current_speech_unit;
                tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                tts.playSilence(500, TextToSpeech.QUEUE_ADD, null);
            }
        }
        if (used != null) {
            text = used.getText().toString();
            if (text != null && text.length() > 0 && used_speech_ack == true) {
                text = used_speech_label + " " + text + " " + used_speech_unit;
                tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                tts.playSilence(500, TextToSpeech.QUEUE_ADD, null);
            }
        }
        if (temp1 != null) {
            text = temp1.getText().toString();
            if (text != null && text.length() > 0 && temp_speech_ack == true) {
                text = temp_speech_label + " " + text + " " + temp_speech_unit;
                tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                tts.playSilence(500, TextToSpeech.QUEUE_ADD, null);
            }
        }
        if (rpm1 != null) {
            text = rpm1.getText().toString();
            if (text != null && text.length() > 0 && rpm_speech_ack == true) {
                text = rpm_speech_label + " " + text + " " + rpm_speech_unit;
                tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                tts.playSilence(500, TextToSpeech.QUEUE_ADD, null);
            }
        }
        if (speed != null) {
            text = speed.getText().toString();
            if (text != null && text.length() > 0 && speed_speech_ack == true) {
                text = speed_speech_label + " " + text + " " + speed_speech_unit;
                tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                tts.playSilence(500, TextToSpeech.QUEUE_ADD, null);
            }
        }
    }

}

From source file:jmri.enginedriver.throttle.java

private void speakWords(int msgNo, int whichThrottle) {
    boolean result = false;
    String speech = "";
    if (!prefTtsWhen.equals(PREF_TT_WHEN_NONE)) {
        if (myTts != null) {
            switch (msgNo) {
            case TTS_MSG_VOLUME_THROTTLE:
                if (!prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_NONE)) {
                    if (whichLastVolume != whichThrottle) {
                        result = true;//from   www  .j  ava  2  s . c  om
                        whichLastVolume = whichThrottle;
                        speech = getApplicationContext().getResources().getString(R.string.TtsVolumeThrottle)
                                + " " + (whichThrottle + 1);
                    }
                    if ((prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO))
                            || (prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO_SPEED))) {
                        speech = speech + ", "
                                + getApplicationContext().getResources().getString(R.string.TtsLoco) + " "
                                + (getConsistAddressString(whichThrottle));
                    }
                    if ((prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_SPEED))
                            || (prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO_SPEED))) {
                        speech = speech + ", "
                                + getApplicationContext().getResources().getString(R.string.TtsSpeed) + " "
                                + (getScaleSpeed(whichThrottle) + 1);
                    }
                }
                break;
            case TTS_MSG_GAMEPAD_THROTTLE:
                if (!prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_NONE)) {
                    if (whichLastGamepad1 != whichThrottle) {
                        result = true;
                        whichLastGamepad1 = whichThrottle;
                        speech = getApplicationContext().getResources().getString(R.string.TtsGamepadThrottle)
                                + " " + (whichThrottle + 1);
                    }
                    if ((prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO))
                            || (prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO_SPEED))) {
                        speech = speech + ", "
                                + getApplicationContext().getResources().getString(R.string.TtsLoco) + " "
                                + (getConsistAddressString(whichThrottle));
                    }
                    if ((prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_SPEED))
                            || (prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO_SPEED))) {
                        speech = speech + ", "
                                + getApplicationContext().getResources().getString(R.string.TtsSpeed) + " "
                                + (getScaleSpeed(whichThrottle) + 1);
                    }
                }
                break;
            case TTS_MSG_GAMEPAD_GAMEPAD_TEST:
                if ((prefTtsGamepadTest)) {
                    result = true;
                    speech = getApplicationContext().getResources().getString(R.string.TtsGamepadTest);
                }
                break;
            case TTS_MSG_GAMEPAD_GAMEPAD_TEST_COMPLETE:
                if ((prefTtsGamepadTestComplete)) {
                    result = true;
                    speech = getApplicationContext().getResources().getString(R.string.TtsGamepadTestComplete);
                }
                break;
            case TTS_MSG_GAMEPAD_GAMEPAD_TEST_SKIPPED:
                if ((prefTtsGamepadTestComplete)) {
                    result = true;
                    speech = getApplicationContext().getResources().getString(R.string.TtsGamepadTestSkipped);
                }
                break;
            case TTS_MSG_GAMEPAD_GAMEPAD_TEST_FAIL:
                if ((prefTtsGamepadTestComplete)) {
                    result = true;
                    speech = getApplicationContext().getResources().getString(R.string.TtsGamepadTestFail);
                }
                break;
            case TTS_MSG_GAMEPAD_GAMEPAD_TEST_RESET:
                if ((prefTtsGamepadTestComplete)) {
                    result = true;
                    speech = getApplicationContext().getResources().getString(R.string.TtsGamepadTestReset);
                }
                break;
            }

            if (result) {
                Time currentTime = new Time();
                currentTime.setToNow();
                // //don't repeat what was last spoken withing 6 seconds
                if (((currentTime.toMillis(true) >= (lastTtsTime.toMillis(true) + 6000))
                        || (!speech.equals(lastTts)))) {
                    //myTts.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
                    myTts.speak(speech, TextToSpeech.QUEUE_ADD, null);
                    lastTtsTime = currentTime;
                }
                lastTts = speech;
            }
        }
    }
}