-1
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    String incoming = intent.getStringExtra("ns");
    Toast.makeText(getBaseContext(), incoming, Toast.LENGTH_SHORT).show();
    String msgspeech = "Phone state changed to " + incoming; 

    if (msgspeech != null) {
        tts.speak(msgspeech, TextToSpeech.QUEUE_FLUSH, null);
    } 

    return START_STICKY;
} 

@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        int result = tts.setLanguage(Locale.US); 

        if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "This Language is not supported");
        } 

        if (!TextUtils.isEmpty(msg)) {
            speakOut(msg);
        } else {
            speakOut("Error");
            Log.e("TTS", "Initilization Failed!");
        }
    } else {
        Log.d("SpeakService", "Could not initialize TextToSpeech.");
    }
}

private void speakOut(String msg) {
    tts.speak(msg, TextToSpeech.QUEUE_FLUSH, null);
}

The above code speak the number, I want how to speak the name of the caller instead the number. What to do with this compare speaking number with contact name?

Anh Pham
  • 2,108
  • 9
  • 18
  • 29

1 Answers1

0

You have the number. You can use the number to find the contact name in the contact list.

See post : How to retrieve the contact name from incoming call number?