1

I am followiing this question to make tts to work

Android TTS doesn't speak

But in the answer he gave say(gameover,true),say(line,false),say(definition_string,false)

please could anyone help me by telling what are those terms.

This is my code

public class SecondActivity extends AppCompatActivity implements OnInitListener {
    TextToSpeech t1;
   // private final int REQ_CODE_SPEECH_INPUT = 100;
    String emailid;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        emailid="Hi,say your email id";

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if(status != TextToSpeech.ERROR) {
                    t1.setLanguage(Locale.US);

                }
            }
        });

        Toast.makeText(getApplicationContext(), emailid,Toast.LENGTH_SHORT).show();
        t1.speak(emailid, TextToSpeech.QUEUE_FLUSH, null);



    }

    public void onPause(){
        if(t1 !=null){
            t1.stop();
            t1.shutdown();
        }
        super.onPause();
    }
  }
Community
  • 1
  • 1
Bhanu Sri
  • 43
  • 6

1 Answers1

0

Try this and see if it works:

public class TextToSpeechController implements TextToSpeech.OnInitListener{

private Context mContext;

private TextToSpeech tts;

public TextToSpeechController(Context context) {
    mContext = context;
    tts = new TextToSpeech(context, this);
}

@Override
public void onInit(int status) {
    Log.e("INIT TTS", "INIT");
    if (status == TextToSpeech.SUCCESS) {
            int result = tts.setLanguage(Locale.ENGLISH);

            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                   Toast.makeText(mContext, "This Language is not supported", Toast.LENGTH_LONG).show();
            }
            else {
                Toast.makeText(mContext, "Ready to Speak", Toast.LENGTH_LONG).show();
                speakTheText("Welcome to the App");
            }

    } 
    else {
         Toast.makeText(mContext, "Can Not Speak", Toast.LENGTH_LONG).show();
    }   
}

public void stopTTS(){
    tts.stop();
    tts.shutdown();
}

 public void speakTheText(String str){
     tts.speak(str, TextToSpeech.QUEUE_FLUSH, null);
 }
Ispas Claudiu
  • 1,890
  • 2
  • 28
  • 54