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

Shortcuts in Android Studio for Android Developers - ABNHive

I hope these shortcuts will definitely help you to increase the productivity level. Search for command: cmd + shift + a ( Windows / Linux : ctrl +  shift + a) You just type: close and you’ll get a proper shortcut/command. Choose from the last copy / pastes : cmd +  shift  + v ( Windows / Linux : Ctrl + Shift + v). By default, there are 5 last copy/paste items. Enable mulmulti cursorature: ctrl + g (alt + j for Windows / Linux ). Open a class: cmd + o ( Windows / Linux : ctrl + n). Open any file: cmd + shift + o ( Windows / Linux : ctrl + shift + n) Open symbol:  cmd + option + o ( Windows / Linux : alt + shift + n). Go to implementation: cmd + option + b ( Windows / Linux : ctrl + alt + b). Go to declaration: cmd + b ( Windows / Linux : ctrl + b).  Go to type declaration: control + shift + b ( Windows / Linux : ctrl + shift + b).  Go to super: cmd + u ( Windows / Linux : ctrl + u).  Move between tabs: cmd + shift + [ (move left) o...

Services in Android - ABNHive

A service is a component which runs in the background without direct interaction with the user.  A service extends the base class Service . Services run with a higher priority than inactive or invisible activities and therefore it is less likely that the Android system terminates them for resource management. The only reason Android will stop a Service prematurely is to provide additional resources for a foreground component usually an Activity. When this happens, your Service can be configured to restart automatically. You can start a service if it is not running using Context.startService(), connect (bind) to a running service using Context.bindService(), and communicate with the running service through an interface that the service exposes. Each service class must have a corresponding <service> declaration in the AndroidManifest.xml file for its package. Types of Services Bound Service Service which call indefinitely in between activity. An Android component m...

Essential Guide to Setting up Emulators- ABNHive

An Android emulator is an Android Virtual Device (AVD) that represents a specific Android device. You can use an Android emulator as a platform to run and test your applications on your PC. Installing Emulator on PC Steps are given below Open SDK Manager from Android Studio, click Tools > SDK Manager. Click SDK Tools section Click to tick Android Emulator and Intel x86 Emulator Accelerator - HAXM Installer (If available) Click OK Button Wait to complete download It will automatically download Android Emulator Creating AVD After downloading the Emulator we need to Create AVD (Android Virtual Device).  Click  Tools > AVD Manager. Click Create New Virtual Device Icon Now choose device  If a download option is there, just click to download Device Image Configure Device Now Android Studio creates AVD Click the green icon to run Emulator - Aswin Bhim Nath