Skip to main content

How to make a Text to Speech Application Android? - ABNHive

Reading the tiny text on a mobile screen is never a fun experience. That text reading done by your android application is another level of experience. Now, get ready to make a Text to speech application.

Now Open Android Studio and create a project.

After creating the project, you can open the activity_main.xml file in res/layout and type the following code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#3498db"
    android:weightSum="1"
    android:orientation="vertical" >
    <EditText
        android:id="@+id/text_enter"
        android:layout_width="match_parent"
        android:layout_weight=".5"
        android:background="#fff"
        android:textColor="#2c3e50"
        android:hint="Type Here!!!"
        android:padding="5dp"
        android:gravity="top|left"
        android:layout_height="0dp"/>
    <Button
        android:id="@+id/btn_speakout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".1"
        android:background="#e74c3c"
        android:textColor="#fff"
        android:text="SPEAK OUT"/>
</LinearLayout>

Now, its time to code java file. Open Main Activity and type the following code. 


package com.abnhive.tts;

import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener {
    private TextToSpeech readTTS;
    Button btnSpeak;
    EditText textEnter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnSpeak = findViewById(R.id.btn_speakout);
        textEnter = findViewById(R.id.text_enter);
        readTTS = new TextToSpeech(this,this);
        btnSpeak.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                readTTS.speak(edtTexttoSpeak.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
            }
        });
    }

    @Override
    public void onInit(int status) {

    }
}


Our app is ready. You can run the app or build the apk file and test on your device. The output looks like this. 


Android Development, Android Codes, Open Source, Text to Speech,

- Aswin Bhim Nath

Comments

Popular posts from this blog

Android Application Components Activities, Services, Broadcast Recievers, Content Providers - ABNHive

Application components are the essential building blocks of Android app development.  Each component is an entry point through which the system or a user can enter your app. There are 4 types of components in android Activities Services Broadcast receivers Content providers Let's dive into the deep.  Activities This is a component that represents a single screen with a user interface or simply an entry point for interacting with the user. Example, an email app might have one activity that shows a list of new emails. Activities work together to form a cohesive user experience in the app. For example, clicking a button on the first screen might replace that screen with another screen containing other widgets, a web page, a movie, or text information. Activities are typically created by subclassing (extending) the Android class Activity.  click here   to know more about Activity. Services This runs in the background ...

Talk about Ingredients before cooking in Android, the complete android tools - ABN Hive

We should know about the ingredients before cooking. Besides, we need to know about tools before developing android applications. Let's talk about it. Android Studio  This is the IDE (Integrated Development Environment) to make Android Applications. Android Studio provides the fastest tools for building apps on every type of Android device. It contains tools for development, debugging, testing, and performance that make it faster and easier to develop apps like these, Visual Layout Editor APK Analyzer Fast Emulator Intelligent Code Editor Flexible build System System requirements Windows Microsoft® Windows® 7/8/10 (32- or 64-bit) 3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android Emulator 2 GB of available disk space minimum, 4 GB Recommended (500 MB for IDE + 1.5 GB for Android SDK and emulator system image) 1280 x 800 minimum screen resolution Mac Mac® OS X® 10.10 (Yosemite) or higher, up to 10.13 (macOS High Sierra) 3 ...