Text To Speech Android Application Complete Source Code

Defination: Android Application For To Text To Speech Conversion.

Source Code:

1: activity_speech_convert.xml 

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.speechconverter.SpeechConvert" >

    <ImageButton
        android:id="@+id/btnspeak"
        android:layout_width="92dp"
        android:layout_height="76dp"
        android:layout_x="95dp"
        android:layout_y="12dp"
        android:src="@drawable/abc_ab_bottom_solid_dark_holo" />

    <TextView
        android:id="@+id/textText"
        android:layout_width="236dp"
        android:layout_height="180dp"
        android:layout_x="32dp"
        android:layout_y="114dp"
        android:text="Your Text"
        android:textSize="20dip" />

</AbsoluteLayout>


2: SpeechConvert.java 

package com.example.speechconverter;

import java.util.ArrayList;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class SpeechConvert extends ActionBarActivity
{

    protected static final int RESULT_SPEECH=1;
    private ImageButton btnspeak;
    private TextView txtText;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_speech_convert);

        txtText=(TextView)findViewById(R.id.textText);
        btnspeak=(ImageButton)findViewById(R.id.btnspeak);

        btnspeak.setOnClickListener(new View.OnClickListener()
        {


            @Override
            public void onClick(View arg0)
            {
                Intent i=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en_us");


                try
                {
                    startActivityForResult(i, RESULT_SPEECH);
                    txtText.setText("");

                }
                catch(ActivityNotFoundException a)
                {
                    Toast.makeText(getApplicationContext(), "Device Is Not Supported", Toast.LENGTH_LONG).show();
                }

            }
        });


    }

    public boolean onCreateoptionsmenu(Menu menu)
    {

        //MenuInflater.this(R.menu.speech_convert,menu);
        getMenuInflater().inflate(R.menu.speech_convert, menu);
        return true;

    }

    protected void onActivityResult(int requestcode,int resultcode,Intent data)
    {
        super.onActivityResult(requestcode, resultcode, data);

        switch(resultcode)
        {
        case RESULT_SPEECH:
        {
            if(resultcode==RESULT_OK && null!=data)
            {
                ArrayList<String>text=data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                txtText.setText(text.get(0));


            }
            break;

        }

        }
    }
}




 


 
Text To Speech Android Application Complete Source Code Text To Speech Android Application Complete Source Code Reviewed by Unknown on 10:46:00 AM Rating: 5

No comments:

Powered by Blogger.