在Android中用tts改变铃声

时间:2013-03-27 09:00:19

标签: android android-intent text-to-speech

我试图创建一个应用程序,当来电来确定号码并使用android文本语音时,它会说出来电者的联系人姓名。我几乎完成了我的问题是当来电而不是默认铃声时它应该说TTS.how用TTS覆盖铃声 在这里,我给了我尝试的东西。任何人都可以帮我找到更好的解决方案。我已经尝试了第一个答案,现在铃声音量被静音了。但是听起来不会来。

   public class myPhoneStateChangeListener extends PhoneStateListener
{
    int ph_state = 0;
    speechcontact clsspcntct = new speechcontact();
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        super.onCallStateChanged(state, incomingNumber);
        if (state == TelephonyManager.CALL_STATE_RINGING)
        {

            String phoneNumber =   incomingNumber;
            String ContactName = objUtility.getContactName2(context,phoneNumber);

            if (RBSpkMde.isChecked())
            {
                speakWords(ContactName);
            }
        } 
    }
     public void speakWords(String speech)
    {
    myTTS.speak("you have call from"+speech, TextToSpeech.QUEUE_FLUSH, null);

    }
}

1 个答案:

答案 0 :(得分:1)

您将STREAM_RING

静音
public class myPhoneStateChangeListener extends PhoneStateListener
{
    private int mRingVolume;
    Context context;

    public myPhoneStateChangeListener(Context cxt)
    {
        context = cxt;
    }

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        super.onCallStateChanged(state, incomingNumber);
        if (state == TelephonyManager.CALL_STATE_RINGING)
        {
            mRingVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_RING);
            mAudioManager.setStreamMute(AudioManager.STREAM_RING, true);
            String phoneNumber =   incomingNumber;
            String ContactName = objUtility.getContactName2(context,phoneNumber);

            if (RBSpkMde.isChecked())
            {
                speakWords(ContactName);
            }
        } 
        if (state == TelephonyManager.CALL_STATE_IDLE)
        {
             mAudioManager.setStreamMute(AudioManager.STREAM_RING, false);
             mAudioManager.setStreamVolume(AudioManager.STREAM_RING, 
                        mRingVolume, AudioManager.FLAG_ALLOW_RINGER_MODES);
        }
    }
     public void speakWords(String speech)
    {
    myTTS.speak("you have call from"+speech, TextToSpeech.QUEUE_FLUSH, null);

    }

}