android分析声音中的节奏,[AndroidTips]调用TextToSpeech朗读的时候怎么中间停顿

[AndroidTips]调用TextToSpeech朗读的时候如何中间停顿

TTS在句子中间会停顿,你也可以通过在任何字符串中加点"."后面加空格来达到目的。最多可以有三个点,最后一个点后面加空格,没有空格可能不起作用。点越多停顿时间越长。

下面的代码中在一开始有一个长的停顿,然后在读消息体之前也有一个停顿:

private final BroadcastReceiver SMScatcher = new BroadcastReceiver() {

@Override

public void onReceive(final Context context, final Intent intent) {

if (intent.getAction().equals(

"android.provider.Telephony.SMS_RECEIVED")) {

// if(message starts with SMStretcher recognize BYTE)

StringBuilder sb = new StringBuilder();

/*

* The SMS-Messages are 'hiding' within the extras of the

* Intent.

*/

Bundle bundle = intent.getExtras();

if (bundle != null) {

/* Get all messages contained in the Intent */

Object[] pdusObj = (Object[]) bundle.get("pdus");

SmsMessage[] messages = new SmsMessage[pdusObj.length];

for (int i = 0; i < pdusObj.length; i++) {

messages[i] = SmsMessage

.createFromPdu((byte[]) pdusObj[i]);

}

/* Feed the StringBuilder with all Messages found. */

for (SmsMessage currentMessage : messages) {

// periods are to pause

sb.append("... Message From: ");

/* Sender-Number */

sb.append(currentMessage.getDisplayOriginatingAddress());

sb.append(".. ");

/* Actual Message-Content */

sb.append(currentMessage.getDisplayMessageBody());

}

// Toast.makeText(application, sb.toString(),

// Toast.LENGTH_LONG).show();

if (mTtsReady) {

try {

mTts.speak(sb.toString(), TextToSpeech.QUEUE_ADD,

null);

} catch (Exception e) {

Toast.makeText(application, "TTS Not ready",

Toast.LENGTH_LONG).show();

e.printStackTrace();

}

}

}

}

}

};

Refer to:

http://stackoverflow.com/questions/4970204/how-to-pause-android-speech-tts-texttospeech