Thursday 25 September 2014

Alphabet Teacher Text to speech


Alphabet teacher uses TTS api to convert text to speech.The text is taken from the database then converted to speech. To get the speech started the default speech engine has to be enabled in your device from settings.
Source code:
package com.example.voice;
import java.util.Locale;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener, OnInitListener {
Button button;
ImageView image;
private int currentimageindex =0;
private int[] IMAGE_DBS ={R.drawable.apple, R.drawable.basket, R.drawable.cat , R.drawable.dog, R.drawable.egg, R.drawable.fish, R.drawable.goat, R.drawable.home, R.drawable.icecream, R.drawable.jug, R.drawable.king, R.drawable.lamp, R.drawable.mat, R.drawable.nest, R.drawable.orange, R.drawable.potato, R.drawable.queen, R.drawable.rabbit, R.drawable.sun, R.drawable.taxi, R.drawable.umbrella, R.drawable.van, R.drawable.wheel, R.drawable.xylophone,R.drawable.yak, R.drawable.zoo};
private TextToSpeech myTTS;
private int i=0;
static String[] hello ={ "A for apple","B for basket","C for cat","D for dog","E for egg","F for fish","G for goat","H for home ","I for ice cream","J for jug","K for king","L for lamp","M for mat","N for nest ","O for orange","P for potato","Q for queen ","R for rabbit","S for sun","T for taxi","U for umbrella","V for van","W for wheel","X for xylophone","Y for yak","Z for zoo"};

private int MY_DATA_CHECK_CODE = 0;
//create the Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button speakButton = (Button)findViewById(R.id.speak);
image = (ImageView) findViewById(R.id.imageView1);
//listen for clicks
speakButton.setOnClickListener(this);
//speakButton.setText("");
//check for TTS data
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
}
//respond to button clicks
public void onClick(View v) {
//get the text entered
try {
image.setImageResource(IMAGE_DBS[currentimageindex]);
currentimageindex++;
System.out.println("array");
EditText enteredText = (EditText)findViewById(R.id.enter);
enteredText.setText(""+hello[i++]);
enteredText.setTextSize(30);
enteredText.setFocusableInTouchMode(true);
enteredText.setFocusable(true);
String words = enteredText.getText().toString();
speakWords(words);
}
catch (Exception e) {
e.printStackTrace();
System.exit(0);
}}
//speak the user text
private void speakWords(String speech) {
//speak straight away
myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}
//act on result of TTS data check
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
//the user has the necessary data - create the TTS
myTTS = new TextToSpeech(this, this);
}
else {
//no data - install it now
Intent installTTSIntent = new Intent();
installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installTTSIntent);
}
}
}
//setup TTS
public void onInit(int initStatus) {
//check for successful instantiation
if (initStatus == TextToSpeech.SUCCESS) {    if(myTTS.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE)
myTTS.setLanguage(Locale.US);
}
else if (initStatus == TextToSpeech.ERROR) {
Toast.makeText(this, "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();
}
}
}
 

Android Copying sample data files into sdcard partition.

Copying sample data files into sdcard partition.

Requirements for copying sample files to SD card:
1.Android sdk(software development kit).
Link to Download: http://developer.android.com/sdk/index.html
Steps:
1.Connect LAN cable to host and target machines.You should connect to RJ45 port in system.
2.Using if config cmd. Configure the manual ip address for both the machines
Cmd: ifconfig eth0 <ip address> <net mask address> up
ex: ifconfig eth0 192.168.1.15 net mask 255.255.255.0 up
3.Enter into Android sdk path
ex: e:/eclipse/android-sdk/platform-tools/
4.Using adb connect command you can connect host and target
Cmd:adb connect <ip address:port address>
ex:adb connect<192.168.1.15:5555>
Screenshot:
5.Check for connected devices.
Cmd:adb devices
as soon you type this command it will list the connect devices.
6.After connecting devices try to push the files into platform-tools folder.
7.Once the files are copied into platform-tools folder .Use adb push cmd to push the files to target.
Cmd:adb push file name /sdcard/file name..
ex:adb push abc.txt /sdcard/abc.txt