siddhushettar
Lurker
I am trying to create a mobile app, when the app is launched it should speak some words(Say for example Welome to this app... etc etc). but somehow i am unable to come up with a solution. Can someone please help me in this?
package com.example.helloworld;
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.widget.Toast;
public class HelloAndroid extends Activity implements OnInitListener
{
TextToSpeech myTTS;
private static final int MY_DATA_CHECK_CODE = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//check for TTS data
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
}
@Override
protected void onStart() {
super.onStart();
// The activity is about to become visible.
String words = "Hi hi hi hi hi hi hi hi hi hi hi";
speakWords(words);
}
//speak the user text
private void speakWords(String speech) {
myTTS.setLanguage(Locale.US);
//speak straight away
myTTS.speak("Hello welcome to this app......", 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
}
}
Thanks in advance for your help
package com.example.helloworld;
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.widget.Toast;
public class HelloAndroid extends Activity implements OnInitListener
{
TextToSpeech myTTS;
private static final int MY_DATA_CHECK_CODE = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//check for TTS data
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
}
@Override
protected void onStart() {
super.onStart();
// The activity is about to become visible.
String words = "Hi hi hi hi hi hi hi hi hi hi hi";
speakWords(words);
}
//speak the user text
private void speakWords(String speech) {
myTTS.setLanguage(Locale.US);
//speak straight away
myTTS.speak("Hello welcome to this app......", 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
}
}
Thanks in advance for your help