Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7054301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:36:36+00:00 2026-05-28T03:36:36+00:00

Ok basically I have everything set up and I have set up my onClick

  • 0

Ok basically I have everything set up and I have set up my onClick method many times, but this time it is set up in my main.xml file

    <Button 
    android:layout_alignParentRight="true"
    android:layout_height="40dip" 
    android:layout_width="80dip" 
    android:id="@+id/speak" 
    android:enabled="true"
    android:visible="true"
    android:text="Speak" > 

</Button>

obviously it has other things to define its layout but that is one of the xml layouts inside my button, and for some reason every time I click on the button, it just closes the entire application, Why is that?
also If I set it up to add a onClickListener then the button just does nothing.

I would set up my onClick listener like this

    speak.setOnClickListener(this);
     public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.speak:
        doSpeak();
        break;
    }
}

and it still doesnt work…. So i just dont know what I am doing wrong

     package com.write.it;

    import android.app.Activity;
    import android.content.Intent;
    import android.media.MediaPlayer;
    import android.os.Bundle;
    import android.speech.tts.TextToSpeech;
    import android.speech.tts.TextToSpeech.OnInitListener;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;

    public class Speech extends Activity implements OnInitListener {
private EditText words = null;
private Button speakBtn = null;
private static final int REQ_TTS_STATUS_CHECK = 0;
private static final String TAG = "TTS Demo";
    private TextToSpeech mTts = null;
    private MediaPlayer player = null;

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    words = (EditText)findViewById(R.id.wordsToSpeak);
    speakBtn = (Button)findViewById(R.id.speak);



    // Check to be sure that TTS exists and is okay to use
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, REQ_TTS_STATUS_CHECK);
}

public void doButton(View view) {
    switch(view.getId()) {
    case R.id.speak:
        mTts.speak(words.getText().toString(), TextToSpeech.QUEUE_ADD, null);
        break;

        }
            }

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQ_TTS_STATUS_CHECK) {
        switch (resultCode) {
        case TextToSpeech.Engine.CHECK_VOICE_DATA_PASS:
            // TTS is up and running
            mTts = new TextToSpeech(this, this);
            Log.v(TAG, "Pico is installed okay");
            break;
        case TextToSpeech.Engine.CHECK_VOICE_DATA_BAD_DATA:
        case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_DATA:
        case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_VOLUME:
            // missing data, install it
            Log.v(TAG, "Need language stuff: " + resultCode);
            Intent installIntent = new Intent();
            installIntent.setAction(
                TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
            break;
        case TextToSpeech.Engine.CHECK_VOICE_DATA_FAIL:
        default:
            Log.e(TAG, "Got a failure. TTS apparently not available");
        }
    }
    else {
        // Got something else
    }
}

public void onInit(int status) {
    // Now that the TTS engine is ready, we enable buttons
    if( status == TextToSpeech.SUCCESS) {
        speakBtn.setEnabled(true);
        }
}

@Override
public void onPause()
{
    super.onPause();
    // if we're losing focus, stop playing
    if(player != null) {
        player.stop();
    }
    // if we're losing focus, stop talking
    if( mTts != null)
        mTts.stop();
}

@Override
public void onDestroy()
{
    super.onDestroy();
    if(player != null) {
        player.release();
    }
    if( mTts != null) {
        mTts.shutdown();
    }
        }
    }

I mean am i not setting the volume or setting or telling it to speak?!?!?, am I not telling it to do something it is supposed to do?….. the volume on my phone is on and the media volume is up, I have an HTC evo 4g so it should work…..
here Ill add another one with utterance and the onClick Method

    package com.write.it;


    import java.util.HashMap;
    import java.util.Locale;
    import java.util.StringTokenizer;
    import android.content.Intent;
    import android.os.Bundle;
    import android.speech.tts.TextToSpeech;
    import android.speech.tts.TextToSpeech.OnInitListener;
    import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;


    public class Speech extends WriteitActivity implements OnInitListener, OnUtteranceCompletedListener {
private EditText words = null;
private Button speakBtn = null;
     private static final int REQ_TTS_STATUS_CHECK = 0;
private static final String TAG = "Word Guesser";
    private TextToSpeech mTts;

    private int uttCount = 0;
    private HashMap<String, String> params = new HashMap<String, String>();

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    words = (EditText)findViewById(R.id.wordsToSpeak);
    speakBtn = (Button)findViewById(R.id.speak);
    speakBtn.setOnClickListener((OnClickListener) this);
    mTts.isLanguageAvailable(Locale.US);



    // Check to be sure that TTS exists and is okay to use
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, REQ_TTS_STATUS_CHECK);
    }

    public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.speak:
        doSpeak();
        break;
    }
}

public void doSpeak() {
    StringTokenizer st = new StringTokenizer(words.getText().toString(),",.");
    while (st.hasMoreTokens()) {
        params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
                String.valueOf(uttCount++));
        mTts.speak(getString(R.id.wordsToSpeak), TextToSpeech.QUEUE_ADD, null);
        mTts.speak(getString(R.id.wordsToSpeak), TextToSpeech.SUCCESS, null);

     }



}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQ_TTS_STATUS_CHECK) {
        switch (resultCode) {
        case TextToSpeech.Engine.CHECK_VOICE_DATA_PASS:
            // TTS is up and running
            mTts = new TextToSpeech(this, this);
            Log.v(TAG, "Pico is installed okay");
            break;
        case TextToSpeech.Engine.CHECK_VOICE_DATA_BAD_DATA:
        case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_DATA:
        case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_VOLUME:
            // missing data, install it
            Log.v(TAG, "Need language stuff: " + resultCode);
            Intent installIntent = new Intent();
            installIntent.setAction(
                TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
            break;
        case TextToSpeech.Engine.CHECK_VOICE_DATA_FAIL:
        default:
            Log.e(TAG, "Got a failure. TTS not available");
        }
    }
    else {
        // Got something else
    }
}

public void onInit(int status) {
    // Now that the TTS engine is ready, we enable the button
    if( status == TextToSpeech.SUCCESS) {
        mTts.setOnUtteranceCompletedListener(this);
}
}

public void onPause()
{
    super.onPause();
    // if we're losing focus, stop talking
    if( mTts != null)
        mTts.stop();
}

@Override
public void onDestroy()
{
    super.onDestroy();
    mTts.shutdown();
}

public void onUtteranceCompleted(String uttId) {
    Log.v(TAG, "Got completed message for uttId: " + uttId);
    Integer.parseInt(uttId);
}



}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:36:36+00:00Added an answer on May 28, 2026 at 3:36 am

    There are many things mixed up in your code, especially the part where you check the engine with a StartActivityforResult().

    Please see this example of a working TTS: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TextToSpeechActivity.html

    Also you did not assign any ID to the button (apparently?) Could it be, that another button is using the ID?

    /edit:
    First of all, merge both Activities. If you call onCreate()again, it will override the previous one. Then add implements OnClickListener and replace

    speakBtn.setOnClickListener((OnClickListener) this);
    

    with

    speakBtn.setOnClickListener(this);
    

    Eclipse will tell you that you need to add an unimplemented method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have a custom UIButton and this custom button contains subviews. If I
I have tried what seems like everything - I've done similiar things many times
Basically, I have my DOM objects set up and am calling the .getAttribute method
So basically what I have been doing is convert one xml file to a
can anyone help? I have a problem aligning rounded corners in IE6/7. Basically everything
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp
I basically have something like this: void Foo(Type ty) { var result = serializer.Deserialize<ty>(inputContent);
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have to do a update of a record. I have a set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.