How can I add audio message in my android application? - android

I want to give audio message at the opening of my android application just like "Welcome our System" but i can't.
code:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String text="Welcome to our location based system";
if (text!=null && text.length()>0)
{
Toast.makeText(SimpleAudioTestActivity.this, "Saying: " + text, Toast.LENGTH_LONG).show();
tts.speak(text, TextToSpeech.QUEUE_ADD, null);
}
Intent checkintent=new Intent();
checkintent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkintent, MY_DATA_CHECK_CODE);
}
When I do it after clicking a button it is ok:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
but1=(Button) findViewById(R.id.button1);
but1.setonclickListener(new View.onclickListener()
{
#Override
public void onclick(View arg0)
{
String text="Welcome to our location based system";
if (text!=null && text.length()>0)
{
Toast.makeText(SimpleAudioTestActivity.this, "Saying: " + text, Toast.LENGTH_LONG).show();
tts.speak(text, TextToSpeech.QUEUE_ADD, null);
}
}
});
Intent checkintent=new Intent();
checkintent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkintent, MY_DATA_CHECK_CODE);
}
How can I do that? Any suggestion please.

You can put your audio file (such as mp3 file) in res/raw folder then create MediaPlayer and play that file

Is this what you're looking for? This code will speak whatever is in the string 'text' using texttospeech. Place it in your onCreate.
TextToSpeech speak;
speak = new TextToSpeech(TextTalk.this,
new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
speak.setLanguage(Locale.US);
}
}
});
speak.speak(text, TextToSpeech.QUEUE_FLUSH, null);

Related

How do I make text to speech sound more human and less robotic?

I have this app for small kids that says "Good job, clap!" when they pick the right choice, or "Try again", when they push the wrong button.
The voice is very robotic, how do I make it sound more human and kids friendly?
tts = new TextToSpeech(Level_11_Testing.this, new TextToSpeech.OnInitListener() {
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
tts.setLanguage(Locale.US);
tts.speak("Push on" + rightchoice, TextToSpeech.QUEUE_ADD, null);
}
}
});
up.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
up.setEnabled(false);//it prevents double clicking
if (idx == rightchoice) {
tts.speak("Good job, clap!", TextToSpeech.QUEUE_FLUSH, null);
mHandler.postDelayed(hMyTimeTask, 1400);
} else {
tts.speak("Try again!", TextToSpeech.QUEUE_FLUSH, null);
}

When I use TTS, occur setLanguage failed on android

I use TTS (Text to speech) but my device not speak voice.
TtsEngine::setLanguage called with unsupported language
setLanguage(kor, KOR,) failed
I think my device not supported korean language.
how to install korean language pack?
my source.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//create TTS
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int i) {
if (i != ERROR) {
tts.setLanguage(Locale.KOREAN);
}
else {
}
}
});
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
tts.speak(editText.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
}
});
}
How to speak on my android device ?
thanks:..
Try this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS ) {
{
int result = tts.setLanguage(Locale.getDefault());
System.out.println ( "Result : " + result + " " + Locale.getDefault().getLanguage() );
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED)
{
Toast.makeText( this , "Please Set your Language to English US.", Toast.LENGTH_LONG ).show();
}
else
{
tts.setLanguage(Locale.KOREAN);//remove this line
tts.setLanguage(new Locale("ko_KR"));//add this line
tts.speak( "hey",TextToSpeech.QUEUE_FLUSH, null );
}
}
});
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
tts.speak(editText.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
}
});
Short answer: Try to turn the WIFI on
I had the same problem.
If you filter the word "TTS" in the logcat, you can see that the device is trying to download the locale. So, if you turn on Wifi, your problem should be solved. I'm looking for a solution to load the Locale locally on the device to avoid downloading it over the Internet.

How to call phone number ending with # using Android Dialer

How do I call a number ending with '#' sign using android dialer?
My code is as follows,
EditText firstNumber;
Button btnAdd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main23);
Toast.makeText(Main23Activity.this,
"Type in your Pin Number", Toast.LENGTH_LONG).show();
btnAdd = (Button)findViewById(R.id.button12);
btnAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
numberSign = "#";
EditText et = (EditText) findViewById(R.id.editText6);
String text= et.getEditableText().toString();
Toast.makeText(Main23Activity.this,
"Adding Money to your account has never been this easy", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:*221*" + text + numberSign ));
startActivity(intent);
} catch (Exception e) {
}
}
});
}
}
This is how you call a number ending with '#' using android dialer. You need to encode and then parse.
Try the below code,
String text = et.getText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + Uri.encode("*221*" + text + "#")));
startActivity(intent);
Using this link you can get unicode and hex values
for example 36 can be stored in strings.xml as
<string name="abcd">36</string>

How to integrate text to speech for telugu language in android application

I am developing the app to show some details in English, and when I click the button it speaks out that message in English,text contains numbers also. I want to speech that text in Telugu language, Is there any way to do that.The default android tts not supports Telugu language , how to use external tts engines in android applications. Please help me on this, Thank you.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tts = new TextToSpeech(this, this);
btnSpeak = (Button) findViewById(R.id.btnSpeak);
txtText = (EditText) findViewById(R.id.txtText);
// button on click event
btnSpeak.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
speakOut();
}
});
}
// shutdown tts when activity destroy
#Override
public void onDestroy() {
// Don't forget to shutdown!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
// It will called before TTS started
#Override
public void onInit(int status) {
// TODO Auto-generated method stub
// check status for TTS is initialized or not
if (status == TextToSpeech.SUCCESS) {
// if TTS initialized than set language
result = tts.setLanguage(Locale.US);
// tts.setPitch(5); // you can set pitch level
// tts.setSpeechRate(); //you can set speech speed rate
// check language is supported or not
// check language data is available or not
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Toast.makeText(this, "Missing data", Toast.LENGTH_LONG).show();
// disable button
btnSpeak.setEnabled(false);
} else {
// if all is good than enable button convert text to speech
btnSpeak.setEnabled(true);
}
} else {
Log.e("TTS", "Initilization Failed");
}
}
// call this method to speak text
private void speakOut() {
String text = txtText.getText().toString();
if (result != tts.setLanguage(Locale.US)) {
Toast.makeText(getApplicationContext(), "Enter right Words...... ",
Toast.LENGTH_LONG).show();
} else {
// speak given text
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
u have to set locale for that in speak out method
NOTE: phone and eclipse should support your locale

how to implement conversion text speech listen in audio file similar google translator in android

i am using google transalate api in my application,i have done in text conversion is ok
but translate-text to speech is pending
http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html
this code i am using how can implement translate text voice in android.
http://www.freeimagehosting.net/uploads/c382dd10f8.png
this above screenshot display text conversion is ok,click audiobutton image listen translate text in audioplayer how can implemented
my code
//audio button click event..........
submit = (ImageView) findViewById(R.id.ImageView01);
submit.setOnClickListener(new View.OnClickListener()
{ public void onClick(View v)
{
//speech code how can implemented
}
});
/////////////////// translate button code//////////////////////
((Button)findViewById(R.id.Button01)).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
String fromLan=spineFrom.getSelectedItem().toString();
String toLan=spineTo.getSelectedItem().toString();
Log.v("check",fromLan+" :"+toLan);
translatedText = Translate.execute(((EditText)findViewById(R.id.EditText01)).getText().toString(),converStrtoLan(fromLan),converStrtoLan(toLan));
((TextView)findViewById(R.id.TextView02)).setText(translatedText);
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent,1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
private TextToSpeech mTts;
protected void onActivityResult(
int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// success, create the TTS instance
mTts = new TextToSpeech(this, null);
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
mTts.setLanguage(Locale.US);
String myText1 = "Did you sleep well?";
String myText2 = "I hope so, because it's time to wake up.";
mTts.speak(myText1, TextToSpeech.QUEUE_FLUSH, null);
mTts.speak(myText2, TextToSpeech.QUEUE_ADD, null);
}
private Language converStrtoLan(String lan){
if(lan.equals("ENGLISH") || lan=="ENGLISH"){
return Language.ENGLISH;
}else if (lan.equals("SPANISH") || lan=="SPANISH"){
return Language.SPANISH;
}
return null;
}
}
how can add this audio code in audio click event ,
please forward some valuable response of this code this issue i am struggle for more number of days thanks in advance ..
In order to do Text To Speech with Android you can use eyes-free library

Categories

Resources