TextToSpeech setLanguage - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TextToSpeech setLanguage method.

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());
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.");
        } 
    } 
 
6
CodeRank
This code example shows how to use the following methods:setLanguage, setOnUtteranceCompletedListener, shutdown, stop
    } 
     
    @Override 
    public void onDestroy() { 
        if (mTts != null) {
            mTts.stop();
            mTts.shutdown();
        } 
        super.onDestroy(); 
    } 
 
    public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {
            int result = mTts.setLanguage(Locale.ENGLISH);
            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
            	this.onDestroy();
            mTts.setOnUtteranceCompletedListener(this);
        } 
    } 
 

6
CodeRank
This code example shows how to use the following methods:isLanguageAvailable, setLanguage, setPitch, setSpeechRate
    } 
     
    public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {
            Locale locale = Locale.ENGLISH;
            if (tts.isLanguageAvailable(locale) >=
                TextToSpeech.LANG_AVAILABLE) {
                tts.setLanguage(locale);
                tts.setPitch(1.5f);
                tts.setSpeechRate(1.5f);
                return; 
            } 
        } 
        Logger.d("Failed to initialize"); 
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:isLanguageAvailable, setLanguage, setOnUtteranceCompletedListener, setSpeechRate, sleep
 
	@SuppressWarnings("deprecation") 
	@Override 
	public void onInit(int arg0)
	{ 
		mTts.setOnUtteranceCompletedListener(this);
 
		Locale l = Locale.getDefault();
		int result = mTts.isLanguageAvailable(l);
		if (result == TextToSpeech.LANG_AVAILABLE || result == TextToSpeech.LANG_COUNTRY_AVAILABLE
				|| result == TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)
		{ 
 
			mTts.setLanguage(l);
		} else 
		{ 
			Toast.makeText(context, "Lang not available:" + result, Toast.LENGTH_LONG).show();
		} 
 
		mTts.setSpeechRate(0.85f);

6
CodeRank
This code example shows how to use the following methods:setLanguage
    @Override 
    public void onInit(int status) {
        // Set a flag so that the TaskBackService knows that the Text-To-Speech 
        // engine has been initialized, and can now handle speaking requests. 
        if (status == TextToSpeech.SUCCESS) {
            mTts.setLanguage(Locale.US);
            mTextToSpeechInitialized = true;
        } 
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    @Override 
    public void onDestroy() { 
        super.onDestroy(); 
        if (mTextToSpeechInitialized) {
            mTts.shutdown();
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:isLanguageAvailable, setLanguage, setOnUtteranceCompletedListener, setPitch, speak
    @Override 
    public void onInit(int status) {
    	Locale locale = new Locale("spa", "MEX");
        if (status == TextToSpeech.SUCCESS) {
            setTtsListener(); 
       	 	tts.setPitch(0.5f);
            switch (tts.isLanguageAvailable(locale))
            { 
                case TextToSpeech.LANG_AVAILABLE:
                case TextToSpeech.LANG_COUNTRY_AVAILABLE:
                case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
                    Log.d(TAG, "SUPPORTED");
                    tts.setLanguage(locale);
                    break; 
                case TextToSpeech.LANG_MISSING_DATA:
                    Log.d(TAG, "MISSING_DATA");
                    // missing data, install it 
                    Intent installIntent = new Intent();
                    installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                    startActivity(installIntent);

6
CodeRank
This code example shows how to use the following methods:isLanguageAvailable, setLanguage, setOnUtteranceCompletedListener, setOnUtteranceProgressListener, speak
    @SuppressWarnings("deprecation") 
    @Override 
    public void onInit(int initStatus) {
        if (initStatus == TextToSpeech.SUCCESS) { 
            hashMap.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "speechMessage"); 
            if (myTTS.isLanguageAvailable(Locale.UK) == TextToSpeech.LANG_COUNTRY_AVAILABLE) { 
                myTTS.setLanguage(Locale.UK); 
            } 
            if (Build.VERSION.SDK_INT >= 15) { 
                myTTS.setOnUtteranceProgressListener(new UtteranceProgressListener() { 
                    @Override 
                    public void onStart(String s) { 
 
                    } 
 
                    @Override 
                    public void onDone(String s) { 
                        onComplete(); 
                    } 
 

6
CodeRank
This code example shows how to use the following methods:setLanguage, setSpeechRate, speak
	 
	/** Need a number to tell screens apart.  Why not speech id? */ 
	private int screenModifier;
	 
	public SMSDelegate(SMSDelegateCallback callback, Activity context, int xmlResId) {
		this.tts = new TextToSpeech(context, this);
		this.smsCallback = callback;
		this.callback = context;
		this.screenModifier = xmlResId;
		 
		speechPack = new SpeechPack(context, xmlResId);
		 
		tts.setLanguage(Locale.US);
		tts.setSpeechRate(4);
		tts.speak("", TextToSpeech.QUEUE_FLUSH, null);
		 
		queuedMessages = new ArrayList<String>();
		isHidden = true;
	} 
	 
6
CodeRank

Related TextToSpeech setLanguage Questions & Answers:

Other TextToSpeech setLanguage Examples

55:			if (status == TextToSpeech.SUCCESS) {
56:	
57:				int result = tts.setLanguage(Locale.US);
58:	
59:				if (result == TextToSpeech.LANG_MISSING_DATA

Read More

setLanguage Method Overview
Sets the text-to-speech language.
See Code Examples for other Android TextToSpeech Methods: