Reading
Add Comment
Android Text to Speech Example
Android provides the facility to know the incoming number and speak it by the help of android speech api and telephony manager.
Here, we are going to develop a basic android app that speaks the incoming number while phone is in ringing mode.
In the next page, we will see the full version of this app that speaks the caller name and provides the setting option to change the speed rate and pitch. Additionaly, it provides option to add text before and after the incoming number or caller name.
activity_main.xml
We have not done anything uncommon here. It has the straightforward textview.
File: activity_main.xml
<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
Activity class
In this activity, we have written the code to know the phone state, and speak the incoming number by the help of TextToSpeech class.
File: MainActivity.java
AndroidManifest.xml
You have to include READ_PHONE_STATE utilizes consent as a part of this manifest.xml record. We should see the full code.
File: AndroidManifest.xml
0 comments:
Post a Comment