CopyPastor

Detecting plagiarism made easy.

Score: 1.7056415677070618; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2017-05-06
by Jinal Awaiya

Original Post

Original - Posted on 2014-05-06
by user1406716



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Please refer this
import android.app.Activity; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import java.util.Locale;
public class MainActivity extends Activity implements TextToSpeech.OnInitListener { /** Called when the activity is first created. */
private TextToSpeech tts; private Button buttonSpeak; private EditText editText;
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
tts = new TextToSpeech(this, this); buttonSpeak = (Button) findViewById(R.id.button1); editText = (EditText) findViewById(R.id.editText1);
buttonSpeak.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { speakOut(); }
}); }
@Override public void onDestroy() { // Don't forget to shutdown tts! if (tts != null) { tts.stop(); tts.shutdown(); } super.onDestroy(); }
@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) { Log.e("TTS", "This Language is not supported"); } else { buttonSpeak.setEnabled(true); speakOut(); }
} else { Log.e("TTS", "Initilization Failed!"); }
}
private void speakOut() { String text = editText.getText().toString(); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">
<EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="77dp" android:layout_marginTop="42dp" android:ems="10" >
<requestFocus /> </EditText>
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1" android:layout_below="@+id/editText1" android:layout_marginLeft="59dp" android:layout_marginTop="39dp" android:text="Speak" />
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText1" android:layout_alignBottom="@+id/editText1" android:layout_alignParentLeft="true" android:text="Enter Text:" />
</RelativeLayout>
How to get string from strings.xml:
"getResources().getString(R.string.name_of_variable_in_stringsxmlfile);"
See this:
public class AndroidTextToSpeechActivity extends Activity implements TextToSpeech.OnInitListener { /** Called when the activity is first created. */ private TextToSpeech tts; private Button btnSpeak; private EditText txtText; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tts = new TextToSpeech(this, this); btnSpeak = (Button) findViewById(R.id.btnSpeak); txtText = (EditText) findViewById(R.id.txtText); // button on click event btnSpeak.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { speakOut(); } }); } @Override public void onDestroy() { // Don't forget to shutdown tts! if (tts != null) { tts.stop(); tts.shutdown(); } super.onDestroy(); } @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) { Log.e("TTS", "This Language is not supported"); } else { btnSpeak.setEnabled(true); speakOut(); } } else { Log.e("TTS", "Initilization Failed!"); } } private void speakOut() { String text = txtText.getText().toString(); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); } }
Source (worked for me): [here][1]

[1]: http://www.androidhive.info/2012/01/android-text-to-speech-tutorial/

        
Present in both answers; Present only in the new answer; Present only in the old answer;