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

这篇博客介绍了如何在使用Android的TextToSpeech服务朗读文本时实现中间停顿。通过在字符串中添加带有空格的点(...)可以控制停顿,点的数量决定了停顿的长度。示例代码展示了如何在接收到短信时,使用TTS朗读短信内容,并在特定位置插入停顿。
摘要由CSDN通过智能技术生成

[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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值