Untitled
unknown
plain_text
2 years ago
2.3 kB
2
Indexable
Never
package com.example.txttospch; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.view.View; import android.widget.EditText; import java.util.Locale; public class MainActivity extends AppCompatActivity { EditText e1; TextToSpeech t1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); e1 = findViewById(R.id.edittext); t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { @Override public void onInit(int i) { if(i!=TextToSpeech.ERROR){ t1.setLanguage(Locale.UK); } } }); } public void convert(View view){ String toSpeak=e1.getText().toString(); t1.speak(toSpeak,TextToSpeech.QUEUE_FLUSH,null); } } <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" android:layout_marginEnd="98dp" android:layout_marginBottom="639dp" android:text="Text to Speech" android:textColor="@color/black" android:textSize="32sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <EditText android:id="@+id/edittext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" android:layout_marginEnd="101dp" android:layout_marginBottom="502dp" android:ems="10" android:hint="type text here" android:inputType="textPersonName" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" android:layout_marginEnd="159dp" android:layout_marginBottom="362dp" android:onClick="convert" android:text="convert" /> </RelativeLayout>