Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

TTS text to speech Android example


Android development example source code


// import
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
// you have to add implementation
public class Main extends Activity implements TextToSpeech.OnInitListener {
        private int _langTTSavailable = -1; // set up in onInit method
        // declaration
	private TextToSpeech mTts;


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
// assigned handle - initialisation
			mTts = new TextToSpeech(this,
			        (OnInitListener) this  // TextToSpeech.OnInitListener
			        );
}

   // Implements TextToSpeech.OnInitListener.
    public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {
            // Set preferred language to US english.
             _langTTSavailable = mTts.setLanguage(Locale.US); // Locale.FRANCE etc.
            if (_langTTSavailable == TextToSpeech.LANG_MISSING_DATA ||
            	_langTTSavailable == TextToSpeech.LANG_NOT_SUPPORTED) {
             } else if ( _langTTSavailable >= 0) {
			 mTts.speak("Good morning",
            TextToSpeech.QUEUE_FLUSH,  // Drop all pending entries in the playback queue.
            null);
            }
        } else {
            // Initialization failed.
        }
    }

    @Override
    public void onDestroy() {
        // TTS shutdown!
        if (mTts != null) {
            mTts.stop();
            mTts.shutdown();
        }

        super.onDestroy();
    }

}










Get supported language:


private TextToSpeech mTts;
// public void onInit(int status){
int result;
String s;
result = mTts.setLanguage(	Locale.	CANADA	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	CANADA	 not supported<br>"	;}else{s+="	CANADA	 supported<br>";}
result = mTts.setLanguage(	Locale.	CANADA_FRENCH	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	CANADA_FRENCH	 not supported<br>"	;}else{s+="	CANADA_FRENCH	 supported<br>";}
result = mTts.setLanguage(	Locale.	CHINA	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	CHINA	 not supported<br>"	;}else{s+="	CHINA	 supported<br>";}
result = mTts.setLanguage(	Locale.	CHINESE	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	CHINESE	 not supported<br>"	;}else{s+="	CHINESE	 supported<br>";}
result = mTts.setLanguage(	Locale.	ENGLISH	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	ENGLISH	 not supported<br>"	;}else{s+="	ENGLISH	 supported<br>";}
result = mTts.setLanguage(	Locale.	FRANCE	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	FRANCE	 not supported<br>"	;}else{s+="	FRANCE	 supported<br>";}
result = mTts.setLanguage(	Locale.	FRENCH	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	FRENCH	 not supported<br>"	;}else{s+="	FRENCH	 supported<br>";}
result = mTts.setLanguage(	Locale.	GERMAN	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	GERMAN	 not supported<br>"	;}else{s+="	GERMAN	 supported<br>";}
result = mTts.setLanguage(	Locale.	GERMANY	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	GERMANY	 not supported<br>"	;}else{s+="	GERMANY	 supported<br>";}
result = mTts.setLanguage(	Locale.	ITALIAN	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	ITALIAN	 not supported<br>"	;}else{s+="	ITALIAN	 supported<br>";}
result = mTts.setLanguage(	Locale.	ITALY	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	ITALY	 not supported<br>"	;}else{s+="	ITALY	 supported<br>";}
result = mTts.setLanguage(	Locale.	JAPAN	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	JAPAN	 not supported<br>"	;}else{s+="	JAPAN	 supported<br>";}
result = mTts.setLanguage(	Locale.	JAPANESE	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	JAPANESE	 not supported<br>"	;}else{s+="	JAPANESE	 supported<br>";}
result = mTts.setLanguage(	Locale.	KOREA	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	KOREA	 not supported<br>"	;}else{s+="	KOREA	 supported<br>";}
result = mTts.setLanguage(	Locale.	KOREAN	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	KOREAN	 not supported<br>"	;}else{s+="	KOREAN	 supported<br>";}
result = mTts.setLanguage(	Locale.	PRC	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	PRC	 not supported<br>"	;}else{s+="	PRC	 supported<br>";}
result = mTts.setLanguage(	Locale.	ROOT	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	ROOT	 not supported<br>"	;}else{s+="	ROOT	 supported<br>";}
result = mTts.setLanguage(	Locale.	SIMPLIFIED_CHINESE	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	SIMPLIFIED_CHINESE	 not supported<br>"	;}else{s+="	SIMPLIFIED_CHINESE	 supported<br>";}
result = mTts.setLanguage(	Locale.	TAIWAN	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	TAIWAN	 not supported<br>"	;}else{s+="	TAIWAN	 supported<br>";}
result = mTts.setLanguage(	Locale.	TRADITIONAL_CHINESE	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	TRADITIONAL_CHINESE	 not supported<br>"	;}else{s+="	TRADITIONAL_CHINESE	 supported<br>";}
result = mTts.setLanguage(	Locale.	UK	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	UK	 not supported<br>"	;}else{s+="	UK	 supported<br>";}
result = mTts.setLanguage(	Locale.	US	);	if (result == TextToSpeech.LANG_MISSING_DATA ||result == TextToSpeech.LANG_NOT_SUPPORTED) {s +=	 "	US	 not supported<br>"	;}else{s+="	US	 supported<br>";}


397LW NO topic_id



Další témata ....(Topics)


256

Spinner Text Size Android Example | spinner-text-size-android-example



      Spinner  _spin1 = (Spinner) findViewById(R.id.spinLangFirst);
      ArrayAdapter<String> adapterJazyky = new ArrayAdapter<String>(this,
              R.layout.spinner_text_layout.xml, {"one","two","etc...."});
      adapterJazyky.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      _spin1.setAdapter(adapterJazyky);





spinner_text_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="//schemas.android.com/apk/res/android"
          android:id="@+id/spinnerText"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
         
         android:textSize="20sp"
/>
86

Map TreeMap key value pair add put get pair by key Java Android example | map-treemap-key-value-pair-add-put-get-pair-by-key-java-android-example


Map TreeMap add key value pair get find pair by key Java Android example.

MainClass.java

import java.util.Map;
import java.util.TreeMap;

public class MainClass {
	public static void main(String[] arg) {
		
		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;zwei", "three;drei" };

		Map<String, String> map = new TreeMap<String, String>();
	    
		for(String s: arrayOfString){
	    	String[] array = s.split(";");
	    	String sKey ="", sValue="";
	    	if(array.length > 1){
	    	sKey = array[0]; sValue = array[1];
	    		map.put(sKey, sValue);
	    	}
	    }

       // check if key exists 	    
	   if( map.containsKey("two")){
		System.out.print("two = " + map.get("two"));
	   }
	}
}
/*
two = zwei
 */

382

Android Studio Browse Files Data Device Emulator | android-studio-browse-data-device-emulator


1.) Open DDMS via Menu Tools > Android > Android Device Monitor
2.) Select Device
3.) In DDMS click Menu Window > Show View > File Exlporer
4.) Device > Storage folder
5.) Emulator > data > data folder
310

ADT Bundle 22.6.2 have memory leak. | adt-bundle-22-6-2-have-memory-leak


If I trying
android-sdk_r22.6.2-windows.zip
adt-bundle-windows-x86_64-20140321.zip
and open xml layout graphic editor and xml layout file
memory continues to grow to crashes Eclipse

https://developer.android.com/sdk/index.html

I have to install old version adt-bundle-windows-x86-20131030.zip
what working fine.
I had to delete .metadata folder in workspace if I want open old version ADT
226

Eclipse my templates store Android | eclipse-my-templates-store-android


Where file(s) does eclipse store Java code style settings to?
If you need copy any old templates to the new workspace.

workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.ui.prefs


You can edit the Eclipse Templates from menu Window - Preferences - Java - Editor - Templates.


Editace: 2011-10-28 09:38:58
Počet článků v kategorii: 397
Url:tts-text-to-speech
Share
Share
Tweet