Example usage for android.speech.tts TextToSpeech LANG_MISSING_DATA

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

Introduction

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

Prototype

int LANG_MISSING_DATA

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

Click Source Link

Document

Denotes the language data is missing.

Usage

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

public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        int result = mTts.setLanguage(Locale.US);
        // Try this someday for some interesting results.
        // int result mTts.setLanguage(Locale.FRANCE);
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e(TAG, "Language is not available.");
        } else {/* w  w w  . j a v  a 2  s . co m*/
            this.twitter = G.checkTwitterCreds();

            if (twitter == null) {
                startActivityForResult(new Intent(this, TwitterLoginActivity.class), G.REQCODE_TWITTER_LOGIN);
            } else {
                speakTwit();
            }
        }
    } else {
        Log.e(TAG, "TTS init error: " + status);
    }
}

From source file:com.xengar.android.englishverbs.ui.DetailsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_details);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   ww w  .j a v  a 2s .  c o  m
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    Bundle bundle = getIntent().getExtras();
    demo = bundle.getBoolean(DEMO_MODE, false);
    verbID = bundle.getLong(VERB_ID, -1);
    String title = bundle.getString(VERB_NAME);
    getSupportActionBar().setTitle(title);

    // Invalidate the options menu, so the "Edit" menu option can be hidden.
    invalidateOptionsMenu();

    //Text
    infinitive = (TextView) findViewById(R.id.infinitive);
    simplePast = (TextView) findViewById(R.id.simple_past);
    pastParticiple = (TextView) findViewById(R.id.past_participle);
    pInfinitive = (TextView) findViewById(R.id.phonetic_infinitive);
    pSimplePast = (TextView) findViewById(R.id.phonetic_simple_past);
    pPastParticiple = (TextView) findViewById(R.id.phonetic_past_participle);
    definition = (TextView) findViewById(R.id.definition);
    translation = (TextView) findViewById(R.id.translation);
    sample1 = (TextView) findViewById(R.id.sample1);
    sample2 = (TextView) findViewById(R.id.sample2);
    sample3 = (TextView) findViewById(R.id.sample3);

    // define click listeners
    LinearLayout header = (LinearLayout) findViewById(R.id.play_infinitive);
    header.setOnClickListener(this);
    header = (LinearLayout) findViewById(R.id.play_simple_past);
    header.setOnClickListener(this);
    header = (LinearLayout) findViewById(R.id.play_past_participle);
    header.setOnClickListener(this);

    // initialize Speaker
    tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {
                int result = tts.setLanguage(Locale.US);
                if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                    if (LOG) {
                        Log.e("TTS", "This Language is not supported");
                    }
                }
            } else {
                if (LOG) {
                    Log.e("TTS", "Initilization Failed!");
                }
            }
        }
    });

    // Initialize a loader to read the verb data from the database and display it
    getLoaderManager().initLoader(EXISTING_VERB_LOADER, null, this);
    showFavoriteButtons();

    // Obtain the FirebaseAnalytics instance.
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    ActivityUtils.firebaseAnalyticsLogEventSelectContent(mFirebaseAnalytics, PAGE_VERB_DETAILS,
            PAGE_VERB_DETAILS, TYPE_PAGE);

    // create AdMob banner
    listener = new LogAdListener(mFirebaseAnalytics, DETAILS_ACTIVITY);
    mAdView = ActivityUtils.createAdMobBanner(this, listener);

    if (demo) {
        defineDemoMode();
    }
}

From source file:com.nbplus.vbroadlistener.BaseActivity.java

@Override
public void onInit(int status) {
    Log.d(TAG, "> TTS onInit()");

    LauncherSettings.getInstance(this).setIsCheckedTTSEngine(true);
    if (status != TextToSpeech.SUCCESS) {
        Log.e(TAG, String.format("TextToSpeechManager.onInit(%d) fail!", status));
        Log.d(TAG, "   ??.... ? ??...");
        if (mcheckText2SpeechLister != null) {
            mcheckText2SpeechLister.onCheckResult(null);
            mText2Speech.shutdown();/*w  w  w  .j  av  a  2 s.c  o  m*/
            mText2Speech = null;
        }
        showText2SpeechAlertDialog();
    } else {
        int result = mText2Speech.setLanguage(Locale.KOREA);
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e(TAG, String.format("TextToSpeech.setLanguage(%s) fail!", Locale.KOREA.getDisplayName()));
            Log.d(TAG, "   ??.... ? ??...");
            if (mcheckText2SpeechLister != null) {
                mcheckText2SpeechLister.onCheckResult(null);
                mText2Speech.shutdown();
                mText2Speech = null;
            }
            showText2SpeechAlertDialog();
        } else {
            if (mcheckText2SpeechLister != null) {
                mcheckText2SpeechLister.onCheckResult(mText2Speech);

            } else {
                if (mcheckText2SpeechLister != null) {
                    mcheckText2SpeechLister.onCheckResult(null);
                    mText2Speech.shutdown();
                    mText2Speech = null;
                }
            }
        }
    }
}

From source file:com.example.h156252.connected_cars.CarGrid.java

@Override
public void onInit(int status) {

    if (status == TextToSpeech.SUCCESS) {

        int result = tts.setLanguage(Locale.US);

        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "This Language is not supported");
        } else {//  w w  w  .  ja v  a  2  s. c  o  m
            /*btnSpeak.setEnabled(true);
            speakOut();*/
        }

    } else {
        Log.e("TTS", "Initilization Failed!");
    }

}

From source file:com.abid_mujtaba.fetchheaders.MainActivity.java

@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        int result = mTTS.setLanguage(Locale.US);

        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Resources.Loge("This Language is not supported. result: " + result, null);
            Resources.Loge(/*from   w  ww  . j ava2 s  .  co  m*/
                    "If result is -1 simply install 'Speech Synthesis Data Installer' from the Google Play Store.",
                    null);
        } else {
            return;
        }
    }

    mTTS.stop();
    mTTS.shutdown();
    mTTS = null;

    Resources.Loge("Initialization failed", null);
}

From source file:com.nbplus.vbroadlauncher.service.BroadcastChatHeadService.java

@Override
public void onInit(int status) {
    Log.d(TAG, "> TTS onInit()");

    if (status != TextToSpeech.SUCCESS) {
        Log.e(TAG, String.format("TextToSpeechManager.onInit(%d) fail!", status));
        Log.d(TAG, "   ??.... ? ??...");
        mText2Speech.shutdown();/*from   w ww .  jav a2 s  .  c  o  m*/
        mText2Speech = null;

        // TODO : ? ?????
    } else {
        int result = mText2Speech.setLanguage(Locale.KOREA);
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e(TAG, String.format("TextToSpeech.setLanguage(%s) fail!", Locale.KOREA.getDisplayName()));

            // TODO : ? ?????
            mText2Speech.shutdown();
            mText2Speech = null;
        } else {
            mText2SpeechHandler.setTextToSpeechObject(mText2Speech);
            mText2SpeechHandler.play(mBroadcastData.getMessage());
        }
    }
}

From source file:com.google.fpl.gim.examplegame.MainService.java

@Override
public void onCreate() {
    // The service is being created.
    Utils.logDebug(TAG, "onCreate");
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(CHOICE_NOTIFICATION_ACTION_1);
    intentFilter.addAction(CHOICE_NOTIFICATION_ACTION_2);
    intentFilter.addAction(CHOICE_NOTIFICATION_ACTION_3);
    registerReceiver(mReceiver, intentFilter);

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    // Determines the behavior for handling Audio Focus surrender.
    mAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
        @Override/*from  w  w w. j  av a2s .  c om*/
        public void onAudioFocusChange(int focusChange) {
            if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT
                    || focusChange == AudioManager.AUDIOFOCUS_LOSS) {

                if (mTextToSpeech.isSpeaking()) {
                    mTextToSpeech.setOnUtteranceProgressListener(null);
                    mTextToSpeech.stop();
                }

                if (mMediaPlayer.isPlaying()) {
                    mMediaPlayer.stop();
                }

                // Abandon Audio Focus, if it's requested elsewhere.
                mAudioManager.abandonAudioFocus(mAudioFocusChangeListener);

                // Restart the current moment if AudioFocus was lost. Since AudioFocus is only
                // requested away from this application if this application was using it,
                // only Moments that play sound will restart in this way.
                if (mMission != null) {
                    mMission.restartMoment();
                }
            }
        }
    };

    // Asynchronously prepares the TextToSpeech.
    mTextToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {
                // Check if language is available.
                switch (mTextToSpeech.isLanguageAvailable(DEFAULT_TEXT_TO_SPEECH_LOCALE)) {
                case TextToSpeech.LANG_AVAILABLE:
                case TextToSpeech.LANG_COUNTRY_AVAILABLE:
                case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
                    Utils.logDebug(TAG, "TTS locale supported.");
                    mTextToSpeech.setLanguage(DEFAULT_TEXT_TO_SPEECH_LOCALE);
                    mIsTextToSpeechReady = true;
                    break;
                case TextToSpeech.LANG_MISSING_DATA:
                    Utils.logDebug(TAG, "TTS missing data, ask for install.");
                    Intent installIntent = new Intent();
                    installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                    startActivity(installIntent);
                    break;
                default:
                    Utils.logDebug(TAG, "TTS local not supported.");
                    break;
                }
            }
        }
    });

    mMediaPlayer = new MediaPlayer();
}

From source file:com.bdcorps.videonews.MainActivity.java

@Override
public void onInit(int status) {

    // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR
    if (status == TextToSpeech.SUCCESS) {
        // Set preferred language to US english.
        // Note that a language may not be available, and the topicNames will indicate this.
        int result = mTts.setLanguage(Locale.US);

        mTts.setOnUtteranceCompletedListener(this);

        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            // Lanuage data is missing or the language is not supported.
            Log.e("404", "Language is not available.");
        }//from   w w  w. j  ava2 s .  c  o  m
    } else {
        // Initialization failed.
        Log.e("404", "Could not initialize TextToSpeech.");
        // May be its not installed so we prompt it to be installed
        Intent installIntent = new Intent();
        installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        startActivity(installIntent);
    }

}

From source file:finalproject.ece558.edu.pdx.ece.brailleblackjack.PlayBlackJackGameFragment.java

/**
 * Check accessibility and set flags. Set-up The Android TextToSpeech Engine. Also Set-up
 *  the Google MessageApi Client./*from   w  w  w.j a v  a 2  s. co  m*/
 *
 *  Android Developers Website was used to aid in creating the MessageApi Client. For more info
 *   go there
 *  Source: http://developer.android.com/training/wearables/data-layer/events.html
 * @param savedInstanceState
 *
 * A Tutorial from tutorialspoint.com was used to aid with Android TextToSpeech
 *  Source: http://www.tutorialspoint.com/android/android_text_to_speech.htm
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    context = this.getActivity();

    /* Check if Accessibility is on to Speak upon certain events */
    am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    isAccessibilityEnabled = am.isEnabled();
    isExploreByTouchEnabled = am.isTouchExplorationEnabled();

    /* Set-up the TTS Api */
    textToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {
                int result = textToSpeech.setLanguage(Locale.US);
                if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                    Log.e("error", "Language chosen is not supported");
                } else {
                    if (isAccessibilityEnabled) {
                        if (!first_draw_spoken) {
                            String speak = "You drew " + player_left_card.getCardDescription() + " and "
                                    + player_right_card.getCardDescription() + "\n  Dealer drew "
                                    + dealer_right_card.getCardDescription();

                            convertTextToSpeech(speak);
                            first_draw_spoken = true;
                        }
                    }
                }
            } else {
                Log.e("error", "Initialization Failed!");
            }
        }
    });

    Log.d(TAG, "Attempting to connect to Google Api Client");
    mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(Wearable.API).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).build();
    Log.d(TAG, "Connected to Google Api Client");

    // Initialize state flags
    button_hit_state = true;
    button_stand_state = true;
    button_hint_state = true;
    button_start_over_state = true;
    first_draw_spoken = false;
}

From source file:com.ola.insta.BookingAcivity.java

@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        int result = mTextToSpeech.setLanguage(Locale.US);
        // mTextToSpeech.setPitch(5); // set pitch level
        mTextToSpeech.setSpeechRate(0.8f); // set speech speed rate
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TextToSpeech", "Language is not supported");
        }/*from  www.j  a v  a2  s.  c o m*/
        speakOut("Tap on mike and say; CHALLO NEEKLLO!");
    } else {
        Log.e("TextToSpeech", "Initilization Failed");
    }

}