TextToSpeech speak - 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 speak method.

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: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:speak
        Log.i(TAG, "TextToSpeech Shut Down.");
 
    } 
    public void say(String text) {
        if (mSpeak && mSpeakingEngineAvailable) {
            mTts.speak(text,
                    TextToSpeech.QUEUE_ADD,  // Drop all pending entries in the playback queue.
                    null); 
        } 
    } 
 
    // 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.");
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: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);

6
CodeRank
This code example shows how to use the following methods:isSpeaking, speak, stop
public class TTSComponent extends Fragment implements TTS, OnInitListener {
    private TextToSpeech tts;
     
    @Override 
    public void speech(String text) {
        if (tts.isSpeaking()) {
            tts.stop();
        } 
 
        tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
    } 
 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return new View(getActivity());
    } 
 
    @Override 
    public void onCreate(Bundle savedInstanceState) {
6
CodeRank
This code example shows how to use the following methods:isSpeaking, setOnUtteranceCompletedListener, setPitch, setSpeechRate, speak
		 
	@Kroll.method 
	public boolean isSpeaking() { 
		Log.d(LCAT, "isSpeaking" );
		if (initialized) {
			return tts.isSpeaking();
		} 
		return false; 
	} 
	 
	@Kroll.method 
	public boolean speak(String text, @Kroll.argument(optional = true) String utteranceId) {
		Log.d(LCAT, "speak " + text);
		if (initialized) {
			if (0 < text.length()) {
				if (tts.setPitch(getPitch()) == TextToSpeech.ERROR) {
					Log.e("TTS", "Ptich(" + getPitch() + ") set error.");
				} 
				if (tts.setSpeechRate(getRate()) == TextToSpeech.ERROR) {
					Log.e("TTS", "Speech rate(" + getRate() + ") set error.");

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
This code example shows how to use the following methods:setLanguage, 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.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);

5
CodeRank

Related TextToSpeech speak Questions & Answers:

Other TextToSpeech speak Examples

75:			String text = txtText.getText().toString();
76:	
77:			tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
78:		}
79:	}

Read More

speak Method Overview
Speaks the string using the specified queuing strategy and speech parameters.
See Code Examples for other Android TextToSpeech Methods: