2017-08-16 4 views
-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); 
} 

Le code ci-dessus parlent le numéro, je veux parler comment le nom de l'appelant au lieu du numéro. Que faire avec ce comparer le nombre parlant avec le nom de contact?comment parler le nom de l'appelant parle à la place du numéro, le code ci-dessous Énoncez le numéro de l'appelant

Répondre