Java Code Examples for android.speech.tts.TextToSpeech#LANG_MISSING_DATA

The following examples show how to use android.speech.tts.TextToSpeech#LANG_MISSING_DATA . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadAloudService.java    From a with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onInit(int i) {
    if (i == TextToSpeech.SUCCESS) {
        int result = textToSpeech.setLanguage(Locale.CHINA);
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            mainHandler.post(() -> Toast.makeText(ReadAloudService.this, getString(R.string.tts_fix), Toast.LENGTH_SHORT).show());
            //先停止朗读服务方便用户设置好后的重试
            ReadAloudService.stop(ReadAloudService.this);
            //跳转到文字转语音设置界面
            toTTSSetting();
        } else {
            textToSpeech.setOnUtteranceProgressListener(new ttsUtteranceListener());
            ttsInitSuccess = true;
            playTTS();
        }
    } else {
        mainHandler.post(() -> Toast.makeText(ReadAloudService.this, getString(R.string.tts_init_failed), Toast.LENGTH_SHORT).show());
        ReadAloudService.this.stopSelf();
    }
}
 
Example 2
Source File: AnnouncementPeriodicTask.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Called when TTS is ready.
 */
private void onTtsReady() {
  Locale locale = Locale.getDefault();
  int languageAvailability = tts.isLanguageAvailable(locale);
  if (languageAvailability == TextToSpeech.LANG_MISSING_DATA
      || languageAvailability == TextToSpeech.LANG_NOT_SUPPORTED) {
    Log.w(TAG, "Default locale not available, use English.");
    locale = Locale.ENGLISH;
    /*
     * TODO: instead of using english, load the language if missing and show a
     * toast if not supported. Not able to change the resource strings to
     * English.
     */
  }
  tts.setLanguage(locale);

  // Slow down the speed just a bit as it is hard to hear when exercising.
  tts.setSpeechRate(TTS_SPEECH_RATE);

  tts.setOnUtteranceCompletedListener(utteranceListener);
}
 
Example 3
Source File: MainActivity.java    From journaldev with MIT License 6 votes vote down vote up
@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) {
            Toast.makeText(getApplicationContext(), "Language not supported", Toast.LENGTH_SHORT).show();
        } else {
            button.setEnabled(true);
        }

    } else {
        Toast.makeText(getApplicationContext(), "Init failed", Toast.LENGTH_SHORT).show();
    }
}
 
Example 4
Source File: TextToVoice.java    From Primary with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        int result = mTts.setLanguage(Locale.getDefault());
        isInit = true;

        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {

            Log.e("error", "This Language is not supported");
        }
        Log.d("TextToSpeech", "Initialization Suceeded! " + System.currentTimeMillis());

        speak(mContext.getString(R.string.voice_ready) + ",");
    } else {
        Log.e("error", "Initialization Failed! " + status);
    }
}
 
Example 5
Source File: ReadAloudService.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onInit(int i) {
    if (i == TextToSpeech.SUCCESS) {
        int result = textToSpeech.setLanguage(Locale.CHINA);
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            RxBus.get().post(RxBusTag.ALOUD_MSG, getString(R.string.tts_fix));
            //先停止朗读服务方便用户设置好后的重试
            ReadAloudService.stop(ReadAloudService.this);
            //跳转到文字转语音设置界面
            toTTSSetting();
        } else {
            textToSpeech.setOnUtteranceProgressListener(new ttsUtteranceListener());
            ttsInitSuccess = true;
            playTTS();
        }
    } else {
        RxBus.get().post(RxBusTag.ALOUD_MSG, getString(R.string.tts_init_failed));
        stopSelf();
    }
}
 
Example 6
Source File: ConversationActivity.java    From TranslateApp with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void speakOut(String textMessage, String languageCode){
    int result = mTextToSpeech.setLanguage(new Locale(languageCode));
    Log.e("Inside","speakOut "+languageCode+" "+result);
    if (result == TextToSpeech.LANG_MISSING_DATA ){
        Toast.makeText(getApplicationContext(),getString(R.string.language_pack_missing),Toast.LENGTH_SHORT).show();
        Intent installIntent = new Intent();
        installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        startActivity(installIntent);
    } else if(result == TextToSpeech.LANG_NOT_SUPPORTED) {
        Toast.makeText(getApplicationContext(),getString(R.string.language_not_supported),Toast.LENGTH_SHORT).show();
    } else {
        process_tts.show();
        map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "UniqueID");
        mTextToSpeech.speak(textMessage, TextToSpeech.QUEUE_FLUSH, map);
    }
}
 
Example 7
Source File: MainActivity.java    From CT_Android_demos with GNU General Public License v3.0 5 votes vote down vote up
@Override  
public void onInit(int status){  
    // �ж��Ƿ�ת���ɹ�  
    if (status == TextToSpeech.SUCCESS){  
        //Ĭ���趨����Ϊ���ģ�ԭ����androidò�Ʋ�֧�����ġ�
        int result = tts.setLanguage(Locale.CHINESE);  
        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED){  
            Toast.makeText(MainActivity.this, R.string.notAvailable, Toast.LENGTH_SHORT).show();  
        }else{
            //��֧�����ľͽ���������ΪӢ��
            tts.setLanguage(Locale.US);
        }  
    }  
}
 
Example 8
Source File: TextToSpeechActivity.java    From android-yolo-v2 with Do What The F*ck You Want To Public License 5 votes vote down vote up
@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(LOGGING_TAG, "Text to speech error: This Language is not supported");
        }
    } else {
        Log.e(LOGGING_TAG, "Text to speech: Initilization Failed!");
    }
}
 
Example 9
Source File: SmsReceivedDialog.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
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) {
            Log.e(TAG, "TTS language is not available.");
        } else {
            mTts.speak(mFullBodyString, TextToSpeech.QUEUE_ADD, null);
        }
    } else {
        // Initialization failed.
        Log.e(TAG, "Could not initialize TTS.");
    }
}
 
Example 10
Source File: EventSpeaker.java    From VIA-AI with MIT License 5 votes vote down vote up
@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        mTTS.setPitch(1.0f);
        mTTS.setSpeechRate(1.0f);
        int result = mTTS.setLanguage(Locale.US);

        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "This Language is not supported");
        }
    }
    else {
        Log.e("TTS", "Initilization Failed!");
    }
}
 
Example 11
Source File: BgToSpeech.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
private BgToSpeech(Context context){
    this.context = context;
    this.tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {

            Log.d("BgToSpeech", "Calling onInit(), tts = " + tts);
            if (status == TextToSpeech.SUCCESS && tts != null) {
                
                //try local language
                Locale loc = Locale.getDefault();
                Log.d("BgToSpeech", "status == TextToSpeech.SUCCESS + loc" + loc);
                int result = tts.setLanguage(Locale.getDefault());
                if (result == TextToSpeech.LANG_MISSING_DATA
                        || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                    Log.e("BgToSpeech", "Default system language is not supported");
                    result = tts.setLanguage(Locale.ENGLISH);
                }
                //try any english
                if (result == TextToSpeech.LANG_MISSING_DATA
                        || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                    Log.e("BgToSpeech", "English is not supported");
                    tts = null;
                }
            } else {
                Log.e("BgToSpeech", "status != TextToSpeech.SUCCESS; status: " + status);
                tts= null;
            }
        }
    });
}
 
Example 12
Source File: TextToSpeechActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
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.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) {
           // 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.
            // Allow the user to press the button for the app to speak again.
            mAgainButton.setEnabled(true);
            // Greet the user.
            sayHello();
        }
    } else {
        // Initialization failed.
        Log.e(TAG, "Could not initialize TextToSpeech.");
    }
}
 
Example 13
Source File: TTS.java    From Multiwii-Remote with Apache License 2.0 5 votes vote down vote up
@Override
public void onInit(int status) {
	if (status == TextToSpeech.SUCCESS) {

		int result = tts.setLanguage(Locale.ENGLISH);
		Log.d("aaa", Locale.getDefault().getLanguage());
		if (Locale.getDefault().getLanguage().equals("de")) {
			result = tts.setLanguage(Locale.getDefault());
			Log.d("aaa", "german");
		}

		if (Locale.getDefault().getLanguage().equals("hu")) {
			result = tts.setLanguage(Locale.getDefault());
			Log.d("aaa", "hungarian");
		}

		if (Locale.getDefault().getLanguage().equals("pl")) {
			result = tts.setLanguage(Locale.getDefault());
			Log.d("aaa", "polish");
		}

		if (result == TextToSpeech.LANG_MISSING_DATA
				|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
			Log.e("TTS", "This Language is not supported");
		}

		TTSinit = true;
		tts.speak(this.text, TextToSpeech.QUEUE_ADD, null);

	} else {
		TTSinit = false;
	}

	Log.d(tag, "text to speach init status " + String.valueOf(status));
	Log.d(tag, "text to speach init TTSinit " + String.valueOf(TTSinit));
}
 
Example 14
Source File: MainActivity.java    From reader with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	mTakePhoto = (Button) findViewById(R.id.take_photo);
	mImageView = (ImageView) findViewById(R.id.imageview);
	speak1 = (Button) findViewById(R.id.speak1);
	responseText = (TextView) findViewById(R.id.textView1);

	mTakePhoto.setOnClickListener(this);
	speak1.setOnClickListener(this);
	
	tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
           @Override
           public void onInit(int status) {
               // TODO Auto-generated method stub
               if (status == TextToSpeech.SUCCESS)
               {
                   int result = tts.setLanguage(Locale.CHINA);
                   if (result == TextToSpeech.LANG_MISSING_DATA
                           || result == TextToSpeech.LANG_NOT_SUPPORTED)
                   {
                       Toast.makeText(getApplicationContext(), "Language is not available.",
                               Toast.LENGTH_SHORT).show();
                   }
               } else {
               	Toast.makeText(getApplicationContext(), "Language is available.",
                           Toast.LENGTH_SHORT).show();
               }
           }
       });
}
 
Example 15
Source File: ExternalTextToSpeech.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
public int isLanguageAvailable(Locale loc) {
  return TextToSpeech.LANG_MISSING_DATA;
}
 
Example 16
Source File: MainService.java    From android-play-games-in-motion with Apache License 2.0 4 votes vote down vote up
@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
        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();
}
 
Example 17
Source File: VoiceActivity.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
   public void onInit(int status) { 
       if (status == TextToSpeech.SUCCESS) {
           List<String> locales = new ArrayList<String>();
           if (MainActivity.voice.language != null) {
           	locales.add(MainActivity.voice.language);
           }
           locales.add(Locale.US.toString());
           locales.add(Locale.UK.toString());
           locales.add(Locale.FRENCH.toString());
           locales.add(Locale.GERMAN.toString());
           locales.add("ES");
           locales.add("PT");
           locales.add(Locale.ITALIAN.toString());
           locales.add(Locale.CHINESE.toString());
           locales.add(Locale.JAPANESE.toString());
           locales.add(Locale.KOREAN.toString());
           for (Locale locale : Locale.getAvailableLocales()) {
           	try {
            	int code = this.tts.isLanguageAvailable(locale);
                if (code != TextToSpeech.LANG_NOT_SUPPORTED) {
                	locales.add(locale.toString());
                }
           	} catch (Exception ignore) {}
           }
   		Spinner spin = (Spinner) findViewById(R.id.languageSpin);
   		ArrayAdapter adapter = new ArrayAdapter(this,
                   android.R.layout.simple_spinner_dropdown_item, locales.toArray());
   		spin.setAdapter(adapter);
           if (MainActivity.voice.language != null) {
           	spin.setSelection(locales.indexOf(MainActivity.voice.language));
           }
   		
           int result = this.tts.setLanguage(Locale.US); 
           if (result == TextToSpeech.LANG_MISSING_DATA
                   || result == TextToSpeech.LANG_NOT_SUPPORTED) {
               Log.e("TTS", "This Language is not supported");
           }
       } else {
           Log.e("TTS", "Initilization Failed!");
       }

   }
 
Example 18
Source File: VoiceActivity.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
   public void onInit(int status) { 
       if (status == TextToSpeech.SUCCESS) {
           List<String> locales = new ArrayList<String>();
           if (MainActivity.voice.language != null) {
           	locales.add(MainActivity.voice.language);
           }
           locales.add(Locale.US.toString());
           locales.add(Locale.UK.toString());
           locales.add(Locale.FRENCH.toString());
           locales.add(Locale.GERMAN.toString());
           locales.add("ES");
           locales.add("PT");
           locales.add(Locale.ITALIAN.toString());
           locales.add(Locale.CHINESE.toString());
           locales.add(Locale.JAPANESE.toString());
           locales.add(Locale.KOREAN.toString());
           for (Locale locale : Locale.getAvailableLocales()) {
           	try {
            	int code = this.tts.isLanguageAvailable(locale);
                if (code != TextToSpeech.LANG_NOT_SUPPORTED) {
                	locales.add(locale.toString());
                }
           	} catch (Exception ignore) {}
           }
   		Spinner spin = (Spinner) findViewById(R.id.languageSpin);
   		ArrayAdapter adapter = new ArrayAdapter(this,
                   android.R.layout.simple_spinner_dropdown_item, locales.toArray());
   		spin.setAdapter(adapter);
           if (MainActivity.voice.language != null) {
           	spin.setSelection(locales.indexOf(MainActivity.voice.language));
           }
   		
           int result = this.tts.setLanguage(Locale.US); 
           if (result == TextToSpeech.LANG_MISSING_DATA
                   || result == TextToSpeech.LANG_NOT_SUPPORTED) {
               Log.e("TTS", "This Language is not supported");
           }
       } else {
           Log.e("TTS", "Initilization Failed!");
       }

   }
 
Example 19
Source File: VoiceActivity.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
   public void onInit(int status) { 
       if (status == TextToSpeech.SUCCESS) {
           List<String> locales = new ArrayList<String>();
           if (MainActivity.voice.language != null) {
           	locales.add(MainActivity.voice.language);
           }
           locales.add(Locale.US.toString());
           locales.add(Locale.UK.toString());
           locales.add(Locale.FRENCH.toString());
           locales.add(Locale.GERMAN.toString());
           locales.add("ES");
           locales.add("PT");
           locales.add(Locale.ITALIAN.toString());
           locales.add(Locale.CHINESE.toString());
           locales.add(Locale.JAPANESE.toString());
           locales.add(Locale.KOREAN.toString());
           for (Locale locale : Locale.getAvailableLocales()) {
           	try {
            	int code = this.tts.isLanguageAvailable(locale);
                if (code != TextToSpeech.LANG_NOT_SUPPORTED) {
                	locales.add(locale.toString());
                }
           	} catch (Exception ignore) {}
           }
   		Spinner spin = (Spinner) findViewById(R.id.languageSpin);
   		ArrayAdapter adapter = new ArrayAdapter(this,
                   android.R.layout.simple_spinner_dropdown_item, locales.toArray());
   		spin.setAdapter(adapter);
           if (MainActivity.voice.language != null) {
           	spin.setSelection(locales.indexOf(MainActivity.voice.language));
           }
   		
           int result = this.tts.setLanguage(Locale.US); 
           if (result == TextToSpeech.LANG_MISSING_DATA
                   || result == TextToSpeech.LANG_NOT_SUPPORTED) {
               Log.e("TTS", "This Language is not supported");
           }
       } else {
           Log.e("TTS", "Initilization Failed!");
       }

   }
 
Example 20
Source File: VoiceActivity.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
   public void onInit(int status) { 
       if (status == TextToSpeech.SUCCESS) {
           List<String> locales = new ArrayList<String>();
           if (MainActivity.voice.language != null) {
           	locales.add(MainActivity.voice.language);
           }
           locales.add(Locale.US.toString());
           locales.add(Locale.UK.toString());
           locales.add(Locale.FRENCH.toString());
           locales.add(Locale.GERMAN.toString());
           locales.add("ES");
           locales.add("PT");
           locales.add(Locale.ITALIAN.toString());
           locales.add(Locale.CHINESE.toString());
           locales.add(Locale.JAPANESE.toString());
           locales.add(Locale.KOREAN.toString());
           for (Locale locale : Locale.getAvailableLocales()) {
           	try {
            	int code = this.tts.isLanguageAvailable(locale);
                if (code != TextToSpeech.LANG_NOT_SUPPORTED) {
                	locales.add(locale.toString());
                }
           	} catch (Exception ignore) {}
           }
   		Spinner spin = (Spinner) findViewById(R.id.languageSpin);
   		ArrayAdapter adapter = new ArrayAdapter(this,
                   android.R.layout.simple_spinner_dropdown_item, locales.toArray());
   		spin.setAdapter(adapter);
           if (MainActivity.voice.language != null) {
           	spin.setSelection(locales.indexOf(MainActivity.voice.language));
           }
   		
           int result = this.tts.setLanguage(Locale.US); 
           if (result == TextToSpeech.LANG_MISSING_DATA
                   || result == TextToSpeech.LANG_NOT_SUPPORTED) {
               Log.e("TTS", "This Language is not supported");
           }
       } else {
           Log.e("TTS", "Initilization Failed!");
       }

   }