Best code examples for Android TextToSpeech class (android.speech.tts.TextToSpeech)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android TextToSpeech class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android TextToSpeech examples from Open Source projects
This code example shows how to use the following methods: getFeatures, getLanguage, isLanguageAvailable, speak
        } 
        return null; 
    } 
 
    private boolean isNetworkRequiredForSynthesis() { 
        Set<String> features = mTts.getFeatures(mTts.getLanguage());
        return features.contains(TextToSpeech.Engine.KEY_FEATURE_NETWORK_SYNTHESIS) &&
                !features.contains(TextToSpeech.Engine.KEY_FEATURE_EMBEDDED_SYNTHESIS);
    } 
 
    private void onSampleTextReceived(int resultCode, Intent data) {
        String sample = getDefaultSampleString();
 
        if (resultCode == TextToSpeech.LANG_AVAILABLE && data != null) {
            if (data != null && data.getStringExtra("sampleText") != null) {
                sample = data.getStringExtra("sampleText");
            } 
            if (DBG) Log.d(TAG, "Got sample text: " + sample);
        } else { 
            if (DBG) Log.d(TAG, "Using default sample text :" + sample);

8
CodeRank
This code example shows how to use the following methods:
 
        return false; 
    } 
 
    private void initTTS() { 
        mTts = new TextToSpeech(context, (OnInitListener)this);
    } 
 
    public void queueSpeak(String textToSpeak) {
        if (mTts != null && isTTSInitialized) {
            mTts.speak(textToSpeak, TextToSpeech.QUEUE_ADD, ttsParams);
            while (mTts.isSpeaking()) {
                try { 
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block 
                    e.printStackTrace();
                } 
            } 
        } else { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setLanguage
 
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == 1) {
 
			if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
				myTTS = new TextToSpeech(this, this);
				myTTS.setLanguage(Locale.US);
			} else { 
				// TTS data not yet loaded, try to install it 
				Intent ttsLoadIntent = new Intent();
				ttsLoadIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
				startActivity(ttsLoadIntent);
			} 
		} 
	} 
 
	public void onInit(int status) {
		if (status == TextToSpeech.SUCCESS) {
			 
			int n = (int)(Math.random() * phrases.size());
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setLanguage, setPitch, setSpeechRate, speak
    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 result will indicate this. 
            int result = mTts.setLanguage(Locale.UK);
            // Try this someday for some interesting results. 
            // int result mTts.setLanguage(Locale.FRANCE); 
            if (result == TextToSpeech.LANG_MISSING_DATA ||
                result == TextToSpeech.LANG_NOT_SUPPORTED) {
               // Lanuage data is missing or the language is not supported. 
                Log.e(TAG, "Language is not available.");
            } else { 
                // Check the documentation for other possible result codes. 
                // For example, the language may be available for the locale, 
                // but not for the specified country and variant. 
 
                // The TTS engine has been successfully initialized. 
                mTts.setPitch(1.6f);
                mTts.setSpeechRate(1.05f);

7
CodeRank
This code example shows how to use the following methods: setLanguage
 
    // Implements TextToSpeech.OnInitListener. 
    public void onInit(int status) {
        // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR. 
        if (status == TextToSpeech.SUCCESS) {
            int result = mTts.setLanguage(Locale.US);
            if (result == TextToSpeech.LANG_MISSING_DATA ||
                result == TextToSpeech.LANG_NOT_SUPPORTED) {
               // Language data is missing or the language is not supported. 
                Log.e(TAG, "Language is not available.");
            } else { 
                Log.i(TAG, "TextToSpeech Initialized.");
                mSpeakingEngineAvailable = true;
            } 
        } else { 
            // Initialization failed. 
            Log.e(TAG, "Could not initialize TextToSpeech.");
        } 
    } 
 
Full Snippet Info
6
CodeRank
Related Android TextToSpeech Questions & Answers:
Other Android TextToSpeech Examples
14:		/** Called when the activity is first created. */
15:	
16:		private TextToSpeech tts;
17:		private Button btnSpeak;
18:		private EditText txtText;
-
23:			setContentView(R.layout.main);
24:	
25:			tts = new TextToSpeech(this, this);
26:	
27:			btnSpeak = (Button) findViewById(R.id.btnSpeak);

Read More

See Code Examples for Android TextToSpeech Methods: