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.perchtech.humraz.blind.libraryact.java

private boolean onTap(float rawX, float rawY) {
    OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);
    TextBlock text = null;//w  w  w.  j  av  a2  s  . c o  m

    if (graphic != null) {
        text = graphic.getTextBlock();
        String readIt = text.getValue().toString();
        if (text != null && text.getValue() != null) {
            Log.d(TAG, "text data is being spoken! " + text.getValue());
            // Speak the string.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
            } else {
                tts.speak(readIt, TextToSpeech.QUEUE_ADD, null);
            }
        } else {
            Log.d(TAG, "text data is null");
        }
    } else {
        Log.d(TAG, "no text detected");
    }
    return text != null;
}

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

/**
 * Speak the data passed from the activity result for speech input.
 *
 * @param data the text to speak/*from   w w  w .  jav  a 2s .c  o  m*/
 */
private void speakData(String data) {
    destination = data;
    isDestinationAvailable = true;
    String mData = "Do you want to go to " + data + "?";
    textToSpeech.speak(mData, TextToSpeech.QUEUE_ADD, null, Config.UTTERANCE_ID_CONFIRMATION);
    Toast.makeText(MainActivity.this, data, Toast.LENGTH_SHORT).show();
}

From source file:com.app.azza.ocr.OcrCaptureActivity.java

/**
 * onTap is called to speak the tapped TextBlock, if any, out loud.
 *
 * @param rawX - the raw position of the tap
 * @param rawY - the raw position of the tap.
 * @return true if the tap was on a TextBlock
 *//*from   w ww .ja v a  2  s.c  o m*/
private boolean onTap(float rawX, float rawY) {
    Log.v("tap", "clicks");
    //screenClicksCounter++;
    //check boolean inorder to know the tap means speak or stop
    if (screenClickedToStop) {
        screenClickedToStop = false;
    } else
        screenClickedToStop = true;
    OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);
    Text text = null;
    List textList = getAllGraphicsText();

    //        for(Object block:textList){
    //             text=(Text)block;
    //
    //            tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
    //        }
    if (!screenClickedToStop) {
        Log.v("tap", "speak");
        if (textList.size() > 0) {
            for (int i = 0; i < textList.size(); i++) {
                text = (Text) textList.get(i);
                if (text != null && text.getValue() != null) {
                    tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
                    // lineNumberToSpeak = i;

                } else {
                    Log.d(TAG, "text data is null");
                }
            }
        } else {
            Log.d(TAG, "no text detected");
        }
    } else {
        Log.v("tap", "stop");
        tts.stop();
    }
    //        if (graphic != null) {
    //
    //            text = graphic.getTextBlock();
    //            if (text != null && text.getValue() != null) {
    //                Log.d(TAG, "text data is being spoken! " + text.getValue());
    //                // Speak the string.
    //                tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
    //            }
    //            else {
    //                Log.d(TAG, "text data is null");
    //            }
    //        }
    //        else {
    //            Log.d(TAG,"no text detected");
    //        }

    return text != null;
}

From source file:in.rade.armud.armudclient.MainActivity.java

private void speech(String Message) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tts.speak(Message, TextToSpeech.QUEUE_ADD, null, null);
        Log.d("Message Passed to TTS:", Message);
    } else {/*from w  ww  .j  a  v  a 2 s  .c  om*/
        Log.d("SDK Version less than:", String.valueOf(Build.VERSION_CODES.LOLLIPOP));
    }
}

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

@Override
public void onBackPressed() {
    tts.speak("", TextToSpeech.QUEUE_ADD, null, "DEFAULT");
    super.onBackPressed();
}

From source file:atlc.granadaaccessibilityranking.VoiceActivity.java

/**
 * Synthesizes a text in the language indicated (or in the default language of the device
 * it it is not available)//from   ww  w . j  a va2  s . co m
 *
 * @param languageCode language for the TTS, e.g. EN
 * @param countryCode country for the TTS, e.g. US
 * @param text string to be synthesized
 * @param id integer that identifies the prompt uniquely
 * @throws Exception when the codes supplied cannot be used and the default locale is selected
 */
public void speak(String text, String languageCode, String countryCode, Integer id) throws Exception {
    setLocale(languageCode, countryCode);
    HashMap<String, String> params = new HashMap<String, String>();
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, id.toString());
    myTTS.speak(text, TextToSpeech.QUEUE_ADD, params);
}

From source file:atlc.granadaaccessibilityranking.VoiceActivity.java

/**
 * Synthesizes a text in the language indicated (or in the default language of the device
 * if it is not available)/*from   w ww  . j a  v a  2s .c o  m*/
 *
 * @param languageCode language for the TTS, e.g. EN
 * @param text string to be synthesized
 * @param id integer that identifies the prompt uniquely
 * @throws Exception when the code supplied cannot be used and the default locale is selected
 */
public void speak(String text, String languageCode, Integer id) throws Exception {
    setLocale(languageCode);
    HashMap<String, String> params = new HashMap<String, String>();
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, id.toString());
    myTTS.speak(text, TextToSpeech.QUEUE_ADD, params);
}

From source file:atlc.granadaaccessibilityranking.VoiceActivity.java

/**
 * Synthesizes a text using the default language of the device
 *
 * @param text string to be synthesized//from  w  w  w. j  a  va  2  s  . c om
 * @param id integer that identifies the prompt uniquely
 */
public void speak(String text, Integer id) {
    setLocale();
    HashMap<String, String> params = new HashMap<String, String>();
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, id.toString());
    myTTS.speak(text, TextToSpeech.QUEUE_ADD, params);
}

From source file:com.app.azza.ocr.OcrCaptureActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();

    Text text = null;/*ww  w  . ja  v a  2s.c om*/
    List mtextList = getAllGraphicsText();
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (action == KeyEvent.ACTION_DOWN) {

            Toast toast = Toast.makeText(this, "volume up pressed", Toast.LENGTH_SHORT);
            toast.show();

            Log.v("upVolume", "up " + lineNumberToSpeak);
            //        for(Object block:textList){
            //             text=(Text)block;
            //
            //            tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
            //        }
            if (mtextList.size() > 0) {
                // for (int i = 0; i < textList.size(); i++) {
                if (lineNumberToSpeak < mtextList.size()) {
                    text = (Text) mtextList.get(lineNumberToSpeak);
                    if (text != null && text.getValue() != null) {
                        tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
                        if (lineNumberToSpeak < mtextList.size())
                            lineNumberToSpeak++;

                    } else {
                        Log.d(TAG, "text data is null");
                    }
                    // }
                } else {
                    // al list al gdeda lines feha 22al
                    lineNumberToSpeak = 0;
                }
            } else {
                Log.d(TAG, "no text detected");
            }

        }
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            Toast toast = Toast.makeText(this, "volume down pressed", Toast.LENGTH_SHORT);
            toast.show();
            if (mtextList.size() > 0) {
                // for (int i = 0; i < textList.size(); i++) {
                if (lineNumberToSpeak > -1) {
                    text = (Text) mtextList.get(lineNumberToSpeak);
                    if (text != null && text.getValue() != null) {
                        tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
                        if (lineNumberToSpeak > 0)
                            lineNumberToSpeak--;

                    } else {
                        Log.d(TAG, "text data is null");
                    }
                } else {
                    lineNumberToSpeak = 0;
                }
            } else {
                Log.d(TAG, "no text detected");
            }
        }
        return true;
    default:
        return super.dispatchKeyEvent(event);
    }
}

From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java

/**
 * onTap is called to speak the tapped TextBlock, if any, out loud.
 *
 * @param rawX - the raw position of the tap
 * @param rawY - the raw position of the tap.
 * @return true if the tap was on a TextBlock
 *///from   w w w  .  ja v a2s. c  o m
private boolean onTap(float rawX, float rawY) {

    OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);
    TextBlock text = null;
    if (graphic != null) {
        text = graphic.getTextBlock();
        if (text != null && text.getValue() != null) {
            Log.d(TAG, "text data is being spoken! " + text.getValue());
            // Speak the string.
            tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
        } else {
            Log.d(TAG, "text data is null");
        }
    } else {
        Log.d(TAG, "no text detected");
    }
    return text != null;
}